You are on page 1of 5

Creating a Basic GIS Agent Environment

By Karl D. Liebert, modpop@charter.net With considerable consultation and source code from Nick Collier, nick.collier@gmail.com his doc is meant to bridge the gap bet!een the "epast # tutorial and the e$planation of the %eography pro&ection in the "eference document. ' little e$perience and the ad(ice of Nick Collier, the primary author of the %)# aspects of "epast #, made it clear that *a(a Classes are the best choice for more comple$ models as !ell as %)# models. #o if you are trying to construct a comple$ %)# model, get ready to !rite some *a(a code. his e$ample includes three files. he model.score, the %)#Conte$tCreator class, and the %is'gent class.

Create a new Project


)f you are in the +clipse *a(a ,erspecti(e, select File->New->Other..., then select Repast Simphony->Repast Simphony Project. -" )f you are in the +clipse "epast ,erspecti(e, you can simply select File->New->Repast Simphony Project. he ,ro&ect Name used in this e$ample is %)#. est. 'ccept defaults for the remainder of the ,ro&ect creation dialog bo$es and /inish.

Add Necessary Items to the model.score


he model.score file is key to pro(iding the "epast "untime to manage your agents and pro&ections. )n the case of *a(a classes, the names must match the associated classes you create. 0. "ight click on %)# est in the model.score editor tab then select Create Member->Projection Geo raphy. 1. )n the ,roperties tab for the ne! %eography, change the Label to Geo raphy and the ,lural Label to Geo raphies. he default name !ill cause an error !hen the display initiali2es. 3 he names are arbitrary, but must be consistent throughout this e$ample.4 5. "ight click on %)# est in the model.score editor tab, then select Create Member->! ent. 6. )n the properties tab for the ne! 'gent, change the label to Gis! ent.

7. 8erify the $ml code for the model.score file by opening it in Notepad. )t9s path !ill be something like C"#RepastS#wor$space#G%S&'est# istest.rs#mo(el.score. )t should look something like this:
<?xml version="1.0" encoding="UTF-8"?> <score:SContext xmlns:xsi=" tt!:""###.#$.org"%001"&'(Sc em)-inst)nce" xmlns:score=" tt!:""score)*m.org"score" l)*el="+,STest" ,-="g,STest" !l.r)l()*el="+,STests"> <im!lement)tion !)c/)ge="gistest" cl)ss0)me="" *)se1)t =".."+,S2Test" mode="3UT4""> <)gents l)*el="+is3gent" ,-="gis3gent" !l.r)l()*el="+is3gents"> <im!lement)tion cl)ss0)me="+is3gent""> <")gents> <!ro5ections xsi:t6!e="score:S+eogr)! 6" l)*el="+eogr)! 6" ,-="geogr)! 6" !l.r)l()*el="+eogr)! ies""> <"score:SContext>

;. <ean!hile, your model.score editor should look like this, minus the &a(a classes in the ,ackage +$plorer 3We ha(en9t gotten there yet.4:

Add the Agent and ContextCreator Classes


he agent can be a (ery simple class. ) tried to keep this as simple as possible, but found the agent needed to ha(e, minimally, one attribute and the associated %etter and #etter to a(oid an error. 0. o create the %is'gent, right click on the istest package in the ,ackage +$plorer. #elect New->Class. 1. +nter Gis! ent in the Name field and select /inish. 5. Complete the %is'gent as belo!:

package gistest7 public class +is3gent 8 int some-)t)7 public +is3gent9: 8 some-)t) = 07 ; public int getSome-)t)9: 8 return some-)t)7 ; public void setSome-)t)9int some-)t): 8 this.some-)t) = some-)t)7 ;

6.

o create the %)#Conte$tCreator, right click on the istest package in the ,ackage +$plorer. #elect New->Class.

7. +nter G%SConte)tCreator in the Name field. ;. )n the )nterfaces list, select the !((... button. =. )n the field under Choose )nterfaces, enter Conte)t*+il(er. By the time you get to 9B9, the <atching )tems list !ill ha(e narro!ed it do!n to right class in repast.simphony.dataloader. #elect Conte)t*+il(er from the <atching )tems list and hit the !(( button. /inally hit the /inish button. >. )n the editor tab for %)#Conte$tBuilder, complete the class as follo!s:
package gistest7 import com.vividsol.tions.5ts.geom.Coordin)te7 import com.vividsol.tions.5ts.geom.+eometr6F)ctor67 import com.vividsol.tions.5ts.geom.1oint7 import import import import import re!)st.sim! re!)st.sim! re!)st.sim! re!)st.sim! re!)st.sim! on6.context.Context7 on6.context.s!)ce.gis.+eogr)! 6F)ctor6Finder7 on6.d)t)(o)der.Context<.ilder7 on6.s!)ce.gis.+eogr)! 67 on6.s!)ce.gis.+eogr)! 61)r)meters7

public class +,SContextCre)tor implements Context<.ilder<+is3gent> 8 public Context<+is3gent> *.ild9Context<+is3gent> context: 8 "" <ec).se t e +eogr)! 6 )cts )s ) cont)iner =or t e "" +is3gent )nd its "" )ssoci)ted Coordin)te> 6o. need to tell t e F)ctor6 "" # )t it #ill *e "" storing> ) <+is3gent>. +eogr)! 61)r)meters<+is3gent> geo1)r)ms = new +eogr)! 61)r)meters<+is3gent>9:7 +eogr)! 6<+is3gent> geogr)! 6 =

+eogr)! 6F)ctor6Finder.createGeographyFactory9null:.cre)te+eogr)! 69"+eog r)! 6"> context> geo1)r)ms:7 "" =)c cre)tes Coordin)tes to old )gent !ositions. +eometr6F)ctor6 =)c = new +eometr6F)ctor69:7 for 9int i = 07 i < 107 i??: 8 "" 3dded t e )gent to t e context. +is3gent )gent = new +is3gent9:7 context.)dd9)gent:7 "" T en !osition t e )gent. "" Since )n )gent is ) 14@4 )nd its "" !osition is eld in t e geometr6 "" r)t er t )n t e o*5ect itsel=> !oint "" )gentAs !osition doesnAt need "" to *e )n )ttri*.te o= t e )gent itsel=. Coordin)te coord = new Coordin)te9-10$.8%$ ? i " 100.0> BB.$C$:7 1oint geom = =)c.cre)te1oint9coord:7 geogr)! 6.move9)gent> geom:7 ; return context7 ; ;

Launch the Runtime and Edit the Scenario


here are t!o tasks in this section, adding the Conte$tBuilder as a Data Loader and defining the display. 0. Launch the runtime !indo! by selecting the little do!n arro! ne$t to the green play button, the selecting R+n G%S&'est from the menu. 1. o add the data n the "epast #imphony runtime control !indo!, right click on Data Loaders and select Set ,ata -oa(er.

.. )n the ?#elect Data #ource ype@ list, select ?! Speci/ic 0a1a Class@. hen hit Ne$t. 2. )n the ?Class Name@ list, all of the Data Loaders creted thus far !ill be listed in the pullAdo!n menu. #elect istest.G%SConte)tCreator from the list. Bit the Ne$t button and then the /inish button. 7. Bit the #a(e button 3the diskette4. 3. o create the Display, rightAclick on ?Displays@ in the #cenario ree and select !(( ,isplay. 4. )n the ?Display Details@ dialog bo$ under ?,ro&ections and 8alue Layers@, #elect Geo raphy in the left side list and hit the arro! button to mo(e it to the right side list. hen hit the Ne$t button. >. )n the ?'gent #tyle@ dialog, %is'gent should be selected in the Layer order list. he 'gent Name field should be gistest.%is'gent. 'nd the %eometry should be ,-)N . Bit the +dit button. )n the agent style editor that pops up change the /ill Color and select the -K button. 3) think it is necessary currently to change some attribute of the 'gent #tyle to a(oid a bug.4 #elect the Ne$t button.

C. )n the #chedule Details, accept the defaults and hit the /inish button. 0D. #a(e the scenario.

Results
-K. We ha(e not added a step function, so nothing mo(es and there is not beha(ior. But procedures for those are co(ered in the utorial and should be straightfor!ard. 0. Bit the )nitiali2e button 3round blue button !ith little man figure in it4. 1. Eou should obser(e that the %)# est:' Display is sho!n !ith a ro! of sFuares in !hate(er color you chose for the agent style. 's sho!n here:

You might also like