simuLCS
Class Classifier

java.lang.Object
  extended bysimuLCS.Classifier
Direct Known Subclasses:
ZClassifier

public class Classifier
extends java.lang.Object

A Classifier is a rule: if CONDITION then ACTION.

Author:
Benoit

Field Summary
static int ACT_ALL
           
static int ACT_EXACT
           
protected  java.lang.String action
           
static int COND_ALL
           
static int COND_EXACT
           
static int COND_MATCH
           
protected  java.lang.String condition
           
protected  java.lang.String name
           
static int PART_ACTION
           
static int PART_CONDITION
           
 
Constructor Summary
Classifier()
           
Classifier(java.lang.String c, java.lang.String a)
          Creates a Classifier with the given condition and action.
Classifier(java.lang.String c, java.lang.String a, java.lang.String n)
           
 
Method Summary
static int createSharedClassifier(Classifier c, Agent[] ag)
          Create a unique instance of a classifier shared by several Agents so that the user has to modify only this classifier to affect the behaviour of all the Agents
static Classifier fromString(java.lang.String s, Template t)
          Returns a Classifier object from a string "XXX->YYYY [cccc]" where X,Y = {0,1,#} XXX is the condition part, YYYY is the action part cccc is the name to put between square brackets (optional)
 java.lang.String getAction()
           
 java.lang.String getBits(int position, int length, int whichpart)
          Get the bits from position position to position + length for the either the Condition or the Action, depending on whichpart
static java.lang.String getBits(java.lang.String s)
          If a String contains only 0s and 1s, returns that string.
 java.lang.String getBitsAction(int position, int length)
           
 java.lang.String getBitsCondition(int position, int length)
           
 java.lang.String getCondition()
           
 java.lang.String getName()
           
 double getValue()
          Gives the "value" of this classifier to be plotted.
 boolean match(Classifier c, int CondMatch, int ActMatch)
          Returns true if the classifier satisfies the properties described by CondMatch and ActMatch
 boolean match(java.lang.String state)
          Returns true if the classifier matches in the current situation.
static int removeSharedClassifier(Classifier c, Agent[] ag)
           
 void setAction(java.lang.String string)
           
 void setBits(java.lang.String s, int position, int whichpart)
           
 void setBitsAction(java.lang.String s, int position)
           
 void setBitsCondition(java.lang.String s, int position)
           
 void setCondition(java.lang.String string)
           
 void setName(java.lang.String string)
           
 java.lang.String toString()
          Returns a string representing the classifier (ie.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PART_CONDITION

public static final int PART_CONDITION
See Also:
Constant Field Values

PART_ACTION

public static final int PART_ACTION
See Also:
Constant Field Values

condition

protected java.lang.String condition

action

protected java.lang.String action

name

protected java.lang.String name

COND_ALL

public static final int COND_ALL
See Also:
Constant Field Values

COND_MATCH

public static final int COND_MATCH
See Also:
Constant Field Values

COND_EXACT

public static final int COND_EXACT
See Also:
Constant Field Values

ACT_ALL

public static final int ACT_ALL
See Also:
Constant Field Values

ACT_EXACT

public static final int ACT_EXACT
See Also:
Constant Field Values
Constructor Detail

Classifier

public Classifier()

Classifier

public Classifier(java.lang.String c,
                  java.lang.String a)
Creates a Classifier with the given condition and action.

Parameters:
c -
a -

Classifier

public Classifier(java.lang.String c,
                  java.lang.String a,
                  java.lang.String n)
Method Detail

createSharedClassifier

public static int createSharedClassifier(Classifier c,
                                         Agent[] ag)
Create a unique instance of a classifier shared by several Agents so that the user has to modify only this classifier to affect the behaviour of all the Agents

Parameters:
c -
ag -
Returns:

removeSharedClassifier

public static int removeSharedClassifier(Classifier c,
                                         Agent[] ag)

fromString

public static Classifier fromString(java.lang.String s,
                                    Template t)
Returns a Classifier object from a string "XXX->YYYY [cccc]" where X,Y = {0,1,#} XXX is the condition part, YYYY is the action part cccc is the name to put between square brackets (optional)

Parameters:
s - the String describing the classifier
t - the Template which describes the number of bits for cond/action
Returns:
a Classifier if the String is correct, null otherwise

getBits

public static java.lang.String getBits(java.lang.String s)
If a String contains only 0s and 1s, returns that string. Otherwise return a String indicating an Error

Parameters:
s -
Returns:
See Also:
Config.PROBLEM

getAction

public java.lang.String getAction()

getBitsAction

public java.lang.String getBitsAction(int position,
                                      int length)

getCondition

public java.lang.String getCondition()

getBitsCondition

public java.lang.String getBitsCondition(int position,
                                         int length)

getBits

public java.lang.String getBits(int position,
                                int length,
                                int whichpart)
Get the bits from position position to position + length for the either the Condition or the Action, depending on whichpart

Parameters:
position -
length -
whichpart - @see Classifier#PART_ACTION @see Classifier#PART_CONDITION
Returns:

setAction

public void setAction(java.lang.String string)

setCondition

public void setCondition(java.lang.String string)

setBitsAction

public void setBitsAction(java.lang.String s,
                          int position)

setBitsCondition

public void setBitsCondition(java.lang.String s,
                             int position)

setBits

public void setBits(java.lang.String s,
                    int position,
                    int whichpart)

toString

public java.lang.String toString()
Returns a string representing the classifier (ie. "Condition->Action")


getName

public java.lang.String getName()

setName

public void setName(java.lang.String string)

match

public boolean match(java.lang.String state)
Returns true if the classifier matches in the current situation.

Parameters:
state - The current situation which is the description of an external agent by a bit of strings.

match

public boolean match(Classifier c,
                     int CondMatch,
                     int ActMatch)
Returns true if the classifier satisfies the properties described by CondMatch and ActMatch

Parameters:
c -
CondMatch -
ActMatch -
Returns:

getValue

public double getValue()
Gives the "value" of this classifier to be plotted. Should be overriden by subclasses, depending on their implementation of the Classifiers (it could be strength, accuracy, fitness,...)

Returns:
A value of the Classifier