Professional Documents
Culture Documents
Basic GIS Agent Example
Basic GIS Agent Example
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.
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:
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 ; ;
.. )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: