MTMS main
Modern Turing Machine Simulator
Loading...
Searching...
No Matches
TuringMachine Class Reference

The central execution engine representing a deterministic Multi-Tape Turing Machine. More...

#include <tm.hpp>

Collaboration diagram for TuringMachine:

Public Member Functions

std::size_t add_transition (State current, State next, std::vector< Symbol > read, std::vector< Symbol > write, std::vector< Direction > dir) noexcept(false)
 Adds a transition to the machine.
 
bool contains_transition (std::size_t id) const noexcept
 Checks whether the machine contains a specific transition.
 
const Stateget_current_state () const noexcept
 Retrieves the active operational state context marker.
 
const Alphabetget_input_alphabet () const noexcept
 Retrieves the formal input validation alphabet.
 
const Stateget_start_state () const noexcept
 Retrieves the factory default initial state configuration.
 
const std::set< State > & get_states () const noexcept
 Retrieves the complete formal set of legal operational state conditions.
 
const Alphabetget_tape_alphabet () const noexcept
 Retrieves the wider operational tape workspace alphabet.
 
std::size_t get_tape_count () const noexcept
 Retrieves the total cardinality of parallel tapes operating inside the machine.
 
const std::vector< Tape > & get_tapes () const noexcept
 Retrieves the entire collection layout of parallel tape tracks.
 
Transitionget_transition (std::size_t id) noexcept
 Retrieves a pointer to a transition by its unique runtime identifier.
 
const std::unordered_map< std::size_t, Transition > & get_transitions () const noexcept
 Retrieves the entire lookup table of transitions.
 
bool load_input (std::string_view input) noexcept(false)
 Validates an input word against the input alphabet and loads it onto Tape 0.
 
bool remove_transition (std::size_t id) noexcept
 Removes a transition from the machine.
 
void run () noexcept(false)
 Loops execution triggers calling step() continuously until a halting condition occurs or the safety step counter threshold breaks execution.
 
bool step () noexcept(false)
 Executes a single computational transition step across all parallel tapes.
 
 TuringMachine () noexcept
 Default constructor.
 
 TuringMachine (Alphabet input_alpha, Alphabet tape_alpha, std::set< State > states, State initial_state, std::size_t tape_count) noexcept(false)
 Explicit constructor to fully instantiate a Multi-Tape Turing Machine configuration.
 

Private Attributes

State current_state_
 Active contextual processing marker.
 
std::size_t id_counter_ {0}
 Unique runtime identifier counter for transitions.
 
Alphabet input_alphabet_
 Input validation vocabulary ( $\Sigma$).
 
State start_state_
 Factory default backup tracking state.
 
std::set< Statestates_
 Valid configurations collection.
 
Alphabet tape_alphabet_
 Structural execution workspace vocabulary ( $\Gamma$).
 
std::size_t tape_count_
 Cardinality multiplier tracking active tapes (k).
 
std::vector< Tapetapes_
 Collection of k dynamic memory layouts.
 
std::unordered_map< std::size_t, Transitiontransitions_
 Lookup table for transitions by ID.
 

Detailed Description

The central execution engine representing a deterministic Multi-Tape Turing Machine.

Manages an arbitrary number of parallel structural Tapes, dispatching updates simultaneously using synchronized multi-dimensional transition rules.

Definition at line 32 of file tm.hpp.

Constructor & Destructor Documentation

◆ TuringMachine() [1/2]

TuringMachine::TuringMachine ( )
inlinenoexcept

Default constructor.

Creates an uninitialized machine.

Definition at line 38 of file tm.hpp.

◆ TuringMachine() [2/2]

TuringMachine::TuringMachine ( Alphabet  input_alpha,
Alphabet  tape_alpha,
std::set< State states,
State  initial_state,
std::size_t  tape_count 
)
explicit

Explicit constructor to fully instantiate a Multi-Tape Turing Machine configuration.

Parameters
input_alphaThe initial string input validation alphabet ( $\Sigma$).
tape_alphaThe wider tape work alphabet ( $\Gamma$).
statesThe complete set of legal operational conditions (Q).
initial_stateThe point of origin state where processing starts ( $q_0$).
tape_countThe total number of parallel tape tracks available (k).

