simuLCS
Class Simulation

java.lang.Object
  extended bysimuLCS.Simulation

public class Simulation
extends java.lang.Object

Important class: handles the entities, the Thread for running the Simulation, and the Thread to update the Behaviour shown to the user when there is a GUI.

Author:
Benoit

Nested Class Summary
(package private)  class Simulation.Animation
          The inner class handling the simulation (MAIN PROCEDURE)
(package private)  class Simulation.TimerUpdate
          The task to be executed every X milliSeconds
 
Field Summary
protected  java.lang.Thread animation
           
protected  Arena arena
           
private  java.io.BufferedWriter bW
           
private  java.util.SortedSet entities
          The entities used in the Simulation
private  java.lang.String fileBaseForPlotting
           
private  java.lang.String fileBaseForSeveralPlotting
           
private  java.io.FileWriter fW
           
protected  java.util.Random generator
           
private  java.awt.Graphics2D graphics
           
private  java.awt.Graphics2D graphicsOffscreen
           
private  boolean hasAlreadyOneAgentInteractive
           
private  boolean isNewRun
          Used to know when to ask the name of the file
private  boolean isPlotting
           
private  boolean isSimuRunning
           
private  int maxTimeSteps
           
private  int nbAgentsToCreate
           
protected  int nbOfRuns
           
protected  int nbOfRunsDone
           
private  java.awt.Image offscreen
           
private  int plottingInterval
           
private  java.io.PrintWriter pW
           
private  boolean simuStep
          Used to run the simulation only for one step
private  int timeStep
           
private static int UPDATE_BEHAVIOUR_TO_SHOW
           
private  Utils utils
           
private  G_MainWindow window
           
 
Constructor Summary
Simulation(Utils u)
           
 
Method Summary
 void add()
          Add one default entity
 void add(Entity e)
          Adding the given entity to the Simulation.
 void add(int name)
          Add the default entity : the AgentClassifierLearning with the TemplateRSPVerySimple (by convention).
 void addWithChoice()
          The user can choose which Agent should be added, if there is a GUI otherwise, the default Agent is added.
 void clearSimu(java.awt.Graphics2D g)
          Erasing everything in the Drawing Panel
private  void closeFile()
          Close the data file and creates the gnuplot file and the file saving the rules at the end, for each agent
 void create()
           
 void create(int numAgents)
           
 void createAnimation()
          Creating the Thread for the Animation
 void finish()
          Stopping the simulation.
 java.util.Iterator getEntities()
           
 java.lang.String getFileBaseForPlotting()
           
 java.lang.String getFileBaseForSeveralPlotting()
           
static int getMaxNbEntities()
           
 int getMaxTimeSteps()
           
 int getNbOfRuns()
           
 int getNumberOfEntities()
           
private  void init()
          Initializing the simulation
 boolean isNewRun()
           
 boolean isSimuRunning()
           
 void launchUpdateThread(long timeInMilliSeconds)
          Launch the Thread that updates every timeInMilliSeconds the behaviour shown in the display (to avoid real-time, because it makes the simulation really slow)
 void linkToGraphics(G_MainWindow win)
           
private  void openFile()
          Open the file to start recording the average reward.
 void paintSimu(java.awt.Graphics2D g)
          Painting all the simulation
 void remove(Entity e)
          Removing the given entity to the simulation
 void reset()
          Starting again with the default simulation.
 void run()
          Starts the Thread Animation
 void setFileBaseForPlotting(java.lang.String string)
           
 void setFileBaseForSeveralPlotting(java.lang.String string)
           
 void setMaximumTimeSteps(int max)
           
 void setMaxTimeSteps(int i)
           
 void setNbOfRuns(int i)
           
 void setNewRun(boolean b)
           
 void start()
          Starting the simulation !
 void step()
          Just one time step more.
 void stop()
          Pausing the simulation.
 void updateBehaviours()
          The function to launch in the Thread updateTask
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entities

private java.util.SortedSet entities
The entities used in the Simulation


window

private G_MainWindow window

graphics

private java.awt.Graphics2D graphics

utils

private Utils utils

isSimuRunning

private boolean isSimuRunning

simuStep

private boolean simuStep
Used to run the simulation only for one step


isNewRun

private boolean isNewRun
Used to know when to ask the name of the file


nbOfRuns

protected int nbOfRuns

nbOfRunsDone

