org.jscience.architecture.traffic.simulation
Class SimModel

java.lang.Object
  extended by java.util.Observable
      extended by org.jscience.architecture.traffic.Model
          extended by org.jscience.architecture.traffic.simulation.SimModel
All Implemented Interfaces:
XMLSerializable

public class SimModel
extends Model
implements XMLSerializable

The heart of the simulation.


Nested Class Summary
 class SimModel.SimModelThread
          The second thread that runs the simulation.
 
Field Summary
protected  SimController controller
          The SimController
static boolean CrossNodes
          Indicates if roadusers cross nodes or jump over them.
protected  int curCycle
          The current cycle we're in
protected  int curSeries
          DOCUMENT ME!
protected static DrivingPolicy dp
          The Driving Policy in this Simulation
protected  java.util.Random generator
          The pseudo-random-number-generator we need in this simulation
protected  boolean hasRun
          A boolean to keep track if this simulation has already run (ivm initialization)
protected static int LOCK_THRESHOLD
          DOCUMENT ME!
protected  boolean locked
          DOCUMENT ME!
protected static int numSeries
          DOCUMENT ME!
protected static int numSeriesSteps
          The number of steps each of the simulations in a series should make
protected  boolean runSeries
          Indicates whether we are running a series of simulations
protected  SignController sgnctrl
          The Thing that makes all Trafficlights shudder
protected  java.lang.String simName
          Name of the simulation
protected  SimModel.SimModelThread thread
          The second thread that runs the actual simulation
protected  TLController tlc
          The TrafficLightControlling Algorithm
 
Fields inherited from class org.jscience.architecture.traffic.Model
infra, parentName, SAVE_STATS
 
Constructor Summary
SimModel()
          Creates second thread
 
Method Summary
protected  PosMov[] calcPosMovs(Node node, Sign sign, Drivelane lane, Roaduser ru, java.util.ListIterator li)
          DOCUMENT ME!
protected  void cityDoStep()
          DOCUMENT ME!
 void doStep()
          Does 1 step in the simulation.
 int getCurCycle()
          Returns the current cycle
 int getCurSeries()
          DOCUMENT ME!
static DrivingPolicy getDrivingPolicy()
          Returns the current Driving Policy
 int getNumSeries()
          DOCUMENT ME!
 java.util.Random getRandom()
          Returns the random number generator
 SpecialNode getRandomDestination(SpecialNode moi)
          Get a completely random destination, don't choose moi
 java.util.Random getRNGen()
          Returns the pseudo-random-number generator of this Model
 java.lang.String getSimName()
          Returns the name of the simulation
 int getSpeed()
          Gets the speed of the simulation
 TLController getTLController()
          Returns the current TLController
 void initialize()
          DOCUMENT ME!
 boolean isRunning()
          DOCUMENT ME!
 boolean isRunSeries()
          DOCUMENT ME!
 void load(XMLElement myElement, XMLLoader loader)
          DOCUMENT ME!
 void lockedSeries()
          DOCUMENT ME!
 void moveAllRoadusers()
          moving all Roadusers to their new places
protected  void moveLane(Drivelane lane)
          moving all roadusers from one lane to their new places
protected  int moveRoaduserOnLane(java.util.ListIterator li, Roaduser ru, int speed_left, Drivelane lane)
           
 void nextCurSeries()
          DOCUMENT ME!
 void nextSeries()
          DOCUMENT ME!
 void pause()
          Pauses the simulation
 void reset()
          Resets data
 void runSeries()
          DOCUMENT ME!
 void saveChilds(XMLSaver saver)
          DOCUMENT ME!
 XMLElement saveSelf()
          DOCUMENT ME!
 void setCurCycle(int c)
          Sets the current cycle
 void setDrivingPolicy(DrivingPolicy _dp)
          Sets the current DrivTLController
 void setInfrastructure(Infrastructure i)
          DOCUMENT ME!
 void setRandom(java.util.Random r)
          Sets the random number generator
 void setSimController(SimController sc)
          DOCUMENT ME!
 void setSimName(java.lang.String s)
          Sets the name of the simulation
 void setSpawnFrequency(EdgeNode en, int rutype, float newspawn)
          Sets spawn frequency for given node and ru type.
 void setSpeed(int s)
          Sets the speed of the simulation
 void setTLController(TLController _tlc)
          Sets the current TLController
 void spawnNewRoadusers()
          New road users are placed on the roads when necessary.
protected  void specialNodesDoStep()
          DOCUMENT ME!
 void stop()
          Stops the simulation.
 void stopSeries()
          DOCUMENT ME!
 void unpause()
          Unpauses the simulation
 
Methods inherited from class org.jscience.architecture.traffic.Model
getInfrastructure, getXMLName, setParentName
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jscience.architecture.traffic.xml.XMLSerializable
getXMLName, setParentName
 

Field Detail

dp

protected static DrivingPolicy dp
The Driving Policy in this Simulation


CrossNodes

public static boolean CrossNodes
Indicates if roadusers cross nodes or jump over them.


numSeriesSteps

protected static int numSeriesSteps
The number of steps each of the simulations in a series should make


LOCK_THRESHOLD

protected static int LOCK_THRESHOLD
DOCUMENT ME!


numSeries

protected static int numSeries
DOCUMENT ME!


generator

protected java.util.Random generator
The pseudo-random-number-generator we need in this simulation


thread

protected SimModel.SimModelThread thread
The second thread that runs the actual simulation


controller

protected SimController controller
The SimController


curCycle

protected int curCycle
The current cycle we're in


tlc

protected TLController tlc
The TrafficLightControlling Algorithm


sgnctrl

protected SignController sgnctrl
The Thing that makes all Trafficlights shudder


simName

protected java.lang.String simName
Name of the simulation


hasRun

protected boolean hasRun
A boolean to keep track if this simulation has already run (ivm initialization)


runSeries

protected boolean runSeries
Indicates whether we are running a series of simulations


locked

protected boolean locked
DOCUMENT ME!


curSeries

protected int curSeries
DOCUMENT ME!

Constructor Detail

SimModel

public SimModel()
Creates second thread

Method Detail

setSimController

public void setSimController(SimController sc)
DOCUMENT ME!

Parameters:
sc - DOCUMENT ME!

setInfrastructure

public void setInfrastructure(Infrastructure i)
DOCUMENT ME!

Overrides:
setInfrastructure in class Model
Parameters:
i - DOCUMENT ME!

getCurCycle

public int getCurCycle()
Returns the current cycle

Returns:
DOCUMENT ME!

setCurCycle

public void setCurCycle(int c)
Sets the current cycle

Parameters:
c - DOCUMENT ME!

getDrivingPolicy

public static DrivingPolicy getDrivingPolicy()
Returns the current Driving Policy

Returns:
DOCUMENT ME!

setDrivingPolicy

public void setDrivingPolicy(DrivingPolicy _dp)
Sets the current DrivTLController

Parameters:
_dp - DOCUMENT ME!

getTLController

public TLController getTLController()
Returns the current TLController

Returns:
DOCUMENT ME!

setTLController

public void setTLController(TLController _tlc)
Sets the current TLController

Parameters:
_tlc - DOCUMENT ME!

getRandom

public java.util.Random getRandom()
Returns the random number generator

Returns:
DOCUMENT ME!

setRandom

public void setRandom(java.util.Random r)
Sets the random number generator

Parameters:
r - DOCUMENT ME!

getSimName

public java.lang.String getSimName()
Returns the name of the simulation

Returns:
DOCUMENT ME!

setSimName

public void setSimName(java.lang.String s)
Sets the name of the simulation

Parameters:
s - DOCUMENT ME!

getRNGen

public java.util.Random getRNGen()
Returns the pseudo-random-number generator of this Model

Returns:
DOCUMENT ME!

setSpawnFrequency

public void setSpawnFrequency(EdgeNode en,
                              int rutype,
                              float newspawn)
Sets spawn frequency for given node and ru type.

Parameters:
en - DOCUMENT ME!
rutype - DOCUMENT ME!
newspawn - DOCUMENT ME!

stop

public void stop()
Stops the simulation. This should only be called when the program exits. To start a new simulation, the simulation should be paused with a call to pause(), then followed by a call to reset(), and finally resumed with unpause().


pause

public void pause()
Pauses the simulation


unpause