Definition at line 22 of file tm.cpp.

Member Function Documentation

◆ add_transition()

std::size_t TuringMachine::add_transition ( State  current,
State  next,
std::vector< Symbol read,
std::vector< Symbol write,
std::vector< Direction dir 
)
inline

Adds a transition to the machine.

Allocates and stores a new multi-tape rule inside the internal lookup map. This operation provides a strong exception guarantee; if an exception is thrown, the machine's state and internal ID counter remain completely unmodified.

Parameters
currentThe required state to trigger this transition.
nextThe target state the machine will transition into.
readThe collection of symbols expected under each parallel tape head.
writeThe collection of new symbols to overwrite onto each tape track.
dirThe collection of displacement directions for each tape head.
Returns
std::size_t The unique runtime identifier assigned to the new transition.
Exceptions
std::bad_allocIf the internal map fails to allocate memory for the new node or during an automatic rehash operation.

Definition at line 159 of file tm.hpp.

References id_counter_, and transitions_.

◆ contains_transition()

bool TuringMachine::contains_transition ( std::size_t  id) const
inlinenoexcept

Checks whether the machine contains a specific transition.

Parameters
idThe unique runtime identifier of the transition.
Returns
true If the transition is contained in the machine, false if it is not.

Definition at line 214 of file tm.hpp.

References transitions_.

◆ get_current_state()

const State & TuringMachine::get_current_state ( ) const
inlinenoexcept

Retrieves the active operational state context marker.

Returns
const State& A read-only reference to the current execution state.

Definition at line 116 of file tm.hpp.

References current_state_.

Referenced by render_dashboard(), and run_cli_session().

◆ get_input_alphabet()

const Alphabet & TuringMachine::get_input_alphabet ( ) const
inlinenoexcept

Retrieves the formal input validation alphabet.

Returns
const Alphabet& A read-only reference to the Sigma ( $\Sigma$) set.

Definition at line 86 of file tm.hpp.

References input_alphabet_.

◆ get_start_state()

const State & TuringMachine::get_start_state ( ) const
inlinenoexcept

Retrieves the factory default initial state configuration.

Returns
const State& A read-only reference to the origin state ( $q_0$).

Definition at line 110 of file tm.hpp.

References start_state_.

◆ get_states()

const std::set< State > & TuringMachine::get_states ( ) const
inlinenoexcept

Retrieves the complete formal set of legal operational state conditions.

Returns
const std::set<State>& A read-only reference to the state collection space (Q).

Definition at line 104 of file tm.hpp.

References states_.

◆ get_tape_alphabet()

const Alphabet & TuringMachine::get_tape_alphabet ( ) const
inlinenoexcept

Retrieves the wider operational tape workspace alphabet.

Returns
const Alphabet& A read-only reference to the Gamma ( $\Gamma$) set.

Definition at line 95 of file tm.hpp.

References tape_alphabet_.

◆ get_tape_count()

std::size_t TuringMachine::get_tape_count ( ) const
inlinenoexcept

Retrieves the total cardinality of parallel tapes operating inside the machine.

Returns
std::size_t The structural tape multiplier metrics (k).

Definition at line 139 of file tm.hpp.

References tape_count_.

◆ get_tapes()

const std::vector< Tape > & TuringMachine::get_tapes ( ) const
inlinenoexcept

Retrieves the entire collection layout of parallel tape tracks.

Returns
const std::vector<Tape>& A read-only reference to the k-tape data array.

Definition at line 122 of file tm.hpp.

References tapes_.

Referenced by render_dashboard().

◆ get_transition()

Transition * TuringMachine::get_transition ( std::size_t  id)
inlinenoexcept

Retrieves a pointer to a transition by its unique runtime identifier.

Parameters
idThe unique runtime identifier of the transition.
Returns
Transition* A pointer to the transition if found, nullptr otherwise.

Definition at line 190 of file tm.hpp.

References transitions_.

◆ get_transitions()

const std::unordered_map< std::size_t, Transition > & TuringMachine::get_transitions ( ) const
inlinenoexcept

Retrieves the entire lookup table of transitions.

Returns
const std::unordered_map<std::size_t, Transition>& A read-only reference to the transition map.

Definition at line 130 of file tm.hpp.

References transitions_.

◆ load_input()

bool TuringMachine::load_input ( std::string_view  input)

Validates an input word against the input alphabet and loads it onto Tape 0.

Validates input string and loads it exclusively onto the FIRST tape (Tape 0).

Clears all secondary tracks, filling them with virtual blank context variables.

Parameters
inputThe raw character view representation to parse.
Returns
true If the input string belongs entirely to the input alphabet, false otherwise.

All secondary work tapes (1 to k-1) remain empty (filled with virtual kBlank).

Definition at line 41 of file tm.cpp.

References String::is_valid_for().

Referenced by run_cli_session().

◆ remove_transition()

bool TuringMachine::remove_transition ( std::size_t  id)
inlinenoexcept

Removes a transition from the machine.

Parameters
idThe unique runtime identifier of the transition to remove.
Returns
true If the transition was successfully erased, false if the transition was not removed.

Definition at line 206 of file tm.hpp.

References transitions_.

◆ run()

void TuringMachine::run ( )

Loops execution triggers calling step() continuously until a halting condition occurs or the safety step counter threshold breaks execution.

Operational runtime loop triggering sequential computation steps.

Integrates a safety threshold loop counter (kMaxSteps) to force-halt execution and prevent infinite runtime hanging situations inside the sandbox environment.

Definition at line 111 of file tm.cpp.

References kMaxSteps, and step().

◆ step()

bool TuringMachine::step ( )

Executes a single computational transition step across all parallel tapes.

Executes a single computational transition step across ALL parallel tapes.

Queries multi-tape rules matching the active conditions vector layout.

Returns
true If a valid transition was found and executed successfully, false if the machine halted or broke down.

Scans symbols from every tape head, matches the collective tuple against the multi-tape transition matrix, and updates all tracks simultaneously.

Definition at line 61 of file tm.cpp.

References current_state_, Transition::get_directions(), Transition::get_next_state(), Transition::get_write_symbols(), State::is_accept(), tape_count_, tapes_, and transitions_.

Referenced by run(), and run_cli_session().

Member Data Documentation

◆ current_state_

State TuringMachine::current_state_
private

Active contextual processing marker.

Definition at line 225 of file tm.hpp.

Referenced by get_current_state(), and step().

◆ id_counter_

std::size_t TuringMachine::id_counter_ {0}
private

Unique runtime identifier counter for transitions.

Definition at line 220 of file tm.hpp.

Referenced by add_transition().

◆ input_alphabet_

Alphabet TuringMachine::input_alphabet_
private

Input validation vocabulary ( $\Sigma$).

Definition at line 221 of file tm.hpp.

Referenced by get_input_alphabet().

◆ start_state_

State TuringMachine::start_state_
private

Factory default backup tracking state.

Definition at line 224 of file tm.hpp.

Referenced by get_start_state().

◆ states_

std::set<State> TuringMachine::states_
private

Valid configurations collection.

Definition at line 223 of file tm.hpp.

Referenced by get_states().

◆ tape_alphabet_

Alphabet TuringMachine::tape_alphabet_
private

Structural execution workspace vocabulary ( $\Gamma$).

Definition at line 222 of file tm.hpp.

Referenced by get_tape_alphabet().

◆ tape_count_

std::size_t TuringMachine::tape_count_
private

Cardinality multiplier tracking active tapes (k).

Definition at line 229 of file tm.hpp.

Referenced by get_tape_count(), and step().

◆ tapes_

std::vector<Tape> TuringMachine::tapes_
private

Collection of k dynamic memory layouts.

Definition at line 226 of file tm.hpp.

Referenced by get_tapes(), and step().

◆ transitions_

std::unordered_map<std::size_t, Transition> TuringMachine::transitions_
private

Lookup table for transitions by ID.

Definition at line 228 of file tm.hpp.

Referenced by add_transition(), contains_transition(), get_transition(), get_transitions(), remove_transition(), and step().


The documentation for this class was generated from the following files: