001 /*
002 * SimuCS - Simulator to use with Classifier Systems
003 * MSc project - Oxford University
004 * by Benoit Isaac - Summer 2005
005 */
006
007 package simuLCS;
008
009 import simuLCS.graphics.*;
010
011 /**
012 * Subclass of all the Templatee: a Template defines the meaning of the bits of a classifier.
013 * @author Benoit
014 *
015 */
016 public abstract class Template {
017
018 protected int NB_BITS_CONDITION;
019 protected int NB_BITS_ACTION;
020 protected String name ;
021 protected int nbPartsCondition;
022 protected int nbPartsAction;
023
024 protected ClassifierComponent[] conditions;
025 protected ClassifierComponent[] actions;
026
027 public String getName(){
028 return name;
029 }
030
031 public void setName(String n){
032 name = n;
033 }
034
035 public int getNbPartsCondition(){
036 return nbPartsCondition;
037 }
038
039 public abstract int getNbPossibleActions();
040
041 /**
042 * Specifies the minimal number of actions that must be present in a match set
043 * or else covering will occur.
044 */
045 public abstract int getMinNbActions();
046
047 /**
048 * Return a string of "0","1", or "#" containing the result of the
049 * condition i tested on the entity otherEntity
050 * @param i the number of the condition tested
051 * @param otherEntity the agent we want to test the condition on
052 */
053 public abstract String testCondition(int i, Entity otherEntity);
054
055
056 /**
057 * Return a string of "0","1", or "#" containing the result of <i>all</i>
058 * the conditions tested on the entity otherEntity
059 * @param otherEntity the agent we want to test the condition on
060 */
061 public String testCondition(Entity otherEntity){
062 StringBuffer s = new StringBuffer();
063 for(int i=0;i<getNbPartsCondition();i++)
064 {
065 s.append(testCondition(i,otherEntity));
066 }
067 return s.toString();
068 }
069
070
071 /**
072 * Return the Vector created by the Action part of the classifier
073 * @author Benoit
074 * @param c the Classifier from which the action part will be interpreted
075 * @param me the Entity which has this classifier
076 * @param otherEntity the Entity which generates this vector as a response
077 */
078 public abstract Vector2D getVectorFromAction(Classifier c, Entity me, Entity otherEntity);
079
080
081 /**
082 * Return the Vector created by the actions partS of several classifiers
083 * @author Benoit
084 *
085 */
086 public Vector2D getVectorFromActions(Classifier[] cs, Entity me, Entity otherEntity)
087 {
088 // System.out.println("Me:"+me);
089 Vector2D result = new Vector2D();
090 if(cs.length > 0)
091 {
092 for(int i=0;i<cs.length;i++)
093 {
094 // System.out.println("CS ici :"+cs[i].toString());
095 Vector2D current = getVectorFromAction(cs[i],me,otherEntity);
096 result.add(current);
097 }
098 }
099 return result ;
100 }
101
102
103
104 /**
105 * @return
106 */
107 public abstract G_Panel getPanConditions();
108
109 /**
110 * @return
111 */
112 public abstract G_Panel getPanActions();
113
114 public abstract void updateValuesUI();
115
116 public ClassifierComponent getAction(int i) {
117 if (i < 0 || i > nbPartsAction) {
118 System.out.println("Action out of range.");
119 return null;
120 } else {
121 return actions[i];
122 }
123 }
124
125 public ClassifierComponent[] getConditions() {
126 return conditions;
127 }
128
129 public ClassifierComponent[] getActions() {
130 return actions;
131 }
132
133 public int getNbBitsCondition() {
134 return NB_BITS_CONDITION;
135 }
136
137 public int getNbBitsAction() {
138 return NB_BITS_ACTION;
139 }
140
141 public ClassifierComponent getCondition(int i) {
142 if (i < 0 || i > nbPartsCondition) {
143 System.out.println("Condition out of range.");
144 return null;
145 } else {
146 return conditions[i];
147 }
148 }
149
150
151 }