📄 muxfunction.java
字号:
package jaga.pj.circuits.experiment;
import jaga.SampleData;
import jaga.experiment.ExperimentLib;
/** This BooleanFunction is to be used to evolve MUXes with configurable address and
* data buses.
*
* Bits data are the data bus with 0 being bit 0, etc...
*
* Bits add are the address bus with bit last bit being the LSB, so having them = 001
* select bit 1 from the data bus (as opposed to bit 4)
*
*
* @author Michael Garvie
* @version
*/
public class MUXFunction implements BooleanFunction {
private int addLines;
private int dataLines;
/** Creates new MUX5d3aFunction */
public MUXFunction( int addLines, int dataLines ) {
this.addLines = addLines;
this.dataLines = dataLines;
}
/** 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)
{
boolean rv;
int totalLines = addLines + dataLines;
// Calculate address from last bits
int address = 0;
for( int bl = 0; bl < addLines; bl++ )
{
if( inputs[ totalLines - bl - 1 ] )
{
address += 1 << bl;
}
}
if( address >= dataLines )
{
rv = false;
}else
{
rv = inputs[ address ];
}
return rv;
}
/** returns the amount of inputs needed to compute this function
*/
public int getNumOfInputs()
{
return addLines + dataLines;
}
/** returns a set of SampleDatas providing a good set of input samples
* to test this function
*
* To avoid doing the full set which would be 256 lines long, use this:
* D0 D1 D2 D3 D4 A2 A1 A0 (Q)
* 0 0 X0 X1 X1 X0 0 0 0 (0)
* 1 1 X0 X1 X0 X0 0 0 0 (1)
* 2 X1 1 X0 X0 X1 0 0 1 (1)
* 3 X0 0 X1 X1 X1 0 0 1 (0)
* 4 X1 X1 1 X1 X0 0 1 0 (1)
* 5 X0 X0 0 X0 X0 0 1 0 (0)
* 6 X0 X1 X0 0 X1 0 1 1 (0)
* 7 X0 X1 X1 1 X1 0 1 1 (1)
* 8 X1 X0 X1 X0 0 1 0 0 (0)
* 9 X1 X0 X1 X0 1 1 0 0 (1)
* 10 X0 X0 X1 X0 X1 1 1 1 (0)
* 11 X0 X0 X1 X0 X0 1 1 1 (0)
* 12 X1 1 X0 X1 X0 0 0 1 (1)
* 13 X1 X1 X1 X1 1 1 0 0 (1)
* 14 X1 X0 0 X0 X0 0 1 0 (0)
*
*/
public SampleData[] getTestData()
{
/*
int[] inputBitsD0 = { 1, 2, 4, 8, 9, 12, 13, 14 };
int[] inputBitsD1 = { 2, 4, 6, 7, 12, 13 };
int[] inputBitsD2 = { 0, 1, 3, 4, 7, 8, 9, 10, 11, 13 };
int[] inputBitsD3 = { 0, 3, 4, 7, 12, 13 };
int[] inputBitsD4 = { 2, 3, 6, 7, 9, 10, 13 };
int[] inputBitsA2 = { 8, 9, 10, 11, 13 };
int[] inputBitsA1 = { 4, 5, 6, 7, 10, 11, 14 };
int[] inputBitsA0 = { 2, 3, 6, 7, 10, 11, 12 };
int[][] bits = { inputBitsD0, inputBitsD1, inputBitsD2, inputBitsD3, inputBitsD4, inputBitsA2, inputBitsA1, inputBitsA0 };
SampleData[] rv = ExperimentLib.bitsToSampleDatas( bits, 15 );
*/
return ExperimentLib.generateCompleteTest( getNumOfInputs() );
}
public String toString()
{
String rv = "MUXFunction with " + addLines + " address lines and " + dataLines + " data lines";
return rv;
}
public void setRandomSeed(long seed) {
jaga.experiment.ExperimentLib.setRandomSeed( seed );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -