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

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

public class TC3B1
extends TLController
implements Colearning, InstantiationAssistant

This algorithm works like TC1 with extra functionality. It outcome is adjusted by reinforcement learning. The Q values are created overseeing the whole environment of each traffic light.

See Also:
gld.algo.tlc.TC1TLC

Nested Class Summary
 class TC3B1.CountEntry
           
 class TC3B1.PEntry
          DOCUMENT ME!
 class TC3B1.PKtlEntry
          DOCUMENT ME!
protected  class TC3B1.Target
          DOCUMENT ME!
 
Nested classes/interfaces inherited from class org.jscience.architecture.traffic.algorithms.tlc.TLController
TLController.TLCDialog, TLController.TLCSettings
 
Field Summary
protected  Node[] allnodes
          DOCUMENT ME!
protected static int BUCK
          DOCUMENT ME!
protected  float[][] bucket
          DOCUMENT ME!
protected  java.util.Vector[][][] count
          DOCUMENT ME!
protected  float gamma
          DOCUMENT ME!
protected static boolean green
          DOCUMENT ME!
protected static int green_index
          DOCUMENT ME!
protected  Infrastructure infrastructure
          DOCUMENT ME!
protected  int num_nodes
          DOCUMENT ME!
protected  java.util.Vector[][][] p_table
          DOCUMENT ME!
protected  java.util.Vector[][][] pKtl_table
          DOCUMENT ME!
protected  float[][][][] q_table
          DOCUMENT ME!
protected  float[][][][] qa_table
          DOCUMENT ME!
protected static float random_chance
          DOCUMENT ME!
protected static boolean red
          DOCUMENT ME!
protected static int red_index
          DOCUMENT ME!
static java.lang.String shortXMLName
          DOCUMENT ME!
protected  TrafficLight[][] tls
          DOCUMENT ME!
protected  float[][][] v_table
          DOCUMENT ME!
protected  float[][][] va_table
          DOCUMENT ME!
protected static int WAIT
          DOCUMENT ME!
 
Fields inherited from class org.jscience.architecture.traffic.algorithms.tlc.TLController
infra, num_tls, tld, trackNode
 
Constructor Summary
TC3B1(Infrastructure infra)
          The constructor for TL controllers
 
Method Summary
 boolean canCreateInstance(java.lang.Class request)
          DOCUMENT ME!
protected  int[] count(Sign tl, int pos, Node destination)
           
 java.lang.Object createInstance(java.lang.Class request)
          DOCUMENT ME!
 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 sign_new, Sign sign, Node destination, int pos)
          DOCUMENT ME!
 float getVValue(Sign sign, Node des, int pos)
          DOCUMENT ME!
 java.lang.String getXMLName()
          DOCUMENT ME!
 void load(XMLElement myElement, XMLLoader loader)
          DOCUMENT ME!
 void loadSecondStage(java.util.Dictionary dictionaries)
          DOCUMENT ME!
protected  void recalcP(Sign tl, int pos, Node destination, boolean light, Sign tl_new, int pos_new, int Ktl)
          DOCUMENT ME!
protected  void recalcQ(Sign tl, int pos, Node destination, boolean light, Sign tl_new, int pos_new, PosMov[] posMovs, int Ktl)
          DOCUMENT ME!
protected  void recalcQa(Sign tl, int pos, Node destination, boolean light, Sign tl_new, int pos_new, PosMov[] posMovs)
          DOCUMENT ME!
protected  void recalcV(Sign tl, int pos, Node destination, boolean light, int Ktl)
          DOCUMENT ME!
protected  void recalcVa(Sign tl, int pos, Node destination)
          DOCUMENT ME!
protected  void relaxBucket(Drivelane prevlane, int prevpos)
          Empties the 'gain-value' bucket partly, which is being filled when Roadusers are waiting/voting for their TrafficLight to be set to green.
protected  int rewardFunction(Sign tl_new, int pos_new, PosMov[] posMovs)
          DOCUMENT ME!
 void saveChilds(XMLSaver saver)
          DOCUMENT ME!
 XMLElement saveSelf()
          DOCUMENT ME!
 void setInfrastructure(Infrastructure infra)
          DOCUMENT ME!
 void showSettings(Controller c)
          DOCUMENT ME!
protected  void siphonGainToOtherBucket(Drivelane here, Drivelane there)
          When a Roaduser may drive according to it's Sign, but cant as the desired Drivelane is full, (some/all) of the current gain-bucket of it's current TrafficLight is siphoned over to the desired Drivelane, making it more probable that that lane will move, making it possible for this Drivelane to move.
 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, reset, setParentName, trackNode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUCK

protected static final int BUCK
DOCUMENT ME!

See Also:
Constant Field Values

WAIT

protected static final int WAIT
DOCUMENT ME!

See Also:
Constant Field Values

red

protected static final boolean red
DOCUMENT ME!

See Also:
Constant Field Values

green

protected static final boolean green
DOCUMENT ME!

See Also:
Constant Field Values

green_index

protected static final int green_index
DOCUMENT ME!

See Also:
Constant Field Values

red_index

protected static final int red_index
DOCUMENT ME!

See Also:
Constant Field Values

shortXMLName

public static final java.lang.String shortXMLName
DOCUMENT ME!

See Also:
Constant Field Values

random_chance

protected static float random_chance
DOCUMENT ME!


infrastructure

protected Infrastructure infrastructure
DOCUMENT ME!


tls

protected TrafficLight[][] tls
DOCUMENT ME!


allnodes

protected Node[] allnodes
DOCUMENT ME!


num_nodes

protected int num_nodes
DOCUMENT ME!


bucket

protected float[][] bucket
DOCUMENT ME!


count

protected java.util.Vector[][][] count
DOCUMENT ME!


p_table

protected java.util.Vector[][][] p_table
DOCUMENT ME!


pKtl_table

protected java.util.Vector[][][] pKtl_table
DOCUMENT ME!


q_table

protected float[][][][] q_table
DOCUMENT ME!


qa_table

protected float[][][][] qa_table
DOCUMENT ME!


v_table

protected float[][][] v_table
DOCUMENT ME!


va_table

protected float[][][] va_table
DOCUMENT ME!


gamma

protected float gamma
DOCUMENT ME!

Constructor Detail

TC3B1

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

Parameters:
infra - model being used.
Throws:
InfraException - DOCUMENT ME!
Method Detail

setInfrastructure

public void setInfrastructure(Infrastructure infra)
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
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)
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!

relaxBucket

protected void relaxBucket(Drivelane prevlane,
                           int prevpos)
Empties the 'gain-value' bucket partly, which is being filled when Roadusers are waiting/voting for their TrafficLight to be set to green.

Parameters:
prevlane - The Drivelane the Roaduser was on just before.
prevpos - DOCUMENT ME!

siphonGainToOtherBucket

protected void siphonGainToOtherBucket(Drivelane here,
                                       Drivelane there)
When a Roaduser may drive according to it's Sign, but cant as the desired Drivelane is full, (some/all) of the current gain-bucket of it's current TrafficLight is siphoned over to the desired Drivelane, making it more probable that that lane will move, making it possible for this Drivelane to move.

Parameters:
here - the Id of the drivelane the Roaduser is waiting at
there - the Id of the drivelane where the Roaduser wants to go now

recalcP

protected void recalcP(Sign tl,
                       int pos,
                       Node destination,
                       boolean light,
                       Sign tl_new,
                       int pos_new,
                       int Ktl)
DOCUMENT ME!

Parameters:
tl - DOCUMENT ME!
pos - DOCUMENT ME!
destination - DOCUMENT ME!
light - DOCUMENT ME!
tl_new - DOCUMENT ME!
pos_new - DOCUMENT ME!
Ktl - DOCUMENT ME!

recalcQ

protected void recalcQ(Sign tl,
                       int pos,
                       Node destination,
                       boolean light,
                       Sign tl_new,
                       int pos_new,
                       PosMov[] posMovs,
                       int Ktl)
DOCUMENT ME!

Parameters:
tl - DOCUMENT ME!
pos - DOCUMENT ME!
destination - DOCUMENT ME!
light - DOCUMENT ME!
tl_new - DOCUMENT ME!
pos_new - DOCUMENT ME!
posMovs - DOCUMENT ME!
Ktl - DOCUMENT ME!

recalcV

protected void recalcV(Sign tl,
                       int pos,
                       Node destination,
                       boolean light,
                       int Ktl)
DOCUMENT ME!

Parameters:
tl - DOCUMENT ME!
pos - DOCUMENT ME!
destination - DOCUMENT ME!
light - DOCUMENT ME!
Ktl - DOCUMENT ME!

recalcVa

protected void recalcVa(Sign tl,
                        int pos,
                        Node destination)
DOCUMENT ME!

Parameters:
tl - DOCUMENT ME!
pos - DOCUMENT ME!
destination - DOCUMENT ME!

recalcQa

protected void recalcQa(Sign tl,
                        int pos,
                        Node destination,
                        boolean light,
                        Sign tl_new,
                        int pos_new,
                        PosMov[] posMovs)
DOCUMENT ME!

Parameters:
tl - DOCUMENT ME!
pos - DOCUMENT ME!
destination - DOCUMENT ME!
light - DOCUMENT ME!
tl_new - DOCUMENT ME!
pos_new - DOCUMENT ME!
posMovs - DOCUMENT ME!

count

protected int[] count(Sign tl,
                      int pos,
                      Node destination)

rewardFunction

protected int rewardFunction(Sign tl_new,
                             int pos_new,
                             PosMov[] posMovs)
DOCUMENT ME!

Parameters:
tl_new - DOCUMENT ME!
pos_new - DOCUMENT ME!
posMovs - DOCUMENT ME!
Returns:
DOCUMENT ME!

getVValue

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

Parameters:
sign - DOCUMENT ME!
des - DOCUMENT ME!
pos - DOCUMENT ME!
Returns:
DOCUMENT ME!

getColearnValue

public float getColearnValue(Sign sign_new,
                             Sign sign,
                             Node destination,
                             int pos)
DOCUMENT ME!

Specified by:
getColearnValue in interface Colearning
Parameters:
sign_new - DOCUMENT ME!
sign - DOCUMENT ME!
destination - DOCUMENT ME!
pos - DOCUMENT ME!
Returns:
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 TLController
Parameters:
myElement - DOCUMENT ME!
loader - DOCUMENT ME!
Throws:
XMLTreeException - DOCUMENT ME!
java.io.IOException - DOCUMENT ME!
XMLInvalidInputException - DOCUMENT ME!

saveSelf

public XMLElement saveSelf()
                    throws XMLCannotSaveException
DOCUMENT ME!

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

saveChilds

public void saveChilds(XMLSaver saver)
                throws XMLTreeException,
                       java.io.IOException,
                       XMLCannotSaveException
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!

getXMLName

public java.lang.String getXMLName()
DOCUMENT ME!

Specified by:
getXMLName in interface XMLSerializable
Returns:
DOCUMENT ME!

loadSecondStage

public void loadSecondStage(java.util.Dictionary dictionaries)
                     throws XMLInvalidInputException,
                            XMLTreeException
DOCUMENT ME!

Specified by:
loadSecondStage in interface TwoStageLoader
Overrides:
loadSecondStage in class TLController
Parameters:
dictionaries - DOCUMENT ME!
Throws:
XMLInvalidInputException - DOCUMENT ME!
XMLTreeException - DOCUMENT ME!

canCreateInstance

public boolean canCreateInstance(java.lang.Class request)
DOCUMENT ME!

Specified by:
canCreateInstance in interface InstantiationAssistant
Parameters:
request - DOCUMENT ME!
Returns:
DOCUMENT ME!

createInstance

public java.lang.Object createInstance(java.lang.Class request)
                                throws java.lang.ClassNotFoundException,
                                       java.lang.InstantiationException,
                                       java.lang.IllegalAccessException
DOCUMENT ME!

Specified by:
createInstance in interface InstantiationAssistant
Parameters:
request - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.ClassNotFoundException - DOCUMENT ME!
java.lang.InstantiationException - DOCUMENT ME!
java.lang.IllegalAccessException - DOCUMENT ME!

showSettings

public void showSettings(Controller c)
DOCUMENT ME!

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