Simulation Class Reference

Class for a one row simulation. More...

#include <simulation.hpp>

Collaboration diagram for Simulation:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Simulation (SimulationView *view, SimulationManager *controller, Grid initialLayout, list< Rule > *rules, list< ForbiddenPattern > *patterns)
 Constructor.
virtual ~Simulation ()
 Destructor.
bool isFinished ()
 Simulation status.
bool nextStep (bool gui)
 Performs a simulation step.
void nextRow ()
 Asks the controller for another row to simulate.
void results ()
 Asks the controller to show the simulation results.
void simulateAll ()
 Simulates all the rows of the simulation.
void resetSimulation (SimulationView *view, SimulationManager *controller, Grid initialLayout, list< Rule > *rules, list< ForbiddenPattern > *patterns)
 Sets the parameters for a new simulation.
list< simulationStepgetStableLayouts ()
 Returns the stable spaces.
list< GridgetProcessedLayouts ()
 Returns the spaces simulated.
list< simulationStepgetForbiddenLayouts ()
 Returns the forbidden spaces.
list< simulationStepgetCycles ()
 Returns the cycle spaces.

Private Member Functions

list< coordinatefindRule (Grid layout, Rule rule)
 Finds a rule in a space.
list< coordinatefindPattern (Grid layout, ForbiddenPattern pattern)
 Finds a forbidden in a space.
Grid applyRule (Grid layout, Rule rule, coordinate position)
 Applies a rule to a space.
bool ruleApplicable (Grid layout, coordinate position, Rule rule)
 Finds if a rule is applicable in a certain coordinate of a space.
void printRule (Rule rule)
 Prints a rule to the standard output.
void printLayout (Grid layout)
 Prints a grid to the standard output.
bool find (Grid initialLayout, list< Grid > *processedLayouts)
 Finds a grid on a grid list.
bool patternApplicable (Grid layout, coordinate position, ForbiddenPattern pattern)
 Finds if a pattern is applicable in a certain coordinate of a space.
void updateView ()
 Updates the simulation view with flow control information.

Private Attributes

SimulationViewview
 Simulation presentation layer.
SimulationManagercontroller
 Simulation controller.
list< simulationStep > * finalLayouts
 List of stable layouts reached through the simulation.
list< simulationStep > * patternsToSimulate
 List of patterns to still be simulated.
list< Grid > * patternsSimulated
 List of spaces which already have been simulated.
list< simulationStep > * forbiddenPatternsFound
 List of forbidden patterns found during the simulation.
list< simulationStep > * cycles
 List of cycles found during the simulation.
list< Rule > * rules
 List of rules to test.
list< ForbiddenPattern > * patterns
 List of forbidden patterns to test.
bool finished
 Is the simulation finished?
bool simulating
 Are we in a step?
bool stillRows
 There are more rows to simulate?

Detailed Description

Class for a one row simulation.

This class is used to simulate rows of a truth table. It gets the initial configuration, the rules and forbidden patterns to use, and it simulates step by step until all the spaces have been simulated or an error occurs.

Author:
Bernat Ràfales Mulet <the_bell@users.sourceforge.net>
Version:
Revision
1.8

Definition at line 61 of file simulation.hpp.


Constructor & Destructor Documentation

Simulation::Simulation SimulationView view,
SimulationManager controller,
Grid  initialLayout,
list< Rule > *  rules,
list< ForbiddenPattern > *  patterns
 

Constructor.

Parameters:
view the simulation view.
controller the simulation controller.
initialLayout the initial space to simulate.
rules the rule list to be applied.
patterns the forbidden pattern list to be found.

Definition at line 35 of file simulation.cpp.

References controller, cycles, finalLayouts, finished, forbiddenPatternsFound, patternsSimulated, patternsToSimulate, SimulationView::setGrid(), simulating, simulationStep::space, stillRows, and view.

Here is the call graph for this function:

Simulation::~Simulation  )  [virtual]
 

Destructor.

Definition at line 58 of file simulation.cpp.


Member Function Documentation

Grid Simulation::applyRule Grid  layout,
Rule  rule,
coordinate  position
[private]
 

Applies a rule to a space.

Parameters:
layout the space where to apply the rule.
rule the rule to be applied.
position coordinate where to apply the rule.
Returns:
A new grid with the rule applied.

Definition at line 126 of file simulation.cpp.

References Rule::getFinalGrid(), Rule::getHeight(), Rule::getInitialGrid(), Rule::getWidth(), nDISABLED, nDONTCARE, coordinate::x, and coordinate::y.

Here is the call graph for this function:

bool Simulation::find Grid  initialLayout,
list< Grid > *  processedLayouts
[private]
 

Finds a grid on a grid list.

Parameters:
initialLayout the grid to find.
processedLayouts the grid list.
Returns:
True iif the grid was found on the list.

Definition at line 269 of file simulation.cpp.

list< coordinate > Simulation::findPattern Grid  layout,
ForbiddenPattern  pattern
[private]
 

Finds a forbidden in a space.

Parameters:
layout the space.
pattern the pattern to be found.
Returns:
A list of all the coordinates where the pattern has been found.

Definition at line 98 of file simulation.cpp.

References Grid::getHeight(), Grid::getWidth(), and patternApplicable().

Referenced by nextStep().

Here is the call graph for this function:

list< coordinate > Simulation::findRule Grid  layout,
Rule  rule
[private]
 

Finds a rule in a space.

Parameters:
layout the space.
rule the rule to be found.
Returns:
A list of all the coordinates where the rule has been found.

Definition at line 70 of file simulation.cpp.

References Grid::getHeight(), Grid::getWidth(), and ruleApplicable().

Here is the call graph for this function:

list< simulationStep > Simulation::getCycles  ) 
 

Returns the cycle spaces.

Returns:
The list of spaces the simulation has obtained that are a cycle. Every item on the list is a space and a trace of the spaces that lead to it in the simulation branch.

Definition at line 660 of file simulation.cpp.

References cycles.

Referenced by SimulationManager::finishedRow().

list< simulationStep > Simulation::getForbiddenLayouts  ) 
 

Returns the forbidden spaces.

Returns:
The list of spaces the simulation has obtained that contain a forbidden pattern. Every item on the list is a space and a trace of the spaces that lead to it in the simulation branch.

Definition at line 643 of file simulation.cpp.

References forbiddenPatternsFound.

Referenced by SimulationManager::finishedRow().

list< Grid > Simulation::getProcessedLayouts  ) 
 

Returns the spaces simulated.

Returns:
A list of all the spaces that have been simulated.

Definition at line 625 of file simulation.cpp.

References patternsSimulated.

Referenced by SimulationManager::finishedRow().

list< simulationStep > Simulation::getStableLayouts  ) 
 

Returns the stable spaces.

Returns:
The list of stable spaces the simulation has obtained. Every item on the list is a space and a trace of the spaces that lead to it in the simulation branch.

Definition at line 610 of file simulation.cpp.

References finalLayouts.

Referenced by SimulationManager::finishedRow().

bool Simulation::isFinished  ) 
 

Simulation status.

Returns:
True if the simulation has finished, false otherwise.

Definition at line 335 of file simulation.cpp.

References finished.

void Simulation::nextRow  ) 
 

Asks the controller for another row to simulate.

Definition at line 579 of file simulation.cpp.

References controller, SimulationView::enableSimulation(), SimulationManager::nextRow(), SimulationView::setNextRow(), SimulationView::setResults(), SimulationManager::simulateRow(), and view.

Referenced by SimulationView::OnNext().

Here is the call graph for this function:

bool Simulation::nextStep bool  gui  ) 
 

Performs a simulation step.

It gets a space to be simulated, checks if it's a valid space, that is, it does not have any forbidden pattern. Then searches for rules to apply to it. If it does not find any rule, it saves the space as a stable layout. Otherwise, it applies the rules it finds, and queue the new spaces to be simulated if they're not repeated.

Parameters:
gui True if the view has to be updated with the changes and simulation information.
Returns:
True if the simulation step was performed without errors.

Definition at line 355 of file simulation.cpp.

References findPattern(), finished, patterns, patternsSimulated, patternsToSimulate, SimulationView::setGrid(), SimulationView::setInfo(), simulating, simulationStep::space, updateView(), and view.

Referenced by SimulationView::OnStep(), SimulationView::OnTimer(), and simulateAll().

Here is the call graph for this function:

bool Simulation::patternApplicable Grid  layout,
coordinate  position,
ForbiddenPattern  pattern
[private]
 

Finds if a pattern is applicable in a certain coordinate of a space.

Parameters:
layout the space.
position the coordinate to find the pattern applicability.
pattern the pattern to be found.
Returns:
True if the pattern is applicable at te given coordinate.

Definition at line 289 of file simulation.cpp.

References Grid::getWidth(), ForbiddenPattern::getWidth(), and coordinate::x.

Referenced by findPattern().

Here is the call graph for this function:

void Simulation::printLayout Grid  layout  )  [private]
 

Prints a grid to the standard output.

This is for debugging purposes only.

Parameters:
layout the grid to be printed.

Definition at line 246 of file simulation.cpp.

References Grid::getWidth().

Here is the call graph for this function:

void Simulation::printRule Rule  rule  )  [private]
 

Prints a rule to the standard output.

This is for debugging purposes only.

Parameters:
rule the rule to be printed.

Definition at line 208 of file simulation.cpp.

References Rule::getWidth().

Here is the call graph for this function:

void Simulation::resetSimulation SimulationView view,
SimulationManager controller,
Grid  initialLayout,
list< Rule > *  rules,
list< ForbiddenPattern > *  patterns
 

