1

I have a simple Agent in a simple context (geography package) which operates using latitude and longitude to represent space. The agent is supposed to die on the 10th iteration of the model. It is then removed from the context. On the 10th iteration of the simulation, the agent stops doing the other methods (such as moving around), so I assume it has successfully been removed from the context/died, but it does not get removed from the simulation display (just sits there).

Why does it remain in the display and how can I remove it from the display as it dies?

UPDATE: there was a bug in the repast display code. The fix files are available by contacting Eric Tatara at repast-interest@lists.sourceforge.net, although all bugs will be removed in the next release version.

public class Agent {
public Geography<Object> geography;
public Context<Object> context;
public int id;


public Agent (Context<Object>context, Geography<Object>geography) {
    this.geography= geography;
    this.context=context;   

}

public int getId() {
    return id;
}


public void setId(int id) {
    this.id = id;
}

@ScheduledMethod(start = 1, pick = 1, interval = 1)
public void otherMethods() {

}

@ScheduledMethod(start = 10, pick = 1, interval = 1)
public void die() {  
    Context context = ContextUtils.getContext(this);
    context.remove(this);

}

}
Taylor Marie
  • 325
  • 1
  • 14

1 Answers1

2

You need to remove your agent from the geography in your die() method, I think.

In the repast code that handles removing agents from the display, the removal is triggered by an event in the Projection object associated with the display - in your case the Geography. Strangely, the Geography interface does not define a remove() method, but one is implemented in the DefaultGeography class. It's likely that your Geography is actually a DefaultGeography concrete object, so you could try the following addition to your die() method:

@ScheduledMethod(start = 10, pick = 1, interval = 1)
public void die() {  
    Context context = ContextUtils.getContext(this);
    context.remove(this);
    ((DefaultGeography) geography).remove(this);

}

Notes

  1. You are getting the context in the die() method, but already have a reference to it from when you construct your Agent, so this is almost certainly redundant.
  2. You need to make sure your display is actually scheduled to update. By default they are, but you should double click on the display in the left hand navigator pane of the GUI and check the Schedule Details tab to make sure that the display updates on a regular schedule (not ONE_TIME)
J Richard Snape
  • 18,946
  • 5
  • 47
  • 73
  • Hi Richard. Thanks for your answer. I contacted the creator of the Geography package, Eric Tatara, who found a bug in the display code. Luckily he fixed the bug and sent me the replacement files for repast. If you are interested obtaining the files, email repast-interest@lists.sourceforge.net. – Taylor Marie Feb 24 '15 at 06:10