ro.inf.p2.odd.alan
Class TuringMachine

java.lang.Object
  extended by ro.inf.p2.odd.alan.Tape
      extended by ro.inf.p2.odd.alan.TuringMachine

public class TuringMachine
extends Tape

Class TuringMachine This class implements a complete Turing Machine which is described by the formula M = (Q,Sigma, Gamma, delta, q0, B, F) where: - Q is a finite set of states - Gamma is a finite set of the tape alphabet - Sigma is a finite set of the input symbols (subset of Gamma) - delta is the set of transistion functions - q0 is the initial state (member of Q) - B is the BLANK symbol - F is set of final accepting states (subset of Q) You can either execute the turing machine with execute and just get the results or walk step by step through the execution using start() and nextStep(). The turing machine can be checked for valid initialization with the isValid() method.

See Also:
execute, start, nextStep, isValid

Nested Class Summary
static class TuringMachine.Direction
          This enum describes the possible ways to move for the tape.
 
Field Summary
static char BLANK
           
static java.io.File DEFAULT_FILE
           
 
Constructor Summary
TuringMachine()
          Create a new Turing Machine which will be initialized with default values.
 
Method Summary
 boolean execute()
          Executes the TuringMachine with the current settings.
 char getBlank()
          Das Leerzeichen B.
 int getCurrentState()
          Allows to retrieve the current state of the turing machine.
 java.lang.String getDescription()
          Gets the description of this turing machine object
 java.util.List<java.lang.Integer> getFinalState()
          F ist die Menge der akzeptierten Endzust?nde.
 java.lang.String getGamma()
          VollstaendigeMenge der Bandsymbole.
 int getInitialState()
          Index der Uebergangsfunktion in ro die den Start Zustand beschreibt.
 java.util.List<java.util.Map<java.lang.Character,TransitionFunctionElement>> getQ()
          Endliche Menge der zust?nde der endlichen Steuerung.
 java.lang.String getSigma()
          Die endliche menge der Eingabesymbole.
 boolean isValid()
          Checks wether this machine can be started using start() safely.
 void loadDefaults()
          Initialize the TuringMachine with default values, so that isValid returns true.
 boolean loadFromFile(java.io.File file)
          Load the turing machines settings from a xml file which was created by TuringMachine.saveToFile() before.
 boolean nextStep()
          Executes the next step of the turing machine.
 boolean saveToFile(java.io.File file)
          Save all settings of the turing machine to a file in XML format.
 void setBlank(char value)
          Das Leerzeichen B.
 void setDescription(java.lang.String description)
          Sets the comment description of this turing machine object
 void setFinalState(java.util.List<java.lang.Integer> f)
          F ist die Menge der akzeptierten Endzustaende.
 void setGamma(java.lang.String value)
          VollstaendigeMenge der Bandsymbole.
 void setInitialState(int value)
          Index der Uebergangsfunktion in ro die den Start Zustand beschreibt.
 void setQ(java.util.List<java.util.Map<java.lang.Character,TransitionFunctionElement>> value)
          Endliche Menge der Zustaende der endlichen Steuerung.
 void setSigma(java.lang.String value)
          Die endliche menge der Eingabesymbole.
 boolean start()
          start the execution of the turing machine
 void stop()
          stop execution of the turing machine
 
Methods inherited from class ro.inf.p2.odd.alan.Tape
getCurrentValue, moveLeft, moveRight, moveStart, offsetToLeftMostChar, setContent, setCurrentValue, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BLANK

public static final char BLANK
See Also:
Constant Field Values

DEFAULT_FILE

public static final java.io.File DEFAULT_FILE
Constructor Detail

TuringMachine

public TuringMachine()
Create a new Turing Machine which will be initialized with default values.

Method Detail

start

public boolean start()
start the execution of the turing machine

Returns:
true if the start was sucessful, otherwise false is returned

nextStep

public boolean nextStep()
                 throws java.lang.IllegalArgumentException
Executes the next step of the turing machine. To get the current value on the band you can use

Returns:
true if sucessfull and false if no next step is available. If no next step is available the TuringMachine will be stopped
Throws:
java.lang.IllegalArgumentException
See Also:
toString

getCurrentState

public int getCurrentState()
Allows to retrieve the current state of the turing machine.

Returns:
int - current state of the turing machine

stop

public void stop()
stop execution of the turing machine


execute

public boolean execute()
Executes the TuringMachine with the current settings. Only the end result can be obtained using the @see toString() method. start() and nextStep() are called by this method for you.

Returns:
true on success

isValid

public boolean isValid()
Checks wether this machine can be started using start() safely.

Returns:
true if the current settings are valid and if the machine can be started other wise return false
See Also:
start

loadDefaults

public void loadDefaults()
Initialize the TuringMachine with default values, so that isValid returns true.


saveToFile

public boolean saveToFile(java.io.File file)
Save all settings of the turing machine to a file in XML format.

Parameters:
file - File where the data is saved
Returns:
true/false if saving was successfull/unsuccessfull

loadFromFile

public boolean loadFromFile(java.io.File file)
Load the turing machines settings from a xml file which was created by TuringMachine.saveToFile() before.

Parameters:
file - load from this file
Returns:
true if loading was sucessfull, otherwise false

getQ

public java.util.List<java.util.Map<java.lang.Character,TransitionFunctionElement>> getQ()
Endliche Menge der zust?nde der endlichen Steuerung.


setQ

public void setQ(java.util.List<java.util.Map<java.lang.Character,TransitionFunctionElement>> value)
Endliche Menge der Zustaende der endlichen Steuerung. Haellt die TuringMaschine an falls sie laeuft.


getSigma

public java.lang.String getSigma()
Die endliche menge der Eingabesymbole.


setSigma

public void setSigma(java.lang.String value)
Die endliche menge der Eingabesymbole. Haellt die TuringMaschine an falls sie laeuft.


getGamma

public java.lang.String getGamma()
VollstaendigeMenge der Bandsymbole. Sigma ist Teilmenge von Gamma.


setGamma

public void setGamma(java.lang.String value)
VollstaendigeMenge der Bandsymbole. Sigma ist Teilmenge von Gamma. Haellt die TuringMaschine an falls sie laeuft.


getInitialState

public int getInitialState()
Index der Uebergangsfunktion in ro die den Start Zustand beschreibt.


setInitialState

public void setInitialState(int value)
Index der Uebergangsfunktion in ro die den Start Zustand beschreibt. Haellt die TuringMaschine an falls sie laeuft.


getBlank

public char getBlank()
Das Leerzeichen B. Enthalten in Gamma aber nicht in Sigma.


setBlank

public void setBlank(char value)
Das Leerzeichen B. Enthalten in Gamma aber nicht in Sigma. Haellt die TuringMaschine an falls sie laeuft.


getFinalState

public java.util.List<java.lang.Integer> getFinalState()
F ist die Menge der akzeptierten Endzust?nde. Teilmenge von Q.


setFinalState

public void setFinalState(java.util.List<java.lang.Integer> f)
F ist die Menge der akzeptierten Endzustaende. Teilmenge von Q. Haellt die TuringMaschine an falls sie laeuft.


getDescription

public java.lang.String getDescription()
Gets the description of this turing machine object

Returns:
m_description The comment description as a string

setDescription

public void setDescription(java.lang.String description)
Sets the comment description of this turing machine object

Parameters:
description - The comment description as a string