Sets the parameters for a new simulation.

Parameters:
view the simulation view.
controller the simulation controller.
initialLayout the initial space to simulate.
rules the rule list to be applied.
patterns the forbidden pattern list to be found.

Definition at line 679 of file simulation.cpp.

References controller, cycles, finalLayouts, finished, forbiddenPatternsFound, patternsSimulated, patternsToSimulate, SimulationView::setGrid(), simulationStep::space, stillRows, SimulationView::stopSimulation(), and view.

Here is the call graph for this function:

void Simulation::results  ) 
 

Asks the controller to show the simulation results.

Definition at line 598 of file simulation.cpp.

References controller, and SimulationManager::results().

Referenced by SimulationView::OnResults().

Here is the call graph for this function:

bool Simulation::ruleApplicable Grid  layout,
coordinate  position,
Rule  rule
[private]
 

Finds if a rule is applicable in a certain coordinate of a space.

Parameters:
layout the space.
position the coordinate to find the rule applicability.
rule the rule to be found.
Returns:
True if the rule is applicable at te given coordinate. That is, if the initial configuration matches the sub grid at the space coordinate.

Definition at line 160 of file simulation.cpp.

References Grid::getWidth(), Rule::getWidth(), and coordinate::x.

Referenced by findRule().

Here is the call graph for this function:

void Simulation::simulateAll  ) 
 

Simulates all the rows of the simulation.

This method simulates all the rows in a shot, without the timer and user interactivity. Useful for quick simulations.

Definition at line 709 of file simulation.cpp.

References controller, SimulationView::enableSimulation(), finished, SimulationManager::nextRow(), nextStep(), SimulationView::setNextRow(), SimulationView::setResults(), SimulationManager::simulateRow(), stillRows, and view.

Referenced by SimulationView::OnForward().

Here is the call graph for this function:

void Simulation::updateView  )  [private]
 

Updates the simulation view with flow control information.

This method updates the view to allow the user simulate other rows and view the simulation results when the simulation is over.

Definition at line 558 of file simulation.cpp.

References controller, SimulationView::enableSimulation(), finished, SimulationManager::nextRow(), SimulationView::setNextRow(), SimulationView::setResults(), and view.

Referenced by nextStep().

Here is the call graph for this function:


Member Data Documentation

SimulationManager* Simulation::controller [private]
 

Simulation controller.

Definition at line 90 of file simulation.hpp.

Referenced by nextRow(), resetSimulation(), results(), simulateAll(), Simulation(), and updateView().

list<simulationStep>* Simulation::cycles [private]
 

List of cycles found during the simulation.

Definition at line 100 of file simulation.hpp.

Referenced by getCycles(), resetSimulation(), and Simulation().

list<simulationStep>* Simulation::finalLayouts [private]
 

List of stable layouts reached through the simulation.

Definition at line 92 of file simulation.hpp.

Referenced by getStableLayouts(), resetSimulation(), and Simulation().

bool Simulation::finished [private]
 

Is the simulation finished?

Definition at line 106 of file simulation.hpp.

Referenced by isFinished(), nextStep(), resetSimulation(), simulateAll(), Simulation(), and updateView().

list<simulationStep>* Simulation::forbiddenPatternsFound [private]
 

List of forbidden patterns found during the simulation.

Definition at line 98 of file simulation.hpp.

Referenced by getForbiddenLayouts(), resetSimulation(), and Simulation().

list<ForbiddenPattern>* Simulation::patterns [private]
 

List of forbidden patterns to test.

Definition at line 104 of file simulation.hpp.

Referenced by nextStep().

list<Grid>* Simulation::patternsSimulated [private]
 

List of spaces which already have been simulated.

Definition at line 96 of file simulation.hpp.

Referenced by getProcessedLayouts(), nextStep(), resetSimulation(), and Simulation().

list<simulationStep>* Simulation::patternsToSimulate [private]
 

List of patterns to still be simulated.

Definition at line 94 of file simulation.hpp.

Referenced by nextStep(), resetSimulation(), and Simulation().

list<Rule>* Simulation::rules [private]
 

List of rules to test.

Definition at line 102 of file simulation.hpp.

bool Simulation::simulating [private]
 

Are we in a step?

Definition at line 108 of file simulation.hpp.

Referenced by nextStep(), and Simulation().

bool Simulation::stillRows [private]
 

There are more rows to simulate?

Definition at line 110 of file simulation.hpp.

Referenced by resetSimulation(), simulateAll(), and Simulation().

SimulationView* Simulation::view [private]
 

Simulation presentation layer.

Definition at line 88 of file simulation.hpp.

Referenced by nextRow(), nextStep(), resetSimulation(), simulateAll(), Simulation(), and updateView().


The documentation for this class was generated from the following files:
Generated on Sat Sep 2 00:00:28 2006 for NanoComp by  doxygen 1.4.6