fourinputfunction.java~

来自「Java遗传算法库」· JAVA~ 代码 · 共 47 行

JAVA~
47
字号
package jaga.pj.circuits.experiment;

import jaga.SampleData;
import jaga.experiment.ExperimentLib;

/** Q = ( A + B ) ( C + D )
 *
 * @author  unknown
 * @version 
 */
public class FourInputFunction extends Object implements BooleanFunction{

    /** Creates new FourInputFunction */
    public FourInputFunction() {
    }

    /** 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) {
        return ( inputs[0]||inputs[1] )^( inputs[2]&&inputs[3] );
    }
    /** returns the amount of inputs needed to compute this function
     */
    
    public int getNumOfInputs() {
        return 4;
    }
    
    /** returns a set of SampleDatas providing a good set of input samples
     * to test this function
     */
    public SampleData[] getTestData() {
        SampleData[] complete = ExperimentLib.generateCompleteTest( getNumOfInputs() );
        int completeLength = complete[ 0 ].length();
        for( int il = 0; il < getNumOfInputs(); il++ )
        {
            complete[ il ].setLength( completeLength * 2 ); // twice as long
            // make second half = first inverted
            for( int bl =0; bl < completeLength; bl++ )
            {
                complete[ il ].setTo( completeLength + bl, complete[ il ].get( completeLength - bl - 1 ) );
            }
        }
        return complete;
    }
}

⌨️ 快捷键说明

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