protected int nbOfRunsDone

isPlotting

private boolean isPlotting

plottingInterval

private int plottingInterval

fileBaseForPlotting

private java.lang.String fileBaseForPlotting

fileBaseForSeveralPlotting

private java.lang.String fileBaseForSeveralPlotting

fW

private java.io.FileWriter fW

bW

private java.io.BufferedWriter bW

pW

private java.io.PrintWriter pW

timeStep

private int timeStep

maxTimeSteps

private int maxTimeSteps

UPDATE_BEHAVIOUR_TO_SHOW

private static final int UPDATE_BEHAVIOUR_TO_SHOW
See Also:
Constant Field Values

animation

protected java.lang.Thread animation

nbAgentsToCreate

private int nbAgentsToCreate

hasAlreadyOneAgentInteractive

private boolean hasAlreadyOneAgentInteractive

generator

protected java.util.Random generator

offscreen

private java.awt.Image offscreen

graphicsOffscreen

private java.awt.Graphics2D graphicsOffscreen

arena

protected Arena arena
Constructor Detail

Simulation

public Simulation(Utils u)
Method Detail

linkToGraphics

public void linkToGraphics(G_MainWindow win)

add

public void add()
Add one default entity


add

public void add(int name)
Add the default entity : the AgentClassifierLearning with the TemplateRSPVerySimple (by convention).

Parameters:
name -

addWithChoice

public void addWithChoice()
The user can choose which Agent should be added, if there is a GUI otherwise, the default Agent is added.


add

public void add(Entity e)
Adding the given entity to the Simulation.

Parameters:
e -

remove

public void remove(Entity e)
Removing the given entity to the simulation

Parameters:
e -

paintSimu

public void paintSimu(java.awt.Graphics2D g)
Painting all the simulation

Parameters:
g -

clearSimu

public void clearSimu(java.awt.Graphics2D g)
Erasing everything in the Drawing Panel

Parameters:
g -

create

public void create()

create

public void create(int numAgents)

openFile

private void openFile()
Open the file to start recording the average reward.


closeFile

private void closeFile()
Close the data file and creates the gnuplot file and the file saving the rules at the end, for each agent

See Also:
Utils.writeFileGnuplot(String, Entity[], String), Utils.writeFileWithRules(String, Entity[])

start

public void start()
Starting the simulation !


stop

public void stop()
Pausing the simulation. It can be resumed.


finish

public void finish()
Stopping the simulation. It cannot be resumed. Files are closed , and a reset should be done before a new simulation.


step

public void step()
Just one time step more.


reset

public void reset()
Starting again with the default simulation.


init

private void init()
Initializing the simulation


createAnimation

public void createAnimation()
Creating the Thread for the Animation


launchUpdateThread

public void launchUpdateThread(long timeInMilliSeconds)
Launch the Thread that updates every timeInMilliSeconds the behaviour shown in the display (to avoid real-time, because it makes the simulation really slow)

Parameters:
timeInMilliSeconds -

run

public void run()
Starts the Thread Animation


updateBehaviours

public void updateBehaviours()
The function to launch in the Thread updateTask

See Also:
launchUpdateThread(long), Simulation.TimerUpdate

getMaxNbEntities

public static int getMaxNbEntities()
Returns:

getNumberOfEntities

public int getNumberOfEntities()
Returns:

getEntities

public java.util.Iterator getEntities()

isSimuRunning

public boolean isSimuRunning()
Returns:

isNewRun

public boolean isNewRun()
Returns:

setNewRun

public void setNewRun(boolean b)
Parameters:
b -

getFileBaseForPlotting

public java.lang.String getFileBaseForPlotting()
Returns:

setFileBaseForPlotting

public void setFileBaseForPlotting(java.lang.String string)
Parameters:
string -

getFileBaseForSeveralPlotting

public java.lang.String getFileBaseForSeveralPlotting()

setFileBaseForSeveralPlotting

public void setFileBaseForSeveralPlotting(java.lang.String string)

setMaximumTimeSteps

public void setMaximumTimeSteps(int max)

getNbOfRuns

public int getNbOfRuns()
Returns:

setNbOfRuns

public void setNbOfRuns(int i)
Parameters:
i -

getMaxTimeSteps

public int getMaxTimeSteps()
Returns:

setMaxTimeSteps

public void setMaxTimeSteps(int i)
Parameters:
i -