1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package zeus.concepts;
25
26 import java.util.*;
27 import zeus.util.*;
28
29 public class AgentDescription {
30
31 protected String name = SystemProps.getProperty("agent.default.name");
32 protected String xClass = SystemProps.getProperty("agent.default.class");
33 protected int planner_width = SystemProps.getInt("agent.default.planner.processors");
34 protected int planner_length = SystemProps.getInt("agent.default.planner.length");
35 protected int doublebook_fraction = SystemProps.getInt("agent.default.planner.doublebooking");
36 protected Vector tasks = new Vector();
37 protected Vector initialFacts = new Vector();
38 protected Vector protocols = new Vector();
39 protected Vector acquaintances = new Vector();
40 protected List restrictions = new Vector();
41
42 public AgentDescription() {}
43
44 public AgentDescription( AgentDescription agent ) {
45 name = agent.getName();
46 xClass = agent.getAgentClass();
47 planner_width = agent.getPlannerWidth();
48 planner_length = agent.getPlannerLength();
49 doublebook_fraction = agent.getDoublebookFraction();
50
51 setTasks( agent.getTasks() );
52 setInitialFacts( agent.getInitialFacts() );
53 setProtocols( agent.getProtocols() );
54 setAcquaintances( agent.getAcquaintances() );
55 setRestrictions(agent.getRestrictions());
56 }
57
58 public void setName( String s ) {
59 Assert.notNull(s);
60 name = s;
61 }
62
63 public void setAgentClass( String s ) {
64 Assert.notNull(s);
65 xClass = s;
66 }
67
68 public void setPlannerWidth( int t ) {
69 Assert.notFalse( t >= SystemProps.getInt("planner.processors.min") &&
70 t <= SystemProps.getInt("planner.processors.max") );
71 planner_width = t;
72 }
73
74 public void setPlannerLength( int t ) {
75 Assert.notFalse( t >= SystemProps.getInt("planner.length.min") &&
76 t <= SystemProps.getInt("planner.length.max") );
77 planner_length = t;
78 }
79
80 public void setDoublebookFraction( int t ) {
81 Assert.notFalse( t >= SystemProps.getInt("planner.doublebooking.min") &&
82 t <= SystemProps.getInt("planner.doublebooking.max") );
83 doublebook_fraction = t;
84 }
85
86 public void setTasks( Vector v ) {
87 tasks.removeAllElements();
88 if ( v == null ) return;
89 for( int i = 0; i < v.size(); i++ )
90 tasks.addElement(v.elementAt(i));
91 }
92
93 public void setTasks( String[] v ) {
94 tasks.removeAllElements();
95 if ( v == null ) return;
96 for( int i = 0; i < v.length; i++ )
97 tasks.addElement(v[i]);
98 }
99
100 public boolean removeTask(String id) {
101 return tasks.removeElement(id);
102 }
103 public boolean containsTask(String id) {
104 return tasks.contains(id);
105 }
106
107 public void setInitialFacts( Vector v ) {
108 initialFacts.removeAllElements();
109 if ( v == null ) return;
110 for(int i = 0; i < v.size(); i++ )
111 initialFacts.addElement(new Fact((Fact)v.elementAt(i)));
112 }
113
114 public void setInitialFacts( Fact[] v ) {
115 initialFacts.removeAllElements();
116 if ( v == null ) return;
117 for(int i = 0; i < v.length; i++ )
118 initialFacts.addElement(new Fact(v[i]));
119 }
120
121 public void setProtocols( Vector v ) {
122 protocols.removeAllElements();
123 if ( v == null ) return;
124 for(int i = 0; i < v.size(); i++ )
125 protocols.addElement(v.elementAt(i));
126 }
127
128 public void setProtocols( ProtocolInfo[] v ) {
129 protocols.removeAllElements();
130 if ( v == null ) return;
131 for(int i = 0; i < v.length; i++ )
132 protocols.addElement(v[i]);
133 }
134
135 public void setAcquaintances( Vector v ) {
136 acquaintances.removeAllElements();
137 if ( v == null ) return;
138 for(int i = 0; i < v.size(); i++ )
139 acquaintances.addElement(new Acquaintance((Acquaintance)v.elementAt(i)));
140 }
141
142 public void setAcquaintances( Acquaintance[] v ) {
143 acquaintances.removeAllElements();
144 if ( v == null ) return;
145 for( int i = 0; i < v.length; i++ )
146 acquaintances.addElement(new Acquaintance(v[i]));
147 }
148
149 public void setRestrictions(List restrictions) {
150 if(restrictions != null) {
151 this.restrictions = restrictions;
152 }
153 }
154
155 public List getRestrictions() {
156 return restrictions;
157 }
158
159 public String getName() { return name; }
160 public String getAgentClass() { return xClass; }
161 public int getPlannerWidth() { return planner_width; }
162 public int getPlannerLength() { return planner_length; }
163 public int getDoublebookFraction() { return doublebook_fraction; }
164
165 public String[] getTasks() {
166 String[] data = new String[tasks.size()];
167 for( int i = 0; i < tasks.size(); i++ )
168 data[i] = (String)tasks.elementAt(i);
169 return data;
170 }
171
172 public ProtocolInfo[] getProtocols() {
173 ProtocolInfo[] data = new ProtocolInfo[protocols.size()];
174 for( int i = 0; i < protocols.size(); i++ )
175 data[i] = (ProtocolInfo)protocols.elementAt(i);
176 return data;
177 }
178
179 public Fact[] getInitialFacts() {
180 Fact[] data = new Fact[initialFacts.size()];
181 for( int i = 0; i < initialFacts.size(); i++ )
182 data[i] = new Fact( (Fact)initialFacts.elementAt(i) );
183 return data;
184 }
185
186 public Acquaintance[] getAcquaintances() {
187 Acquaintance[] data = new Acquaintance[acquaintances.size()];
188 for( int i = 0; i < acquaintances.size(); i++ )
189 data[i] = new Acquaintance((Acquaintance)acquaintances.elementAt(i) );
190 return data;
191 }
192
193 public String toString() {
194 String s = "(:name " + name + " ";
195 if ( xClass != null && !((xClass.trim()).equals("")) )
196 s += ":class " + xClass + " ";
197 s += ":planner_width " + planner_width + " ";
198 s += ":planner_length " + planner_length + " ";
199 s += ":doublebook_fraction " + doublebook_fraction + " ";
200
201 if ( !tasks.isEmpty() ) {
202 s += ":tasks (";
203 for( int i = 0; i < tasks.size(); i++ )
204 s += (String)tasks.elementAt(i) + " ";
205 s = s.trim() + ") ";
206 }
207 if ( !initialFacts.isEmpty() ) {
208 s += ":initial_facts (";
209 for( int i = 0; i < initialFacts.size(); i++ )
210 s += ((Fact) initialFacts.elementAt(i)).toString();
211 s += ") ";
212 }
213 if ( !protocols.isEmpty() ) {
214 s += ":protocols (";
215 for( int i = 0; i < protocols.size(); i++ )
216 s += protocols.elementAt(i) + " ";
217 s = s.trim() + ") ";
218 }
219 if ( !acquaintances.isEmpty() ) {
220 s += ":acquaintances (";
221 for( int i = 0; i < acquaintances.size(); i++ )
222 s += ((Acquaintance) acquaintances.elementAt(i)).toString();
223 s += ") ";
224 }
225 if( !restrictions.isEmpty() ) {
226 s += ":restrictions (";
227 for( int i = 0 ; i < restrictions.size() ; i++) {
228 s += ((Restriction)restrictions.get(i)).toString();
229 }
230 s += ") ";
231 }
232 return s.trim() + ")";
233 }
234
235 public String pprint() {
236 return pprint(0);
237 }
238
239 public String pprint(int sp) {
240 String suffix, prefix;
241 String tabs = Misc.spaces(sp);
242 String eol = "\n" + tabs + " ";
243
244 String s = "(:name " + name + eol;
245 if ( xClass != null && !((xClass.trim()).equals("")) )
246 s += ":class " + xClass + eol;
247 s += ":planner_width " + planner_width + eol;
248 s += ":planner_length " + planner_length + eol;
249 s += ":doublebook_fraction " + doublebook_fraction + eol;
250
251 if ( !tasks.isEmpty() ) {
252 prefix = ":tasks ";
253 suffix = Misc.spaces(1+ sp + prefix.length());
254 s += prefix + "(";
255 for( int i = 0; i < tasks.size(); i++ )
256 s += ((String)tasks.elementAt(i)) + "\n" + suffix + " ";
257 s = s.trim() + "\n" + suffix + ")" + eol;
258 }
259 if ( !initialFacts.isEmpty() ) {
260 prefix = ":initial_facts ";
261 suffix = Misc.spaces(1+ sp + prefix.length());
262 s += prefix + "(";
263 for( int i = 0; i < initialFacts.size(); i++ )
264 s += ((Fact)initialFacts.elementAt(i)).pprint(1+suffix.length()) +
265 "\n" + suffix + " ";
266 s = s.trim() + "\n" + suffix + ")" + eol;
267 }
268 if ( !protocols.isEmpty() ) {
269 prefix = ":protocols ";
270 suffix = Misc.spaces(1+ sp + prefix.length());
271 s += prefix + "(";
272 for( int i = 0; i < protocols.size(); i++ )
273 s += ((ProtocolInfo)protocols.elementAt(i)).pprint(1+suffix.length()) +
274 "\n" + suffix + " ";
275 s = s.trim() + "\n" + suffix + ")" + eol;
276 }
277 if ( !acquaintances.isEmpty() ) {
278 prefix = ":acquaintances ";
279 suffix = Misc.spaces(1+ sp + prefix.length());
280 s += prefix + "(";
281 for( int i = 0; i < acquaintances.size(); i++ )
282 s += ((Acquaintance)
283 acquaintances.elementAt(i)).pprint(1+suffix.length()) +
284 "\n" + suffix + " ";
285 s = s.trim() + "\n" + suffix + ")" + eol;
286 }
287 if( !restrictions.isEmpty() ) {
288 prefix = ":restrictions ";
289 suffix = Misc.spaces(1+ sp + prefix.length());
290 s += prefix + "(";
291 for( int i = 0 ; i < restrictions.size() ; i++) {
292 s += ((Restriction)restrictions.get(i)).pprint(1 + suffix.length())
293 + "\n" + suffix + " ";
294 }
295 s = s.trim() + "\n" + suffix + ")" + eol;
296 }
297 return tabs + s.trim() + "\n" + tabs + ")";
298 }
299 }