simuLCS
Class AgentClassifierLearning

java.lang.Object
  extended bysimuLCS.Entity
      extended bysimuLCS.Agent
          extended bysimuLCS.AgentClassifier
              extended bysimuLCS.AgentClassifierLearning

public class AgentClassifierLearning
extends AgentClassifier

Agent with a Behaviour and a Learning Classifier System plugged in.

Author:
Benoit

Field Summary
protected  ClassifierSet behaviourLearning
           
protected  ClassifierSet behaviourTemp
           
protected  ClassifierSet behaviourToShow
          This behaviour is just a copy of behaviourLearning, with the classifiers ordered to present them to the user.
protected  javax.swing.JButton buttonUpdate
           
protected  java.awt.geom.Point2D coordGhost
           
static int EXPECTED_BEHAVIOUR
           
static int EXPECTED_BEHAVIOUR_TO_SHOW
           
protected  boolean isGhostPainted
           
protected  boolean isLearning
           
private static double MAX_ERROR
           
protected  int nbOfStepsLearning
           
protected  int nbOfStepsLearningFromLastPlot
           
protected  java.awt.geom.Point2D oldcoordGhost
           
static int REAL_BEHAVIOUR
           
protected  double totalRewardFromLastPlot
           
protected  double totalRewardUntilNow
           
private static int UPDATE_BEHAVIOUR_TO_SHOW
           
protected  boolean updateBehaviourTemp
           
protected  boolean updateBehaviourToShow
           
 
Fields inherited from class simuLCS.AgentClassifier
behaviour, DETECTION_DISTANCE, isDetectionLimited, lastMovVector, template
 
Fields inherited from class simuLCS.Agent
arena, heading, oldcoord
 
Fields inherited from class simuLCS.Entity
color_ext, color_int, coord, generator, name, paintName, size
 
Constructor Summary
  AgentClassifierLearning(java.util.Random gen, Arena a, java.lang.String name)
          Creates an ACL with a default behaviour "Avoid danger".
protected AgentClassifierLearning(java.util.Random gen, Arena a, java.lang.String name, Template t, ClassifierSet b)
          Creates an ACL with a given Template and a given Behaviour
 
Method Summary
protected  void clearGhost(java.awt.Graphics2D g, java.awt.geom.Point2D c)
          Clear the drawing of the ghost
 double getAverageRewardFromLastPlot()
          Get the average reward from the last plot, and reset the counters to start again to record
 double getAverageRewardUntilNow()
           
 ClassifierSet getBehaviour(int whichOne)
          Returns the given behaviour (real one, expected one, or expected one ordered)
 java.awt.geom.Point2D getCoordGhost()
           
 int getNbOfStepsLearning()
           
 java.awt.geom.Point2D getOldcoordGhost()
           
protected  double getReward(java.awt.geom.Point2D real, java.awt.geom.Point2D expected)
          Get the reward from the environnement.
 double getTotalRewardUntilNow()
           
 boolean isGhostPainted()
           
 boolean isLearning()
           
private  boolean isUpdateBehaviourTemp()
           
 void move(Arena arena, Entity[] others, int nbEntities, java.awt.Graphics2D g)
          Moves the agent.
protected  void moveAndLearn(java.awt.geom.Point2D nextCoord, Vector2D nextMovVector, Arena arena, Entity[] others, int nbEntities, java.awt.Graphics2D g)
          Moves the Ghost and updates the rules with the reward
protected  ZClassifierSet moveLearner(Arena arena, Entity[] others, int nbEntities, java.awt.Graphics2D g)
          From the actual position of the agent, the system will try to guess where it is going to be at the next time step, by calculating its response according to its expected behaviour (ie the current behaviour provided by the Learning System).
 void paint(java.awt.Graphics2D g)
          Removes the drawing of the agent for the old coordinates and repaint the agent at its new coordinates.
protected  void paintGhost(java.awt.Graphics2D g)
          Paint the ghost (ie the Agent at the expected position)
 void requestUpdateBehaviourToShow(boolean simuIsRunning, javax.swing.JButton b)
          Asks for the behaviour to be updated.
 void setGhostPainted(boolean b)
           
 void setLearning(boolean b)
           
 void setTotalRewardUntilNow(double d)
           
private  void setUpdateBehaviourTemp(boolean b)
           
protected  void updateBehaviourToShow()
          Create a copy of the current population and order the classifiers so that they can be shown ranked.
 
Methods inherited from class simuLCS.AgentClassifier
canDetect, drawVisibilityCircle, getBehaviour, getLastMovVector, getNewMovVectorAccordingTo, getTemplate, isDetectionLimited, setBehaviour, setDetectionLimited, setLastMovVector, setTemplate
 
Methods inherited from class simuLCS.Agent
clear, clear, getArena, getCoordNearTo, getRadius, isDangerous, isMoving, move, toString
 
Methods inherited from class simuLCS.Entity
collideWithMe, distanceTo, getColor_ext, getColor_int, getCoord, getId, getName, getRadiusBody, getSize, isPaintName, setColor_ext, setColor_int, setName, setPaintName, setSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REAL_BEHAVIOUR

public static final int REAL_BEHAVIOUR
See Also:
Constant Field Values

EXPECTED_BEHAVIOUR

public static final int EXPECTED_BEHAVIOUR
See Also:
Constant Field Values

EXPECTED_BEHAVIOUR_TO_SHOW

public static final int EXPECTED_BEHAVIOUR_TO_SHOW
See Also:
Constant Field Values

behaviourToShow

protected ClassifierSet behaviourToShow
This behaviour is just a copy of behaviourLearning, with the classifiers ordered to present them to the user.


behaviourTemp

protected ClassifierSet behaviourTemp

updateBehaviourTemp

protected boolean updateBehaviourTemp

updateBehaviourToShow

protected boolean updateBehaviourToShow

buttonUpdate

protected javax.swing.JButton buttonUpdate

coordGhost

protected java.awt.geom.Point2D coordGhost

oldcoordGhost

protected java.awt.geom.Point2D oldcoordGhost

isLearning

protected boolean isLearning

isGhostPainted

protected boolean isGhostPainted

MAX_ERROR

private static final double MAX_ERROR
See Also:
Constant Field Values

UPDATE_BEHAVIOUR_TO_SHOW

private static final int UPDATE_BEHAVIOUR_TO_SHOW
See Also:
Constant Field Values

nbOfStepsLearning

protected int nbOfStepsLearning

totalRewardUntilNow

protected double totalRewardUntilNow

totalRewardFromLastPlot

protected double totalRewardFromLastPlot

nbOfStepsLearningFromLastPlot

protected int nbOfStepsLearningFromLastPlot

behaviourLearning

protected ClassifierSet behaviourLearning
Constructor Detail

AgentClassifierLearning

protected AgentClassifierLearning(java.util.Random gen,
                                  Arena a,
                                  java.lang.String name,
                                  Template t,
                                  ClassifierSet b)
Creates an ACL with a given Template and a given Behaviour

Parameters:
gen -
a -
name -
t -
b -

AgentClassifierLearning

public AgentClassifierLearning(java.util.Random gen,
                               Arena a,
                               java.lang.String name)
Creates an ACL with a default behaviour "Avoid danger".

Parameters:
gen -
a -
name -
Method Detail

moveLearner

protected ZClassifierSet moveLearner(Arena arena,
                                     Entity[] others,
                                     int nbEntities,
                                     java.awt.Graphics2D g)
From the actual position of the agent, the system will try to guess where it is going to be at the next time step, by calculating its response according to its expected behaviour (ie the current behaviour provided by the Learning System).

Parameters:
arena -
g -
Returns:
the total set of Classifiers that lead this response (Set of all the ActionSets involved in the process)
See Also:
behaviourLearning

moveAndLearn

protected void moveAndLearn(java.awt.geom.Point2D nextCoord,
                            Vector2D nextMovVector,
                            Arena arena,
                            Entity[] others,
                            int nbEntities,
                            java.awt.Graphics2D g)
Moves the Ghost and updates the rules with the reward

Parameters:
nextCoord - the REAL next position (to compare with the expected one)
nextMovVector - the REAL next Movement Vector
arena -
others -
nbEntities -
g -

getReward

protected double getReward(java.awt.geom.Point2D real,
                           java.awt.geom.Point2D expected)
Get the reward from the environnement.

Parameters:
expected -
Returns:

move

public void move(Arena arena,
                 Entity[] others,
                 int nbEntities,
                 java.awt.Graphics2D g)
Moves the agent. Moves the ghost and applies the learning system if isLearning == true.

Overrides:
move in class AgentClassifier
See Also:
isLearning

clearGhost

protected void clearGhost(java.awt.Graphics2D g,
                          java.awt.geom.Point2D c)
Clear the drawing of the ghost

Parameters:
g -
c -

paintGhost

protected void paintGhost(java.awt.Graphics2D g)
Paint the ghost (ie the Agent at the expected position)

Parameters:
g -

updateBehaviourToShow

protected void updateBehaviourToShow()
Create a copy of the current population and order the classifiers so that they can be shown ranked.


requestUpdateBehaviourToShow

public void requestUpdateBehaviourToShow(boolean simuIsRunning,
                                         javax.swing.JButton b)
Asks for the behaviour to be updated. In order to avoid Concurrency problems, the update will be done at a thread-safe stage.

Parameters:
simuIsRunning -
b -

paint

public void paint(java.awt.Graphics2D g)
Removes the drawing of the agent for the old coordinates and repaint the agent at its new coordinates. Paints the ghost as well if isGhostPainted==true. (This avoids a blinking effect)

Overrides:
paint in class AgentClassifier
See Also:
Agent#paint(), isGhostPainted

getCoordGhost

public java.awt.geom.Point2D getCoordGhost()

isGhostPainted

public boolean isGhostPainted()

isLearning

public boolean isLearning()

getNbOfStepsLearning

public int getNbOfStepsLearning()

getOldcoordGhost

public java.awt.geom.Point2D getOldcoordGhost()

setGhostPainted

public void setGhostPainted(boolean b)
Parameters:
b -

setLearning

public void setLearning(boolean b)

getBehaviour

public ClassifierSet getBehaviour(int whichOne)
Returns the given behaviour (real one, expected one, or expected one ordered)

Overrides:
getBehaviour in class Agent
Parameters:
whichOne -
Returns:

isUpdateBehaviourTemp

private boolean isUpdateBehaviourTemp()

setUpdateBehaviourTemp

private void setUpdateBehaviourTemp(boolean b)

getTotalRewardUntilNow

public double getTotalRewardUntilNow()

getAverageRewardUntilNow

public double getAverageRewardUntilNow()

setTotalRewardUntilNow

public void setTotalRewardUntilNow(double d)

getAverageRewardFromLastPlot

public double getAverageRewardFromLastPlot()
Get the average reward from the last plot, and reset the counters to start again to record

Returns: