Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/mrd/models/example/ExampleModel.java


1   /*
2    * Copyright (C) 2002-2003, Mark Diggory
3    *
4    * This program is free software; you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation; either version 2 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, write to the Free Software
16   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. License
17   * information is also available at http://www.gnu.org.
18   *
19   */
20  package org.mrd.models.example;
21  
22  import org.apache.commons.logging.*;
23  import uchicago.src.sim.engine.*;
24  
25  import org.mrd.repast.util.*;
26  
27  /**
28   * This is a simple example layout for a RePast Model, All the basic 
29   * requirements are available plus 3 added features.
30   *
31   * 1.) The Stepable interface provides one method "step" to place code 
32   *     which will happen every interation of the model.
33   * 2.) The MaxIterations property provides a means to have the model stop
34   *     after a specific set of iterations have past.
35   * 3.) the "log" property is added to allow easly dumping of messages to the 
36   *     console window. 
37   *
38   * @author Mark Diggory <mdiggory@latte.harvard.edu>
39   * @version 0.1
40   */
41  public class ExampleModel extends SimModelImpl implements Stepable{
42      
43      protected Log log = LogFactory.getLog(this.getClass().getName());
44      
45      /** Every model must have a schedule */
46      protected Schedule schedule;
47      
48      /** Holds value of property maxIterations. */
49      protected double maxIterations = Double.MAX_VALUE;
50      
51      /** Holds value of property charArray. */
52      private char[] charArray = { 'c', 'h', 'a', 'r'};
53      
54      /** Holds value of property byteArray. */
55      private byte[] byteArray = { Byte.MAX_VALUE,Byte.MIN_VALUE };
56      
57      /** Holds value of property byteObjectArray. */
58      private Byte[] byteObjectArray = new Byte[]{new Byte(Byte.MAX_VALUE),new Byte(Byte.MIN_VALUE)};
59      
60      /** Holds value of property charObjectArray. */
61      private Character[] charObjectArray = new Character[]{ new Character('c'), new Character('h'), new Character('a'), new Character('r')};
62      
63      /** Holds value of property intArray. */
64      private int[] intArray = {1,2,3,4};
65      
66      /** Holds value of property intObjectArray. */
67      private Integer[] intObjectArray = new Integer[]{new Integer(1),new Integer(2),new Integer(3),new Integer(4)};
68      
69      /** Holds value of property doubleArray. */
70      private double[] doubleArray = {1.0,2.0,3.0,4.0};
71      
72      /** Holds value of property doubleObjectArray. */
73      private Double[] doubleObjectArray= new Double[]{new Double(1.0),new Double(2.0),new Double(3.0),new Double(4.0)};
74      
75      /** Holds value of property longArray. */
76      private long[] longArray  = {1,2,3,4};
77      
78      /** Holds value of property longObjectArray. */
79      private Long[] longObjectArray = new Long[]{new Long(1),new Long(2),new Long(3),new Long(4)};
80      
81      /** Holds value of property shortArray. */
82      private short[] shortArray  = {1,2,3,4};
83      
84      /** Holds value of property shortObjectArray. */
85      private Short[] shortObjectArray= new Short[]{new Short(Short.MAX_VALUE),new Short(Short.MIN_VALUE)};
86      
87      /** Holds value of property floatArray. */
88      private float[] floatArray  = {Float.MAX_VALUE,Float.MIN_VALUE};
89      
90      /** Holds value of property floatObjectArray. */
91      private Float[] floatObjectArray= new Float[]{new Float(Float.MAX_VALUE),new Float(Float.MIN_VALUE)};
92      
93      /** Holds value of property stringArray. */
94      private String[] stringArray = new String[]{"S","t","r","i","n","g"};
95      
96      /** Holds value of property booleanArray. */
97      private boolean[] booleanArray = {true, false};
98      
99      /** Holds value of property booleanObjectArray. */
100     private Boolean[] booleanObjectArray = new Boolean[]{new Boolean(true), new Boolean(false)};
101     
102     /** Holds value of property foo. */
103     private Foo[] foo = {new Foo("foo"), new Foo("bar")};
104     
105     /** Holds value of property bar. */
106     private Bar[] bar = {new Bar(99.0), new Bar(99.0)};
107     
108     public ExampleModel(){
109         super();
110         
111         descriptors.put("ByteArray",new ArrayPropertyDescriptor("byteArray",byteArray));
112         descriptors.put("ByteObjectArray",new ArrayPropertyDescriptor("byteObjectArray",byteObjectArray));
113         descriptors.put("CharArray",new ArrayPropertyDescriptor("charArray",charArray));
114         descriptors.put("CharObjectArray",new ArrayPropertyDescriptor("charObjectArray",charObjectArray));
115         descriptors.put("DoubleArray",new ArrayPropertyDescriptor("doubleArray",doubleArray));
116         descriptors.put("DoubleObjectArray",new ArrayPropertyDescriptor("doubleObjectArray",doubleObjectArray));
117         descriptors.put("FloatArray",new ArrayPropertyDescriptor("floatArray",floatArray));
118         descriptors.put("FloatObjectArray",new ArrayPropertyDescriptor("floatObjectArray",floatObjectArray));
119         descriptors.put("IntArray",new ArrayPropertyDescriptor("intArray",intArray));
120         descriptors.put("IntObjectArray",new ArrayPropertyDescriptor("intObjectArray",intObjectArray));
121         descriptors.put("LongArray",new ArrayPropertyDescriptor("longArray",longArray));
122         descriptors.put("LongObjectArray",new ArrayPropertyDescriptor("longObjectArray",longObjectArray));
123         descriptors.put("ShortArray",new ArrayPropertyDescriptor("shortArray",shortArray));
124         descriptors.put("ShortObjectArray",new ArrayPropertyDescriptor("shortObjectArray",shortObjectArray));
125 
126         descriptors.put("BooleanArray",new ArrayPropertyDescriptor("booleanArray",booleanArray));
127         descriptors.put("BooleanObjectArray",new ArrayPropertyDescriptor("booleanObjectArray",booleanObjectArray));
128         
129         descriptors.put("StringArray",new ArrayPropertyDescriptor("stringArray",shortObjectArray));
130 
131     
132         descriptors.put("Foo",
133                         new ArrayPropertyDescriptor("foo",
134                                                     foo,
135                                                     new ObjectEditor(){
136             public Object getNewInstance(String value){
137                 return new Foo(value.toString());
138             }
139         }
140         ));
141     
142         descriptors.put("Bar",
143                         new ArrayPropertyDescriptor("bar",
144                                                     bar,
145                                                     new ObjectEditor(){
146             public Object getNewInstance(String value){
147                 return new Bar(Double.parseDouble(value));
148             }
149         }
150         ));
151     }
152     
153     public java.lang.String[] getInitParam(){
154         return new String[]{"maxIterations", 
155             "byteArray", "byteObjectArray",
156             "charArray", "charObjectArray",
157             "doubleArray", "doubleObjectArray",
158             "floatArray", "floatObjectArray",
159             "intArray", "intObjectArray",
160             "longArray", "longObjectArray",
161             "shortArray", "shortObjectArray",
162             "booleanArray", "booleanObjectArray",
163             
164             "stringArray","foo","bar"
165         };
166     }
167     
168     public java.lang.String getName(){
169         return "Demo Model";
170     }
171     
172     public void setup() {
173         log.debug("setup()");
174         
175         // create a schedule with an interval of one.
176         schedule = new Schedule(1.0);
177     }
178     
179     public void begin() {
180         log.debug("begin()");
181         
182         // Adding basic update and shutdown events to schedule
183         schedule.scheduleActionAtInterval(1.0,this,"step", Schedule.LAST);
184         schedule.scheduleActionAt(maxIterations,this,"stop",Schedule.LAST);
185     }
186     
187     public void step(){
188         log.debug("step()");
189 
190         System.out.println("");
191     }
192     
193     
194     /** Getter for property maxIterations.
195      * @return Value of property maxIterations.
196      */
197     public double getMaxIterations() {
198         return this.maxIterations;
199     }
200     
201     /** Setter for property maxIterations.
202      * @param maxIterations New value of property maxIterations.
203      */
204    /* public void setMaxIterations(double maxIterations) {
205         this.maxIterations = maxIterations;
206     }*/
207     
208     /** Getter for property schedule.
209      * @return Value of property schedule.
210      */
211     public Schedule getSchedule(){
212         return schedule;
213     }
214     
215     /** Setter for property schedule.
216      * @param schedule New value of property schedule.
217      */
218     public void setSchedule(Schedule schedule) {
219         this.schedule = schedule;
220     }
221 
222     /** Getter for property charArray.
223      * @return Value of property charArray.
224      */
225     public char[] getCharArray() {
226         return this.charArray;
227     }
228     
229     /** Setter for property charArray.
230      * @param charArray New value of property charArray.
231      */
232     public void setCharArray(char[] charArray) {
233         this.charArray = charArray;
234     }
235     
236     /** Getter for property byteArray.
237      * @return Value of property byteArray.
238      */
239     public byte[] getByteArray() {
240         return this.byteArray;
241     }
242     
243     /** Setter for property byteArray.
244      * @param byteArray New value of property byteArray.
245      */
246     public void setByteArray(byte[] byteArray) {
247         this.byteArray = byteArray;
248     }
249     
250     /** Getter for property byteObjectArray.
251      * @return Value of property byteObjectArray.
252      */
253     public Byte[] getByteObjectArray() {
254         return this.byteObjectArray;
255     }
256     
257     /** Setter for property byteObjectArray.
258      * @param byteObjectArray New value of property byteObjectArray.
259      */
260     public void setByteObjectArray(Byte[] byteObjectArray) {
261         this.byteObjectArray = byteObjectArray;
262     }
263     
264     /** Getter for property charObjectArray.
265      * @return Value of property charObjectArray.
266      */
267     public Character[] getCharObjectArray() {
268         return this.charObjectArray;
269     }
270     
271     /** Setter for property charObjectArray.
272      * @param charObjectArray New value of property charObjectArray.
273      */
274     public void setCharObjectArray(Character[] charObjectArray) {
275         this.charObjectArray = charObjectArray;
276     }
277     
278     /** Getter for property intArray.
279      * @return Value of property intArray.
280      */
281     public int[] getIntArray() {
282         return this.intArray;
283     }
284     
285     /** Setter for property intArray.
286      * @param intArray New value of property intArray.
287      */
288     public void setIntArray(int[] intArray) {
289         this.intArray = intArray;
290     }
291     
292     /** Getter for property intObjectArray.
293      * @return Value of property intObjectArray.
294      */
295     public Integer[] getIntObjectArray() {
296         return this.intObjectArray;
297     }
298     
299     /** Setter for property intObjectArray.
300      * @param intObjectArray New value of property intObjectArray.
301      */
302     public void setIntObjectArray(Integer[] intObjectArray) {
303         this.intObjectArray = intObjectArray;
304     }
305     
306     /** Getter for property doubleArray.
307      * @return Value of property doubleArray.
308      */
309     public double[] getDoubleArray() {
310         return this.doubleArray;
311     }
312     
313     /** Setter for property doubleArray.
314      * @param doubleArray New value of property doubleArray.
315      */
316     public void setDoubleArray(double[] doubleArray) {
317         this.doubleArray = doubleArray;
318     }
319     
320     /** Getter for property doubleObjectArray.
321      * @return Value of property doubleObjectArray.
322      */
323     public Double[] getDoubleObjectArray() {
324         return this.doubleObjectArray;
325     }
326     
327     /** Setter for property doubleObjectArray.
328      * @param doubleObjectArray New value of property doubleObjectArray.
329      */
330     public void setDoubleObjectArray(Double[] doubleObjectArray) {
331         this.doubleObjectArray = doubleObjectArray;
332     }
333     
334     /** Getter for property longArray.
335      * @return Value of property longArray.
336      */
337     public long[] getLongArray() {
338         return this.longArray;
339     }
340     
341     /** Setter for property longArray.
342      * @param longArray New value of property longArray.
343      */
344     public void setLongArray(long[] longArray) {
345         this.longArray = longArray;
346     }
347     
348     /** Getter for property longObjectArray.
349      * @return Value of property longObjectArray.
350      */
351     public Long[] getLongObjectArray() {
352         return this.longObjectArray;
353     }
354     
355     /** Setter for property longObjectArray.
356      * @param longObjectArray New value of property longObjectArray.
357      */
358     public void setLongObjectArray(Long[] longObjectArray) {
359         this.longObjectArray = longObjectArray;
360     }
361     
362     /** Getter for property shortArray.
363      * @return Value of property shortArray.
364      */
365     public short[] getShortArray() {
366         return this.shortArray;
367     }
368     
369     /** Setter for property shortArray.
370      * @param shortArray New value of property shortArray.
371      */
372     public void setShortArray(short[] shortArray) {
373         this.shortArray = shortArray;
374     }
375     
376     /** Getter for property shortObjectArray.
377      * @return Value of property shortObjectArray.
378      */
379     public Short[] getShortObjectArray() {
380         return this.shortObjectArray;
381     }
382     
383     /** Setter for property shortObjectArray.
384      * @param shortObjectArray New value of property shortObjectArray.
385      */
386     public void setShortObjectArray(Short[] shortObjectArray) {
387         this.shortObjectArray = shortObjectArray;
388     }
389     
390     /** Getter for property floatArray.
391      * @return Value of property floatArray.
392      */
393     public float[] getFloatArray() {
394         return this.floatArray;
395     }
396     
397     /** Setter for property floatArray.
398      * @param floatArray New value of property floatArray.
399      */
400     public void setFloatArray(float[] floatArray) {
401         this.floatArray = floatArray;
402     }
403     
404     /** Getter for property floatObjectArray.
405      * @return Value of property floatObjectArray.
406      */
407     public Float[] getFloatObjectArray() {
408         return this.floatObjectArray;
409     }
410     
411     /** Setter for property floatObjectArray.
412      * @param floatObjectArray New value of property floatObjectArray.
413      */
414     public void setFloatObjectArray(Float[] floatObjectArray) {
415         this.floatObjectArray = floatObjectArray;
416     }
417     
418     /** Getter for property stringArray.
419      * @return Value of property stringArray.
420      */
421     public String[] getStringArray() {
422         return this.stringArray;
423     }
424     
425     /** Setter for property stringArray.
426      * @param stringArray New value of property stringArray.
427      */
428     public void setStringArray(String[] stringArray) {
429         this.stringArray = stringArray;
430     }
431     
432     /** Getter for property booleanArray.
433      * @return Value of property booleanArray.
434      */
435     public boolean[] getBooleanArray() {
436         return this.booleanArray;
437     }
438     
439     /** Setter for property booleanArray.
440      * @param booleanArray New value of property booleanArray.
441      */
442     public void setBooleanArray(boolean[] booleanArray) {
443         this.booleanArray = booleanArray;
444     }
445     
446     /** Getter for property booleanObjectArray.
447      * @return Value of property booleanObjectArray.
448      */
449     public Boolean[] getBooleanObjectArray() {
450         return this.booleanObjectArray;
451     }
452     
453     /** Setter for property booleanObjectArray.
454      * @param booleanObjectArray New value of property booleanObjectArray.
455      */
456     public void setBooleanObjectArray(Boolean[] booleanObjectArray) {
457         this.booleanObjectArray = booleanObjectArray;
458     }
459     
460     /** Getter for property foo.
461      * @return Value of property foo.
462      */
463     public Foo[] getFoo() {
464         return this.foo;
465     }
466     
467     /** Setter for property foo.
468      * @param foo New value of property foo.
469      */
470     public void setFoo(Foo[] foo) {
471         this.foo = foo;
472     }
473     
474     /** Getter for property bar.
475      * @return Value of property bar.
476      */
477     public Bar[] getBar() {
478         return this.bar;
479     }
480     
481     /** Setter for property bar.
482      * @param bar New value of property bar.
483      */
484     public void setBar(Bar[] bar) {
485         this.bar = bar;
486     }
487     
488     public class Foo {
489         
490         protected String string;
491         
492         public Foo(String string){
493             this.string = string;
494         }
495         
496         public String toString(){
497             return string;
498         }
499     }
500     
501     public class Bar {
502         
503         protected double dbl;
504         
505         public Bar(double dbl){
506             this.dbl = dbl;
507         }
508         
509         public String toString(){
510             return Double.toString(dbl);
511         }
512     }    
513 }