📄 kissfsmexperiment.java~
字号:
( jaga.ESLib.indexOf( ql, nextTrans.outputXPos ) < 0 );
for( int odl = 0; odl < iss; odl++ )
{
if( isDefinite )
{
desQ[ ql ].setTo( baseOdl + odl, currDesQ[ ql ] );
}else
{
desQ[ ql ].setTo( baseOdl + odl, out[ ql ].get( baseOdl + odl ) );
System.out.println("NOT DEFINITE - UNTESTED");
}
}
}
}
/*
System.out.println( jaga.ESLib.sampleDatasToString( in, out ) );
System.out.println("\n\n\n");
System.out.println( jaga.ESLib.sampleDatasToString( in, desQ ) ); // debug
*/
FitnessFunction ignoreStart = new TestWindowFitnessFunction( fitnessFunction, lastResetStatePreparationPatternLength );
double rv = ignoreStart.getFitness( in, out, desQ );
return rv;
}
/** generates an array of inputs suitable for this experiment
* using default input sample separation.
*/
public SampleData[] generateInput() {
final int DEF_ISS = 30;
return generateInput( DEF_ISS );
}
/** generates an array of inputs suitable for this experiment.
* @param inputSampleSeparation relative frequency of input to output samples. If this is n, then n outputs will be sampled for every change in inputs.
*/
public SampleData[] generateInput(int inputSampleSeparation) {
final int NON_RND_TEST_PROP = 1;
if( inputSampleSeparation != lastInputSampleSeparation )
{
refreshTestV = true;
lastInputSampleSeparation = inputSampleSeparation;
}
if( refreshTestV )
{
int totalInputs = nrInputs;
if( generateClock )
{
totalInputs++;
}
resetWalkedStates();
BitSet[] inpPatterns = new BitSet[ totalInputs ];
int Cix = nrInputs;
int testLength = 0;
MealyFSMNode currNode = null;
MealyFSMEdge currEdge = null;
// 0. Initialize data structures
for( int il = 0; il < nrInputs; il++ )
{
inpPatterns[ il ] = new BitSet();
}
if( generateClock )
{
inpPatterns[ Cix ] = new BitSet();
}
// 1. Initialize to Reset state
// 1.1 Randomize Reset Sequence
int resetInpIx = rnd.nextInt( resetInputs.length );
int resetSeqLen = resetInputs[ resetInpIx ].length;
if( generateClock )
{
for( int rl = 0; rl < resetSeqLen; rl++ )
{
for( int il = 0; il < nrInputs; il++ )
{
if( resetInputs[ resetInpIx ][ rl ].charAt( il ) == '1' )
{
inpPatterns[ il ].set( rl * 2 );
inpPatterns[ il ].set( rl * 2 + 1 ); // Assume all false to start off with
}
}
// 1.1 Clock this reset state in
//inpPatterns[ Cix ].setTo( rl * 2, false ); // Assume all false
inpPatterns[ Cix ].setTo( rl * 2 + 1, true );
}
lastResetStatePreparationPatternLength = testLength = resetSeqLen * 2;
}else
{
for( int rl = 0; rl < resetSeqLen; rl++ )
{
for( int il = 0; il < nrInputs; il++ )
{
if( resetInputs[ resetInpIx ][ rl ].charAt( il ) == '1' )
{
inpPatterns[ il ].set( rl );
}
}
}
lastResetStatePreparationPatternLength = testLength = resetSeqLen;
}
currEdge = new MealyFSMEdge( null, resetInputs[ resetInpIx ][ resetSeqLen - 1 ], "" );
currNode = resetState;
HashSet enteredStates = new HashSet();
int stateEnteredArrayIx = 0;
//System.out.println("" + currNode + " at " + testLength ); //D
stateEnterOrder[ stateEnteredArrayIx ] = currNode;
stateEnterPos[ stateEnteredArrayIx++ ] = testLength;
enteredStates.add( currNode );
// 2. Walk along edges
int pathsLeft = nrEdges;
while( pathsLeft > 0 )
{
int startAt = 0;
int endAt = 1;
if( generateClock )
{
boolean Cbefore = rnd.nextBoolean();
if( Cbefore )
{ // if clock goes down before inputs change
for( int il = 0; il < nrInputs; il++ )
{
inpPatterns[ il ].setTo( testLength, currEdge.inputs[ il ] ); // old edge
}
startAt = 1;
inpPatterns[ Cix ].setTo( testLength, false );
}else
{ // if inputs change before clock goes down
startAt = 0;
inpPatterns[ Cix ].setTo( testLength, true );
}
endAt = 3;
inpPatterns[ Cix ].setTo( testLength + 1, false );
inpPatterns[ Cix ].setTo( testLength + 2, true ); // clock
}
currEdge = currNode.pick();
//System.out.println("Moving to " + currNode + " with paths left = " + pathsLeft); //D
if( pathsLeft == 16 )
{
printNodes();
}
for( int rl = startAt; rl < endAt; rl++ )
{
for( int il = 0; il < nrInputs; il++ )
{
inpPatterns[ il ].setTo( testLength + rl, currEdge.inputs[ il ] );
}
}
testLength += endAt;
if( currNode.remove( currEdge ) )
{
pathsLeft--;
}
currNode = currEdge.dest;
if( !enteredStates.contains( currNode ) )
{
//System.out.println("" + currNode + " at " + testLength ); //D
stateEnterOrder[ stateEnteredArrayIx ] = currNode;
stateEnterPos[ stateEnteredArrayIx++ ] = testLength; // + 1
enteredStates.add( currNode );
}
}
// If got here is because crossed new path, may be also reaching new state. If this is the case then need
// extra input data loop to test stuff in this state. If every state has outgoing edge then cannot possibly
// be a new node.
for( int il = 0; il < totalInputs; il++ )
{
inpPatterns[ il ].setLength( testLength );
}
refreshTestV = false;
lastInput = ExperimentLib.generateInputFromTest( inpPatterns , NON_RND_TEST_PROP, testLength, inputSampleSeparation );
rndStatePos = stateEnterPos[ rnd.nextInt( stateEnterPos.length ) ];
}
return lastInput;
}
protected void resetWalkedStates()
{
for( int sl = 0; sl < allStates.length; sl++ )
{
allStates[ sl ].resetWalk();
}
}
public int getNumOfInputs() {
int totalInputs = nrInputs;
if( generateClock )
{
totalInputs++;
}
return totalInputs;
}
public int getNumOfOutputs() {
return nrOutputs;
}
public String toString()
{
String rv = "KISSFSMExperiment with:\n";
rv += " KISS file name = " + kissFileName + "\n";
rv += " Nr. Inputs = " + nrInputs + "\n";
rv += " Nr. Outputs = " + nrOutputs + "\n";
return rv;
}
/** @return Array of positions in last test pattern generated of when the tested FSM - if perfect -
* would enter each state. So State N is entered at input data position rv[ N ]
*/
public int[] getStateEnterPos() {
return stateEnterPos;
}
public int rndStatePos()
{
return rndStatePos;
}
/** @return Array of Mealy Finite State Machine Nodes. The nth node in the array represents the state
* for which the nth int in the array returned by getStateEnterPos() represents the position in the TP at which
* this state is entered.
*/
public MealyFSMNode[] getStateGraphNodes()
{
return stateEnterOrder;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -