|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.generation5.ai.FSM
org.generation5.ai.TuringMachine
This class implements a Turing machine by deriving from a finite-state machine. The tape is simply implemented as a tape—as such, the tape is not infinite. You must allocate any space you want your Turing Machine to use in the tape itself.
| Nested Class Summary | |
static class |
TuringMachine.Transition
This class handles the Turing Machine transitions. |
| Nested classes inherited from class org.generation5.ai.FSM |
FSM.State |
| Field Summary | |
static int |
ACCEPTED
The machine acceptance state. |
protected java.lang.StringBuffer |
inputTape
The input tape. |
static int |
LEFT
Move the tape left. |
static int |
MACHINE_LEFT
Move the machine left (equivalent to RIGHT). |
static int |
MACHINE_RIGHT
Move the machine right (equal to LEFT). |
static int |
MACHINE_STOP
A final, stopping state (equivalent to STOP). |
protected int |
machineState
The state the machine is in (ACCEPTED, UNDECIDED, REJECTED). |
static int |
REJECTED
The machine rejection state. |
static int |
RENDER_LARGE
Set the render size of the FSM/Turing Machine as large. |
static int |
RENDER_NORMAL
Set the render size of the FSM/Turing Machine as normal. |
static int |
RENDER_SMALL
Set the render size of the Turing Machine as small. |
static int |
RIGHT
Move the tape right. |
static int |
STOP
A final, stopping state. |
protected int |
tapeDirection
The direction the tape is moving in. |
protected int |
tapePosition
The position the tape is in. |
static int |
UNDECIDED
The machine is in an undecided state. |
| Fields inherited from class org.generation5.ai.FSM |
currentState, fsmStates, numStates, renderSize |
| Constructor Summary | |
TuringMachine()
Creates a new instance of TuringMachine |
|
| Method Summary | |
void |
addTransition(FSM.State start,
int transition,
FSM.State end)
Add a transition state between the specified start and end states for the given transition symbol. |
void |
doAnimate()
doAnimate animates the Turing Machine transitioning from one tape
position to the next. |
void |
doStep()
Steps the Turing Machine using the tape position and input tape:
transition(inputTape.charAt(tapePosition));
|
int |
getMachineState()
Return the current machine state. |
java.lang.String |
getTape()
Return the input tape in non-mutable String form. |
void |
init()
Initializes the Turing Machine to its default settings. |
void |
render(java.awt.Graphics g,
int width,
int height)
Render the Turing Machine. |
void |
renderAsFSM(java.awt.Graphics g,
int width,
int height)
Render the Turing Machine as a finite-state machine. |
void |
reset()
Resets the input tape, removes all the states and calls init. |
int |
runMachine(java.lang.StringBuffer input,
int start)
This function simply runs the machine with a given input until the input is accepted or rejected. |
int |
runMachine(java.lang.String input,
int start)
This function simply runs the machine with a given input until the input is accepted or rejected. |
void |
setInputTape(java.lang.StringBuffer input,
int start)
Set the input tape. |
void |
setInputTape(java.lang.String input,
int start)
Set the input tape. |
void |
setRenderSize(int renderSize)
Set the render size. |
void |
setTapeDirection(int td)
Set the tape direction. |
java.lang.String |
toString()
Converts the Turing Machine to a string. |
FSM.State |
transition(int transition)
Transitions the Turing Machine from one state to another. |
| Methods inherited from class org.generation5.ai.FSM |
addState, addStates, getCurrentState, getRenderSize, getState, getStates, main, removeAllStates, setState, writeImage |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int LEFT
public static final int RIGHT
public static final int STOP
public static final int MACHINE_LEFT
public static final int MACHINE_RIGHT
public static final int MACHINE_STOP
public static final int ACCEPTED
public static final int UNDECIDED
public static final int REJECTED
public static final int RENDER_SMALL
public static final int RENDER_NORMAL
public static final int RENDER_LARGE
protected java.lang.StringBuffer inputTape
protected int tapePosition
protected int machineState
protected int tapeDirection
| Constructor Detail |
public TuringMachine()
| Method Detail |
public int getMachineState()
ACCEPTED,
REJECTED,
UNDECIDED
public void setInputTape(java.lang.String input,
int start)
StringBuffer. The initial position also needs to be set.
input - the input string.start - the tape position.public void setTapeDirection(int td)
td - the tape direction (LEFT or RIGHT).
public void setInputTape(java.lang.StringBuffer input,
int start)
input - A mutable StringBuffer.start - the initial tape position.setInputTape(String, int)public FSM.State transition(int transition)
transition in class FSMtransition - the transition input.
public void addTransition(FSM.State start,
int transition,
FSM.State end)
addTransition in class FSMstart - the start state.transition - the transition symbol.end - the end state.
public int runMachine(java.lang.String input,
int start)
input - the input tape.start - the start position of the tape.
public int runMachine(java.lang.StringBuffer input,
int start)
input - the input tape.start - the start position of the tape.
public void doAnimate()
doAnimate animates the Turing Machine transitioning from one tape
position to the next. The animation system animates that tape moving left or
right.
public void doStep()
transition(inputTape.charAt(tapePosition));
doStep in interface Steppablepublic void init()
init in interface Steppablepublic void reset()
init.
reset in interface Steppableinit()public java.lang.String toString()
Tape = 1[ ]1, State = q1, Position = 4, I/O State = Undecided
Only the three most immediate tape characters are shown, as well as the current
state, tape position and machine state.
public java.lang.String getTape()
public void setRenderSize(int renderSize)
setRenderSize in class FSMrenderSize - the render size.
public void render(java.awt.Graphics g,
int width,
int height)
render in interface Visualizablerender in class FSMg - the graphics context.width - the width of the context.height - the height of the context.
public void renderAsFSM(java.awt.Graphics g,
int width,
int height)
g - the graphics context.width - the width of the context.height - the height of the context.
|
This documentation is part of the Generation5 JDK.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||