Probing Agent Properties that are Objects: REPAST S
The way to probe agent properties that are user-defined objects in repast is through converters. For example, we have an agent with a parameter Volume, an object.
package properties; /* @author Shefali Kulkarni */ public class Volume { private double vol; private double minVol; private double maxVol; public Volume() { this.vol = 100; this.minVol = 0; this.maxVol = 500; } // to define Accessor methods @Override public String toString() { return vol+" "+minVol+" "+maxVol; } }
There is a need to write a Converter class for Volume, that converts Volume object to and from String. This is required since, the probe display is essentially String representation of Object. The definition for this Volume converter would be something as:
package properties.converter; import repast.simphony.parameter.StringConverter; /** * @author Shefali Kulkarni */ public class VolumeConverter implements StringConverter<Volume> { public Volume fromString(String str) { if(str.equals(null)) new Volume(); int index = str.indexOf(" "); System.out.println(index); Double vol = Double.parseDouble (str.substring(0,index)); int next_index = str.indexOf(" ",index+1); System.out.println(next_index); Double min = Double.parseDouble (str.substring(index+1,next_index)); double max = Double.parseDouble (str.substring(next_index+1, str.length())); return new Volume(vol,min,max); } public String toString(Volume obj) { if(obj.equals(null)) return "Volume of the Tank is Undefined."; return obj.getVol()+" "+obj.getMinVol()+ " "+obj.getMaxVol(); } }
The definition has to make sure that the object and string are convertible from each other.
The parameter annotation would then be as follows indicating the converter class.
package somepackage; public class SomeAgent{ @Parameter(displayName="Volume", usageName="volume", converter=" properties.converter.VolumeConverter") public Volume getVolume() { return volume; } public void setVolume(Volume volume) { this.volume=volume; } private Volume volume = null; }
If Volume is a simulation parameter, then this has to be included in extended_params.XML in the modelname.rs directory.
<parameters> <parameter name="sim_vol" displayName = "Simulation Volume" type = "properties.Volume" converter = "properties.converter.VolumeConverter" defaultValue = "0 100 500" /> </parameters>
It would be more exciting to probe Volume as a category, with its some or all instance variables as subcategory.
About this entry
You’re currently reading “Probing Agent Properties that are Objects: REPAST S,” an entry on Technical Musings
- Published:
- May 6, 2008 / 10:49 am
- Category:
- Agent-Based Systems, RePast S
- Tags:
1 Comment
Jump to comment form | comments rss [?] | trackback uri [?]