Home » Modeling » AMP » Building Agents in the GUI (Discussion on how to use the hierarchical GUI tree to build agent logic)
| Building Agents in the GUI [message #523043] |
Wed, 24 March 2010 16:45  |
John T. Murphy Messages: 15 Registered: November 2009 |
Junior Member |
|
|
I'd like to open a discussion on how to build agent logic using AMP's hierarchical editor. As a starting point, consider:

This is the tree from the 'Movement' act of an Individual in the 'Epidemic' demo metaabm file. Here is the way the corresponding source code looks when this is generated as an Escape model:
public void movement() {
double movementDraw = getRandom().nextDouble();
if ((getStatus() != StatusEnum.dead
&& movementDraw < getEpidemic().getMovementProbability()
&& getStatus() != StatusEnum.symptomInfectious && movementDraw < getEpidemic()
.getMovementProbability())) {
{
Location neighboringLocation = (Location) ((org.ascape.model.space.Discrete) getEpidemic()
.getCity().getSpace())
.findRandomAvailableNeighbor(((org.ascape.model.CellOccupant) this)
.getHostCell());
if (neighboringLocation != null) {
if (getHostScape() != neighboringLocation.getScape()) {
die();
neighboringLocation.getEpidemic().getIndividualScape()
.add(this);
}
moveTo(neighboringLocation);
}
}
}
}
I'd like this forum to be a discussion about how AMP goes from the tree structure to the code.
As a starting point, consider the following question: notice that the code starts with a set of validation comparisons that define whether the agent should move or not; the criteria are: the agent is not status = dead; the agent is not status = symptomInfection; and the randomly selected value 'random draw' is less than the model attribute 'Movement Probability.' However, notice that the generated code compares the random value with the movement probability twice. Of course, comparing it twice doesn't matter (technically the short-circuit calculation will execute the comparison only once if it is false, and if it is true the first time then it will be true the second time). But still- out of a curiosity for how these things are structured, as an exercise, how would this double-comparison be eliminated?
Could we get a line-by-line (node by node) discussion of what, exactly, is going on in this little section of code and how it would be created? (By 'how' I mean what would be added as the first node, then the second, etc.- I notice, for example, that some nodes appear in the tree in multiple places, which I know corresponds to nodes that have multiple sources, AKA places where the data flow has branched and is coming back together, but I don't know how to edit this or what the code would look like for each elaboration from scratch to the finished code.) I'm also interested in how some parts (like the check to make sure the destination location is not null, and the reference to 'die()') got in the code at all; is there a template being applied, and if so where can I find it?
|
|
|
Goto Forum:
Current Time: Sun May 19 10:36:34 EDT 2013
Powered by FUDForum. Page generated in 0.01652 seconds
|