public void unpause()
Unpauses the simulation


isRunning

public boolean isRunning()
DOCUMENT ME!

Returns:
DOCUMENT ME!

runSeries

public void runSeries()
DOCUMENT ME!


nextSeries

public void nextSeries()
DOCUMENT ME!


lockedSeries

public void lockedSeries()
DOCUMENT ME!


stopSeries

public void stopSeries()
DOCUMENT ME!


nextCurSeries

public void nextCurSeries()
DOCUMENT ME!


getCurSeries

public int getCurSeries()
DOCUMENT ME!

Returns:
DOCUMENT ME!

isRunSeries

public boolean isRunSeries()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getNumSeries

public int getNumSeries()
DOCUMENT ME!

Returns:
DOCUMENT ME!

reset

public void reset()
           throws SimulationRunningException
Resets data

Throws:
SimulationRunningException - DOCUMENT ME!

doStep

public void doStep()
Does 1 step in the simulation. All cars move, pedestrians get squashed etc...


initialize

public void initialize()
DOCUMENT ME!


getSpeed

public int getSpeed()
Gets the speed of the simulation

Returns:
DOCUMENT ME!

setSpeed

public void setSpeed(int s)
Sets the speed of the simulation

Parameters:
s - DOCUMENT ME!

cityDoStep

protected void cityDoStep()
DOCUMENT ME!


specialNodesDoStep

protected void specialNodesDoStep()
                           throws java.lang.Exception
DOCUMENT ME!

Throws:
java.lang.Exception - DOCUMENT ME!

moveAllRoadusers

public void moveAllRoadusers()
                      throws InfraException
moving all Roadusers to their new places

Throws:
InfraException - DOCUMENT ME!

moveLane

protected void moveLane(Drivelane lane)
                 throws InfraException
moving all roadusers from one lane to their new places

Parameters:
lane - The lane whose roadusers should be moved
Throws:
InfraException - DOCUMENT ME!

moveRoaduserOnLane

protected int moveRoaduserOnLane(java.util.ListIterator li,
                                 Roaduser ru,
                                 int speed_left,
                                 Drivelane lane)

calcPosMovs

protected PosMov[] calcPosMovs(Node node,
                               Sign sign,
                               Drivelane lane,
                               Roaduser ru,
                               java.util.ListIterator li)
DOCUMENT ME!

Parameters:
node - DOCUMENT ME!
sign - DOCUMENT ME!
lane - DOCUMENT ME!
ru - DOCUMENT ME!
li - DOCUMENT ME!
Returns:
DOCUMENT ME!

spawnNewRoadusers

public void spawnNewRoadusers()
                       throws InfraException,
                              java.lang.ClassNotFoundException
New road users are placed on the roads when necessary. When roads are full, new road users are queued.

Throws:
InfraException - DOCUMENT ME!
java.lang.ClassNotFoundException - DOCUMENT ME!

getRandomDestination

public SpecialNode getRandomDestination(SpecialNode moi)
                                 throws InfraException
Get a completely random destination, don't choose moi

Parameters:
moi - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
InfraException - DOCUMENT ME!

load

public void load(XMLElement myElement,
                 XMLLoader loader)
          throws XMLTreeException,
                 java.io.IOException,
                 XMLInvalidInputException
DOCUMENT ME!

Specified by:
load in interface XMLSerializable
Overrides:
load in class Model
Parameters:
myElement - DOCUMENT ME!
loader - DOCUMENT ME!
Throws:
XMLTreeException - DOCUMENT ME!
java.io.IOException - DOCUMENT ME!
XMLInvalidInputException - DOCUMENT ME!

saveSelf

public XMLElement saveSelf()
DOCUMENT ME!

Specified by:
saveSelf in interface XMLSerializable
Overrides:
saveSelf in class Model
Returns:
DOCUMENT ME!

saveChilds

public void saveChilds(XMLSaver saver)
                throws java.io.IOException,
                       XMLTreeException,
                       XMLCannotSaveException
DOCUMENT ME!

Specified by:
saveChilds in interface XMLSerializable
Overrides:
saveChilds in class Model
Parameters:
saver - DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!
XMLTreeException - DOCUMENT ME!
XMLCannotSaveException - DOCUMENT ME!