-
Notifications
You must be signed in to change notification settings - Fork 2
/
Agent.java
326 lines (207 loc) · 5.97 KB
/
Agent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/**
* --Copyright notice--
*
* Copyright (c) School of Geography, University of Leeds.
* http://www.geog.leeds.ac.uk/
* This software is licensed under 'The Artistic License' which can be found at
* the Open Source Initiative website at...
* http://www.opensource.org/licenses/artistic-license.php
*
* The Standard Version source code, and associated documentation can be found at...
* [online] https://github.com/AJEvans/SmallWorldCore/
*
*
* --End of Copyright notice--
*
*/
import java.util.*;
/**
* A geographical agent class with network connection.
* Agents can have an x/y/z coordinate, a double value and
* a String name, as well as a series of networked neighbours.
* The update method alters the Agent's properties.
* Subclasses should override this method. They can use the protected neighbours
* variable and others if they are needed. Default test behaviour for this
* super class's update method is to set the value variable to
* the number of neighbours. Properties can be set
* using the protected properties hashtable variable.<P>
* @author <A href="http://www.geog.leeds.ac.uk/people/a.evans/">Andy Evans</A>
* @version 0.13
*/
public class Agent {
// All variables can be accessed by subclasses.
protected Vector neighbours = null; // Network neighbours.
protected int x = -1; // Geographical x.
protected int y = -1; // Geographical y.
protected int z = -1; // Geographical z.
protected String name = null; // What it is. Easy to get string property or name.
protected double value = 0; // What its value is. Easy to get double property.
protected Hashtable attributes = null; // Holds more complex Agent attributes.
protected int graphX = -1; // Display X position for graph space.
protected int graphY = -1; // Display y position for graph space.
protected int graphZ = -1; // Display z position for graph space.
/**
* Creates a new instance of Agent.
**/
public Agent() {
neighbours = new Vector();
}
/**
* Adds a network neighbour.
* Note that these don't have to be geographical links.
**/
public void addNeighbour(Agent a) {
neighbours.add(a);
}
/**
* Removes a network neighbour.
* Up to developers to ask for neigbours that exist.
**/
public void removeNeighbour(Agent a) {
neighbours.remove(a);
}
/**
* Gets all the network neighbour.
* Returns null is there are none.
**/
public Vector getNeighbours() {
return neighbours;
}
/**
* Runs one iteration of the Agent.
* Alters the Agent's attributes.
* Subclasses should override this method using getNeighbours
* if they are needed. Default test behaviour is to set the
* the value variable to the number of neighbours.
**/
public void update() {
value = neighbours.size();
}
/**
* Sets geographical x.
* The default value is -1.
**/
public void setX(int x) {
this.x = x;
}
/**
* Gets geographical x.
* Returns -1 if not set.
**/
public int getX() {
return x;
}
/**
* Sets geographical y.
* The default value is -1.
**/
public void setY(int y) {
this.y = y;
}
/**
* Gets geographical y.
* Returns -1 if not set.
**/
public int getY() {
return y;
}
/**
* Sets geographical z.
* The default value is -1.
**/
public void setZ(int z) {
this.z = z;
}
/**
* Gets geographical z.
* Returns -1 if not set.
**/
public int getZ() {
return z;
}
/**
* Sets X position in graph display space.
* The default value is -1.
**/
public void setGraphX(int x) {
this.graphX = x;
}
/**
* Gets X position in graph display space.
* The default value is -1.
**/
public int getGraphX() {
return graphX;
}
/**
* Sets Y position in graph display space.
* The default value is -1.
**/
public void setGraphY(int y) {
this.graphY = y;
}
/**
* Gets Y position in graph display space.
* The default value is -1.
**/
public int getGraphY() {
return graphY;
}
/**
* Sets Z position in graph display space.
* The default value is -1.
**/
public void setGraphZ(int z) {
this.graphZ = z;
}
/**
* Gets Z position in graph display space.
* The default value is -1.
**/
public int getGraphZ() {
return graphZ;
}
/**
* Sets the value.
* The default value is 0.
**/
public void setValue(double x) {
value = x;
}
/**
* Gets the value.
* Returns 0 if not set.
**/
public double getValue() {
return value;
}
/**
* Sets the name.
* The default value is null.
**/
public void setName(String a) {
this.name = a;
}
/**
* Gets the name.
* Returns null if not set.
**/
public String getName() {
return name;
}
/**
* Sets the attributes of the Agent.
* Used for storing more complex properties than name or value.
**/
public void setAttributes(Hashtable attributes) {
this.attributes = attributes;
}
/**
* Gets the attributes of the Agent.
* Used to display properties on the interface.
**/
public Hashtable getAttributes() {
return attributes;
}
// End of class.
}