Generic superclass representing state machines. Don't instantiate
this: make a subclass with definitions for the following methods:
See State Machines chapter in 6.01 Readings for detailed
explanation.
|
getStartState(self)
Handles the case that self.startState is a function. |
|
|
|
|
|
done(self,
state)
By default, machines don't terminate |
|
|
|
isDone(self)
Should only be used by transduce. |
|
|
|
start(self,
traceTasks=[ ] ,
verbose=False,
compact=True,
printInput=True)
Call before providing inp to a machine, or to reset it. |
|
|
|
step(self,
inp)
Execute one 'step' of the machine, by propagating inp
through to get a result, then updating self.state . |
|
|
|
transduce(self,
inps,
verbose=False,
traceTasks=[ ] ,
compact=True,
printInput=True,
check=False)
Start the machine fresh, and feed a sequence of values into the
machine, collecting the sequence of outputs |
|
|
|
run(self,
n=10,
verbose=False,
traceTasks=[ ] ,
compact=True,
printInput=True,
check=False)
For a machine that doesn't consume input (e.g., one made with
feedback , for n steps or until it
terminates. |
|
|
|
transduceF(self,
inpFn,
n=10,
verbose=False,
traceTasks=[ ] ,
compact=True,
printInput=True)
Like transduce , but rather than getting inputs from a
list of values, get them by calling a function with the input index
as the argument. |
|
|
|
guaranteeName(self)
Makes sure that this instance has a unique name that can be used for
tracing. |
|
|
|
printDebugInfo(self,
depth,
state,
nextState,
inp,
out,
debugParams)
Default method for printing out all of the debugging information for
a primitive machine. |
|
|
|
doTraceTasks(self,
inp,
state,
out,
debugParams)
Actually execute the trace tasks. |
|
|
|
check(thesm,
inps=None)
Run a rudimentary check on a state machine, using the list of inputs
provided. |
|
|