Class Agent

java.lang.Object
  |
  +--Agent
All Implemented Interfaces:
java.io.Serializable

public class Agent
extends java.lang.Object
implements java.io.Serializable

This class is an agent, containing the main loop of the XCS and handling communications. It stores the population and the posed problem. The XCS is implemented following Martin V. Butz and Steward Wilson (2001) "An algorithmic description of XCS". Moreover, it handles the performance evaluation.

Since:
JDK 1.3
See Also:
Serialized Form

Field Summary
private  Book addressBook
          The address book of the agent
private  double averErr
          initialization of the average performance fitness and prediction error of the agent's population of classifiers
private  double averExp
          initialization of the average performance fitness and prediction error of the agent's population of classifiers
private  double averFit
          initialization of the average performance fitness and prediction error of the agent's population of classifiers
private  double averPerf
          initialization of the average performance fitness and prediction error of the agent's population of classifiers
private  XClassifier bestClassifier
          The classifier selected for communication
private static XCSConstants cons
          Stores the relevant constants for XCS.
private  double distLevelOne
          threshold distance from the central competence of agents for signals and GA
private  double distLevelTwo
          threshold distance from the core competence to accept communication
private  XClassifierSet gpop
          Stores the current population of XCS.
private  int name
          The name of the agent
private  double perC
          The percentage of agents asked at random in the whole population of agents
private  java.util.Vector randomArray
          A vector used to store agents picked up at random from the total population of agents
private  double reward
          The reward the agent receives from the environment for a given answer
private static int totalNumberOfAgents
          The total number of agents involved in the experiment
 
Constructor Summary
Agent()
          Constructs the XCS system of the agent.
 
Method Summary
private  XClassifierSet answer(java.lang.String state, XClassifierSet collectedAnswersArray, int time)
          The method used by agents to answer the question.
private  XClassifierSet askAgentsAtRandom(AgentsPopulations population, java.lang.String state, Environment env, XClassifierSet collectedAnswersArray, int time)
          This method asks agents randomly chosen in the population to answer the question. 10% of the whole population is selected.
private  XClassifierSet askAgentsInAddressBook(AgentsPopulations population, Environment env, java.lang.String state, XClassifierSet collectedAnswersArray, int time)
          This method asks to each agent in the address book to try to answer the question.
private  boolean checkAgent(int ran)
          Checks that 1) the agent does not choose itself 2) the agents does not choose an agent already in its address book
private  boolean checkRand(int[] t, int i)
          Checks that a random number is not drawn twice in one single process
private  java.util.Vector chooseAgents(int size, AgentsPopulations population)
          Build an array of randomly chosen agents.
 boolean doOneSingleStepProblemExplore(java.lang.String state, int counter, AgentsPopulations wholePopulation)
          Executes one main learning loop for a single step problem.
 Book getAddressBook()
          return the address book of the agent
 int getName()
          Return the name of the agent
 double getPerformance()
          return the reward received by the agent
 XClassifierSet getPopulation()
          Return the population of rules of an agent
private  java.util.Vector randomPopulation(AgentsPopulations population)
          Construct a random population of agents picked up from the global population.
private  XClassifier selectBestAnswer(XClassifierSet collectedAnswersArray, int time)
          THis method is used by the agent who asks a question to select the best answer from the ones it recieved
 void setAddressBook(Book addBook)
          Set an address book for the agent
 void setName(int i)
          Set the name of the agent
 void setXClassifierSet(XClassifierSet aXClassifierSet)
          Set the initial population of classifiers within an agent
private  void startCommunication(java.lang.String state, Environment env, XClassifierSet matchSet, AgentsPopulations wholePopulation, int time)
          This method is the communication itself.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

totalNumberOfAgents

private static int totalNumberOfAgents
The total number of agents involved in the experiment


gpop

private XClassifierSet gpop
Stores the current population of XCS.


bestClassifier

private XClassifier bestClassifier
The classifier selected for communication


name

private int name
The name of the agent


distLevelOne

private double distLevelOne
threshold distance from the central competence of agents for signals and GA


distLevelTwo

private double distLevelTwo
threshold distance from the core competence to accept communication


addressBook

private Book addressBook
The address book of the agent


randomArray

private java.util.Vector randomArray
A vector used to store agents picked up at random from the total population of agents


cons

private static XCSConstants cons
Stores the relevant constants for XCS.

See Also:
XCSConstants

perC

private double perC
The percentage of agents asked at random in the whole population of agents


averPerf

private double averPerf
initialization of the average performance fitness and prediction error of the agent's population of classifiers


averFit

private double averFit
initialization of the average performance fitness and prediction error of the agent's population of classifiers


averExp

private double averExp
initialization of the average performance fitness and prediction error of the agent's population of classifiers


averErr

private double averErr
initialization of the average performance fitness and prediction error of the agent's population of classifiers


reward

private double reward
The reward the agent receives from the environment for a given answer

Constructor Detail

Agent

public Agent()
Constructs the XCS system of the agent.

See Also:
XCSConstants.XCSConstants()
Method Detail

setXClassifierSet

public void setXClassifierSet(XClassifierSet aXClassifierSet)
Set the initial population of classifiers within an agent

Parameters:
aXClassifierSet - An object of the class XClassifierSet attached to each agent

setName

public void setName(int i)
Set the name of the agent

Parameters:
i - The agent's name

setAddressBook

public void setAddressBook(Book addBook)
Set an address book for the agent

Parameters:
addBook - Address book of the agent

getAddressBook

public Book getAddressBook()
return the address book of the agent


getPerformance

public double getPerformance()
return the reward received by the agent


getPopulation

public XClassifierSet getPopulation()
Return the population of rules of an agent


getName

public int getName()
Return the name of the agent


doOneSingleStepProblemExplore

public boolean doOneSingleStepProblemExplore(java.lang.String state,
                                             int counter,
                                             AgentsPopulations wholePopulation)
Executes one main learning loop for a single step problem. In addition, it checks whether a communication loop should be started and, if yes, it starts the communication process. if the agent has no answer, or a "bad" answer in terms of prediction or fitness to the signal from the environment, or if the signal is remote from its core competencies, then it asks for help. If despite the communication process, the agent has still no answer, then he passes the question through to the next agent in the list. Else, it answers with the rule it has, doing some exploration.

Parameters:
state - The actual problem instance.
counter - The number of problems observed so far in exploration.
wholePopulation - The whole set of agents in the population
See Also:
XClassifierSet.XClassifierSet(String,XClassifierSet,int,int), PredictionArray.PredictionArray(XClassifierSet, int), PredictionArray.bestActionWinner(), XClassifierSet.XClassifierSet(XClassifierSet,int), Environment.executeAction(int), XClassifierSet.updateSet(double, double), XClassifierSet.runGA(int, Environment, java.lang.String, int, double, double), XClassifierSet.testPerformance(double), XClassifierSet.testFitness(double), XClassifierSet.computeMinDistance(Environment, java.lang.String, double), startCommunication(java.lang.String, Environment, XClassifierSet, AgentsPopulations, int)

startCommunication

private void startCommunication(java.lang.String state,
                                Environment env,
                                XClassifierSet matchSet,
                                AgentsPopulations wholePopulation,
                                int time)
This method is the communication itself. First, the agent ask agents present in its address book. Second, it asks agents taken at random in the whole population. Third, it chooses the best answer among the ones collected and insert it in its own population and in its matchSet.

Parameters:
state - the current problem submitted by the environment
env - the environment or problem space
matchSet - the set of classifiers with conditions matchning the problem
wholePopulation - the population of agents in the experiment
time - the time counter of the experiment
See Also:
XClassifierSet.XClassifierSet(int), askAgentsInAddressBook(AgentsPopulations, Environment, java.lang.String, XClassifierSet, int), askAgentsAtRandom(AgentsPopulations, java.lang.String, Environment, XClassifierSet, int), selectBestAnswer(XClassifierSet, int), XClassifierSet.addBestAnswerToPopulation(XClassifier, XClassifierSet)

askAgentsInAddressBook

private XClassifierSet askAgentsInAddressBook(AgentsPopulations population,
                                              Environment env,
                                              java.lang.String state,
                                              XClassifierSet collectedAnswersArray,
                                              int time)
This method asks to each agent in the address book to try to answer the question. The answers are collected in an array collectedAnswersArray. Moreover, the status of agents in the address book are actualized.

Parameters:
population - the population of agents
env - the problem space
state - the signal from the environment
collectedAnswersArray - The array storing the answers received by the asking agent
time - The time counter of the experiment
See Also:
Slot.actualizeTime(), Slot.actualizeCounter(), answer(java.lang.String, XClassifierSet, int), Slot.trackExchange(XClassifier), Book.deleteAddress(Slot), Book.ordering(), Book.transferAddressBook(Agent)

askAgentsAtRandom

private XClassifierSet askAgentsAtRandom(AgentsPopulations population,
                                         java.lang.String state,
                                         Environment env,
                                         XClassifierSet collectedAnswersArray,
                                         int time)
This method asks agents randomly chosen in the population to answer the question. 10% of the whole population is selected. First, an array of randomly chosen agents is built. Second each of these agents are asked to answer and they are added to the address book if they do so. Answers are added to the collectedAnswersArray.

Parameters:
population - the population of agents
state - the signal from the environment
env - the problem space
collectedAnswersArray - The array storing the answers received by the asking agent
time - The time counter of the experiment
See Also:
randomPopulation(AgentsPopulations), XClassifierSet.computeMinDistance(Environment, java.lang.String, double), answer(java.lang.String, XClassifierSet, int), Book.addToAddressBook(Agent)

answer

private XClassifierSet answer(java.lang.String state,
                              XClassifierSet collectedAnswersArray,
                              int time)
The method used by agents to answer the question. First, the asked agent compares the question and the rules it has in its population of classifiers. If some of these rules match, it stores them in an array. Next, if it has some potential answers to the question, it picks up the best one. Then the best answer is transmitted to the questioning agent by being put in the array collecting the answers from all the asked agents.

Parameters:
state - Signal from the environment
time - The time counter of the experiment
See Also:
XClassifier.test(java.lang.String)

selectBestAnswer

private XClassifier selectBestAnswer(XClassifierSet collectedAnswersArray,
                                     int time)
THis method is used by the agent who asks a question to select the best answer from the ones it recieved

Parameters:
collectedAnswersArray - Array Where answers are stored
time - The time counter of the experiment

randomPopulation

private java.util.Vector randomPopulation(AgentsPopulations population)
Construct a random population of agents picked up from the global population. We must consider the case of an address book of size < (total number of agents in population - number of agents asked at random)and address book of size >= (total number of agents in population - number of agents asked at random).

Parameters:
population - The population of agents in the experiment
See Also:
chooseAgents(int, AgentsPopulations)

chooseAgents

private java.util.Vector chooseAgents(int size,
                                      AgentsPopulations population)
Build an array of randomly chosen agents. However, agents must not already be in the address book, must not be itself and an agent can not be drawn twice.

Parameters:
size - The number of agents to be picked up
population - The whole population from which agents will be drawn
See Also:
checkAgent(int), checkRand(int[], int)

checkRand

private boolean checkRand(int[] t,
                          int i)
Checks that a random number is not drawn twice in one single process

Parameters:
t - The list of agents randomly drawn
i - the latest drawn agent. the method checks that i is not already in the list.

checkAgent

private boolean checkAgent(int ran)
Checks that 1) the agent does not choose itself 2) the agents does not choose an agent already in its address book

Parameters:
ran - The random number drawn