📄 mealyfsmnode_3.java~
字号:
/*
* MealyFSMNode_3.java
*
* Created on May 30, 2003, 2:36 PM
*/
package es.pj.circuits.experiment;
import java.util.Vector;
import java.util.Random;
/** A Node in a Mealy Finite State Machine. Provides functions for
* walking along a graph of the FSM.
* @author Michael Garvie
* @version
*/
public class MealyFSMNode_3 implements java.io.Serializable {
public MealyFSMEdge_3[] nextStates;
public Vector vNextStates; // pub for testing
protected Random rnd;
public MealyFSMNode_3(int nrInputs, Random rnd) {
this( nrInputs );
this.rnd = rnd;
}
/** Creates new MealyFSMNode_3 */
public MealyFSMNode_3(int nrInputs) {
rnd = new Random();
nextStates = new MealyFSMEdge_3[ 1 << nrInputs ];
}
public int addEdge( MealyFSMNode_3 dest, String ins, String outs )
{
return addEdge( dest, ins, outs, false );
}
public int addEdge( MealyFSMNode_3 dest, String ins, String outs, boolean permanent )
{
int rv = 0;
if( ins.indexOf( "-" ) >=0 )
{
int[] xPos = getDontCarePos( ins );
int xs = xPos.length;
int totalNewEdges = 1 << xs;
for( int c = 0; c < totalNewEdges; c++ )
{
String xVals = es.ESLib.int2BinStr( c, xs );
char[] newIns = ins.toCharArray();
for( int dcl = 0; dcl < xs; dcl++ )
{
newIns[ xPos[ dcl ] ] = xVals.charAt( dcl );
}
rv += addEdge( dest, new String( newIns ), outs, permanent );
permanent = false;
}
}else
{
int inpCode = Integer.parseInt( ins, 2 );
MealyFSMEdge_3 newEdge = new MealyFSMEdge_3( dest, ins, outs );
if( nextStates[ inpCode ] == null )
{
rv = 1;
}else
{
rv = 0;
}
nextStates[ inpCode ] = newEdge;
newEdge.permanent = permanent;
}
return rv;
}
public void resetWalk()
{
vNextStates = new Vector();
MealyFSMEdge_3 currEdge;
for( int nl = 0; nl < nextStates.length; nl++ )
{
currEdge = nextStates[ nl ];
if( currEdge != null )
{
currEdge.walked = false;
vNextStates.add( currEdge );
}
}
}
public MealyFSMEdge_3 pick()
{
return ( MealyFSMEdge_3 ) vNextStates.get( rnd.nextInt( vNextStates.size() ) );
}
public boolean remove( MealyFSMEdge_3 which )
{
if( !which.permanent )
{
vNextStates.remove( which );
return true;
}else
{
if( which.walked )
{
return false;
}else
{
which.walked = true;
return true;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -