simuLCS
Class ZClassifierSet

java.lang.Object
  extended bysimuLCS.ClassifierSet
      extended bysimuLCS.ZClassifierSet

public class ZClassifierSet
extends ClassifierSet

Implements the main functions of our ZCS. A few lines of code (roulette Wheel, creation of the Match Set using covering) below draw inspiration from the freely available XCSJava by Martin V. Butz

Author:
Benoit, Martin V. Butz

Field Summary
private static int maxPopSize
           
 
Fields inherited from class simuLCS.ClassifierSet
classifiers, isSorted, template
 
Constructor Summary
ZClassifierSet(Template t)
          Creates a new, empty population.
ZClassifierSet(Template t, boolean isSort)
          Creates an empty set that can be ranked if isSort = true
ZClassifierSet(Template t, int initialSize)
          Creates a Set with initialSize random classifiers
ZClassifierSet(Template t, int initialSize, ZClassifier init)
          Creates a ZClassifierSet with initialSize copies of the classifier init.
 
Method Summary
private  void addClassifierMaintainingSize(ZClassifier classifier)
          Adds a classifier to the set.
 ClassifierSet getActionSet()
          By convention, the default Action Set is generated with a Roulette Wheel
private  double getAverageStrength()
           
private  ZClassifier getIdenticalClassifier(ZClassifier newCl)
          Looks for an identical classifier in the population.
 ZClassifierSet getMatchSet(java.lang.String state, ZClassifierSet pop)
          Constructs a match set out of the population.
 ZClassifierSet getRandomActionSet(int nbOfClassifiers)
          Constructs a random action set out of the given match set.
 ZClassifierSet getRWActionSet(int nbOfClassifiers)
          Get an Action Set from the current set, by selecting nbOfClassifiers using the Roulette Wheel
private  double getSumStrength()
           
 ZClassifier[] giveBestClassifiers(int nbFromTop)
          Returns an array with the classifier ranked according to their strength
private  boolean isActionCovered(java.lang.String act)
          Returns true if the specified action is covered in this set.
 void printBestInSet(int i)
          Prints to the console the i best classifiers of the population
private  boolean removeClassifier(ZClassifier classifier)
          Removes the specified classifier from the population.
private  boolean removeClassifierRW()
          Remove a classifier using probability proportional to the inverse of their strengths (inverse Roulette wheel)
 void runGA(int timeSteps, java.lang.String state, ZClassifierSet pop)
          The Genetic Algorithm for the ZCS.
private  ZClassifier selectClassifierRW()
          Selects one classifier using roulette wheel selection according to the fitnesses of the classifiers.
 void updateSet(double reward, double maxReward)
          Updates the Set, with the technique we designed
 
Methods inherited from class simuLCS.ClassifierSet
addClassifier, addClassifierSet, contains, getClassifiers, getIterator, getMatchSet, getSize, getTemplate, removeClassifier, setTemplate, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

maxPopSize

private static final int maxPopSize
See Also:
Constant Field Values
Constructor Detail

ZClassifierSet

public ZClassifierSet(Template t)
Creates a new, empty population. (With an empty Set)

See Also:
ClassifierSet

ZClassifierSet

public ZClassifierSet(Template t,
                      boolean isSort)
Creates an empty set that can be ranked if isSort = true

Parameters:
t -
isSort -

ZClassifierSet

public ZClassifierSet(Template t,
                      int initialSize)
Creates a Set with initialSize random classifiers

Parameters:
t -
initialSize -

ZClassifierSet

public ZClassifierSet(Template t,
                      int initialSize,
                      ZClassifier init)
Creates a ZClassifierSet with initialSize copies of the classifier init.

Method Detail

getMatchSet

public ZClassifierSet getMatchSet(java.lang.String state,
                                  ZClassifierSet pop)
Constructs a match set out of the population. After the creation, it is checked if the match set covers all possible actions in the environment. If one or more actions are not present, covering occurs, generating the missing action(s). If maximal population size is reached when covering, deletion occurs. Modified to be used with a Set implementation.

Parameters:
state - the situation that shoud satisfy the conditions of the classifiers
pop - the Population in which the new classifiers should be inserted

getRandomActionSet

public ZClassifierSet getRandomActionSet(int nbOfClassifiers)
Constructs a random action set out of the given match set.

Parameters:
nbOfClassifiers - the number of classifiers to select

getActionSet

public ClassifierSet getActionSet()
By convention, the default Action Set is generated with a Roulette Wheel

Overrides:
getActionSet in class ClassifierSet
See Also:
ClassifierSet.getActionSet()

getRWActionSet

public ZClassifierSet getRWActionSet(int nbOfClassifiers)
Get an Action Set from the current set, by selecting nbOfClassifiers using the Roulette Wheel

Parameters:
nbOfClassifiers -
Returns:

updateSet

public void updateSet(double reward,
                      double maxReward)
Updates the Set, with the technique we designed

Parameters:
reward -
maxReward -

getAverageStrength

private double getAverageStrength()
Returns:

getSumStrength

private double getSumStrength()

isActionCovered

private boolean isActionCovered(java.lang.String act)
Returns true if the specified action is covered in this set.


runGA

public void runGA(int timeSteps,
                  java.lang.String state,
                  ZClassifierSet pop)
The Genetic Algorithm for the ZCS.


selectClassifierRW

private ZClassifier selectClassifierRW()
Selects one classifier using roulette wheel selection according to the fitnesses of the classifiers.


getIdenticalClassifier

private ZClassifier getIdenticalClassifier(ZClassifier newCl)
Looks for an identical classifier in the population.

Parameters:
newCl - The new classifier.
Returns:
Returns the identical classifier if found, null otherwise.

addClassifierMaintainingSize

private void addClassifierMaintainingSize(ZClassifier classifier)
Adds a classifier to the set. If the mamximum Population Size has been reached, a Classifier is deleted before adding this new one (using an inverse Roulette Wheel).


removeClassifierRW

private boolean removeClassifierRW()
Remove a classifier using probability proportional to the inverse of their strengths (inverse Roulette wheel)


removeClassifier

private boolean removeClassifier(ZClassifier classifier)
Removes the specified classifier from the population.

Returns:
true if the given classifier was found and removed; false if it was not found

giveBestClassifiers

public ZClassifier[] giveBestClassifiers(int nbFromTop)
Returns an array with the classifier ranked according to their strength

Parameters:
nbFromTop -
Returns:

printBestInSet

public void printBestInSet(int i)
Prints to the console the i best classifiers of the population

Parameters:
i -