tablebooleanfunction.java

来自「Java遗传算法库」· Java 代码 · 共 66 行

JAVA
66
字号
/* * TableBooleanFunction.java * * Created on 10 June 2003, 15:09 */package jaga.pj.circuits.experiment;import jaga.experiment.TestPatternGenerator;import jaga.experiment.CompleteShuffledTPG;/** First input defines MSB of table address * * @author  mmg20 */public class TableBooleanFunction implements BooleanFunction {        protected boolean[] table;    protected int nrIns;    protected TestPatternGenerator tpg = new CompleteShuffledTPG();        public TableBooleanFunction( int nrInputs, boolean[] table, TestPatternGenerator tpg  ) {        this( nrInputs, table );        this.tpg = tpg;    }        /** Creates a new instance of TableBooleanFunction */    public TableBooleanFunction( int nrInputs, boolean[] table ) {        this.table = table;        nrIns = nrInputs;    }        /** returns the amount of inputs needed to compute this function     */    public int getNumOfInputs() {        return nrIns;    }        /** returns the result of this function given the inputs in the array     * @param inputs what values the inputs to the function have     */    public boolean getResult(boolean[] inputs) {        int add = 0;        for( int il = 0; il < nrIns; il++ )        {            if( inputs[ il ] )            {                add += 1 << ( nrIns - il - 1 );            }        }        return table[ add ];    }        /** returns a set of SampleDatas providing a good set of input samples     * to test this function     */    public jaga.SampleData[] getTestData() {        return tpg.getPattern( nrIns );    }        public void setRandomSeed(long seed) {        tpg.setRandomSeed( seed );    }    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?