org.jscience.architecture.traffic.algorithms.tlc
Class TC1TLCFix

java.lang.Object
  extended by org.jscience.architecture.traffic.algorithms.tlc.TLController
      extended by org.jscience.architecture.traffic.algorithms.tlc.TC1TLCFix
All Implemented Interfaces:
Colearning, InstantiationAssistant, TwoStageLoader, XMLSerializable

public class TC1TLCFix
extends TLController
implements Colearning, InstantiationAssistant

This controller will decide it's Q values for the traffic lights according to the traffic situation on the lane connected to the TrafficLight. It will learn how to alter it's outcome by reinforcement learning. Now being fixed.


Nested Class Summary
 class TC1TLCFix.CountEntry
           
 class TC1TLCFix.PEntry
           
 
Nested classes/interfaces inherited from class org.jscience.architecture.traffic.algorithms.tlc.TLController
TLController.TLCDialog, TLController.TLCSettings
 
Field Summary
protected  Node[] allnodes
           
protected  java.util.Vector[][][] count
           
protected static float gamma
           
protected static boolean green
           
protected static int green_index
           
protected  Infrastructure infrastructure
           
protected  int num_nodes
           
protected  java.util.Vector[][][] pTable
           
protected  float[][][][] qTable
           
protected static float random_chance
           
protected static boolean red
           
protected static int red_index
           
protected static java.lang.String shortXMLName
           
protected  TrafficLight[][] tls
           
protected  float[][][] vTable
           
 
Fields inherited from class org.jscience.architecture.traffic.algorithms.tlc.TLController
infra, num_tls, tld, trackNode
 
Constructor Summary
TC1TLCFix(Infrastructure infra)
          The constructor for TL controllers
 
Method Summary
protected  float[] calcPGR(int tlId, int pos, int desId)
           
protected  float[] calcPGROpt(int tlId, int pos, int desId)
           
 boolean canCreateInstance(java.lang.Class request)
          Tell our parser if we can create an instance of a certain class
 java.lang.Object createInstance(java.lang.Class request)
          Create an instance of a certain class for our parser
 TLDecision[][] decideTLs()
          Calculates how every traffic light should be switched Per node, per sign the waiting roadusers are passed and per each roaduser the gain is calculated.
 float getColearnValue(Sign now, Sign sign, Node des, int pos)
          DOCUMENT ME!
 float getVValue(Sign sign, Node des, int pos)
           
 java.lang.String getXMLName()
          DOCUMENT ME!
 void load(XMLElement myElement, XMLLoader loader)
          DOCUMENT ME!
protected  void recalcP(int tlId, int pos, int desId, boolean light, int tlNewId, int posNew, Roaduser ru, Drivelane dl)
           
protected  void recalcQ(int tlId, int pos, int desId, boolean light, int tlNewId, int posNew, Roaduser ru, Drivelane dl)
           
protected  void recalcQ2(int tlId, int pos, int desId, boolean light, int tlNewId, int posNew, Roaduser ru, Drivelane dl, PosMov[] posMovs)
           
protected  void recalcQOpt(int tlId, int pos, int desId, boolean light, int tlNewId, int posNew, PosMov[] posMovs)
           
protected  void recalcV(int tlId, int pos, int desId)
           
protected  int rewardFunction(int tlId, int pos, int tlNewId, int posNew, int ruSpeed)
           
 void saveChilds(XMLSaver saver)
          DOCUMENT ME!
 XMLElement saveSelf()
          DOCUMENT ME!
 void setInfrastructure(Infrastructure infra)
          DOCUMENT ME!
 void showSettings(Controller c)
          To be overridden by subclasses if TLC settings are to be modified.
 void updateRoaduserMove(Roaduser ru, Drivelane prevlane, Sign prevsign, int prevpos, Drivelane dlanenow, Sign signnow, int posnow, PosMov[] posMovs, Drivelane desired)
          DOCUMENT ME!
 
Methods inherited from class org.jscience.architecture.traffic.algorithms.tlc.TLController
applyGainValues, createDecisionArray, doSettingsDialog, getGainValuesFromDecisionArray, getInfrastructure, getNumTLs, loadSecondStage, reset, setParentName, trackNode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

infrastructure

protected Infrastructure infrastructure

tls

protected TrafficLight[][] tls

allnodes

protected Node[] allnodes

num_nodes

protected int num_nodes

count

protected java.util.Vector[][][] count

pTable

protected java.util.Vector[][][] pTable

qTable

protected float[][][][] qTable

vTable

protected float[][][] vTable

gamma

protected static float gamma

red

protected static final boolean red
See Also:
Constant Field Values

green

protected static final boolean green
See Also:
Constant Field Values

green_index

protected static final int green_index
See Also:
Constant Field Values

red_index

protected static final int red_index
See Also:
Constant Field Values

shortXMLName

protected static final java.lang.String shortXMLName
See Also:
Constant Field Values

random_chance

protected static float random_chance
Constructor Detail

TC1TLCFix

public TC1TLCFix(Infrastructure infra)
          throws InfraException
The constructor for TL controllers

Parameters:
The - model being used.
Throws:
InfraException
Method Detail

setInfrastructure

public void setInfrastructure(Infrastructure infra)
Description copied from class: TLController
DOCUMENT ME!

Overrides:
setInfrastructure in class TLController
Parameters:
infra - DOCUMENT ME!

decideTLs

public TLDecision[][] decideTLs()
Calculates how every traffic light should be switched Per node, per sign the waiting roadusers are passed and per each roaduser the gain is calculated.

Specified by:
decideTLs in class TLController
Parameters:
The - TLDecision is a tuple consisting of a traffic light and a reward (Q) value, for it to be green
Returns:
DOCUMENT ME!
See Also:
gld.algo.tlc.TLDecision

updateRoaduserMove

public void updateRoaduserMove(Roaduser ru,
                               Drivelane prevlane,
                               Sign prevsign,
                               int prevpos,
                               Drivelane dlanenow,
                               Sign signnow,
                               int posnow,
                               PosMov[] posMovs,
                               Drivelane desired)
Description copied from class: TLController
DOCUMENT ME!

Specified by:
updateRoaduserMove in class TLController
Parameters:
ru - DOCUMENT ME!
prevlane - DOCUMENT ME!
prevsign - DOCUMENT ME!
prevpos - DOCUMENT ME!
dlanenow - DOCUMENT ME!
signnow - DOCUMENT ME!
posnow - DOCUMENT ME!
posMovs - DOCUMENT ME!
desired - DOCUMENT ME!

recalcP

protected void recalcP(int tlId,
                       int pos,
                       int desId,
                       boolean light,
                       int tlNewId,
                       int posNew,
                       Roaduser ru,
                       Drivelane dl)

recalcQ

protected void recalcQ(int tlId,
                       int pos,
                       int desId,
                       boolean light,
                       int tlNewId,
                       int posNew,
                       Roaduser ru,
                       Drivelane dl)

recalcQ2

protected void recalcQ2(int tlId,
                        int pos,
                        int desId,
                        boolean light,
                        int tlNewId,
                        int posNew,
                        Roaduser ru,
                        Drivelane dl,
                        PosMov[] posMovs)

recalcQOpt

protected void recalcQOpt(int tlId,
                          int pos,
                          int desId,
                          boolean light,
                          int tlNewId,
                          int posNew,
                          PosMov[] posMovs)

recalcV

protected void recalcV(int tlId,
                       int pos,
                       int desId)

calcPGR

protected float[] calcPGR(int tlId,
                          int pos,
                          int desId)

calcPGROpt

protected float[] calcPGROpt(int tlId,
                             int pos,
                             int desId)

rewardFunction

protected int rewardFunction(int tlId,
                             int pos,
                             int tlNewId,
                             int posNew,
                             int ruSpeed)

getVValue

public float getVValue(Sign sign,
                       Node des,
                       int pos)

getColearnValue

public float getColearnValue(Sign now,
                             Sign sign,
                             Node des,
                             int pos)
Description copied from interface: Colearning
DOCUMENT ME!

Specified by:
getColearnValue in interface Colearning
Parameters:
now - DOCUMENT ME!
sign - DOCUMENT ME!
des - DOCUMENT ME!
pos - DOCUMENT ME!
Returns:
DOCUMENT ME!

showSettings

public void showSettings(Controller c)
Description copied from class: TLController
To be overridden by subclasses if TLC settings are to be modified.

Overrides:
showSettings in class TLController
Parameters:
c - DOCUMENT ME!

load

public void load(XMLElement myElement,
                 XMLLoader loader)
          throws XMLTreeException,
                 java.io.IOException,
                 XMLInvalidInputException
Description copied from class: TLController
DOCUMENT ME!

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

saveChilds

public void saveChilds(XMLSaver saver)
                throws XMLTreeException,
                       java.io.IOException,
                       XMLCannotSaveException
Description copied from class: TLController
DOCUMENT ME!

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

saveSelf

public XMLElement saveSelf()
                    throws XMLCannotSaveException
Description copied from class: TLController
DOCUMENT ME!

Specified by:
saveSelf in interface XMLSerializable
Overrides:
saveSelf in class TLController
Returns:
DOCUMENT ME!
Throws:
XMLCannotSaveException - DOCUMENT ME!

getXMLName

public java.lang.String getXMLName()
Description copied from interface: XMLSerializable
DOCUMENT ME!

Specified by:
getXMLName in interface XMLSerializable
Returns:
The tagname of the XML element in which information about this object is stored prepended by a dot separated list of the tagnames of the parents of this object. (e.g. "model.infrastructure.node")

canCreateInstance

public boolean canCreateInstance(java.lang.Class request)
Description copied from interface: InstantiationAssistant
Tell our parser if we can create an instance of a certain class

Specified by:
canCreateInstance in interface InstantiationAssistant
Parameters:
request - The class of the object that the parser wants
Returns:
Can we create that?

createInstance

public java.lang.Object createInstance(java.lang.Class request)
                                throws java.lang.ClassNotFoundException,
                                       java.lang.InstantiationException,
                                       java.lang.IllegalAccessException
Description copied from interface: InstantiationAssistant
Create an instance of a certain class for our parser

Specified by:
createInstance in interface InstantiationAssistant
Parameters:
request - The class of the object that the parser wants
Returns:
An instance of that object
Throws:
java.lang.ClassNotFoundException - If we don't know that class
java.lang.InstantiationException - In case something goes wrong
java.lang.IllegalAccessException - DOCUMENT ME!