sim.engine.TentativeStep Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mason Show documentation
Show all versions of mason Show documentation
MASON is a fast discrete-event multiagent simulation library core in Java, designed to be the foundation for large custom-purpose Java simulations, and also to provide more than enough functionality for many lightweight simulation needs. MASON contains both a model library and an optional suite of visualization tools in 2D and 3D.
The newest version!
/*
Copyright 2006 by Sean Luke and George Mason University
Licensed under the Academic Free License version 3.0
See the file "LICENSE" for more information
*/
package sim.engine;
/**
A Steppable wrapper which can be stopped. This is a convenience class for those situations where you'd
like to schedule an agent to get stepped once in the future, but then think better of it
and would like to prevent it from happening. Wrap your agent in the TentativeStep, then
schedule the TentativeStep on the Schedule. When you want to prevent the agent's step() method from
being called, simply call stop() on the TentativeStep. When stop() is called on a TentativeStep, it
sets its underlying agent to null and forgets about it. Note that the TentativeStep itself is still
scheduled, and so at some point the Schedule's time step will advance to that point even if the
underlying Steppable has been removed from the TentativeStep.
Example usage:
double scheduleTime = ...
Steppable mySteppable = ...
TentativeStep tent = new TentativeStep(mySteppable);
state.schedule.scheduleOnce(scheduleTime,tent);
Now, to stop mySteppable from being called before scheduleTime has come, you'd say:
tent.stop();
*/
public class TentativeStep implements Steppable, Stoppable
{
private static final long serialVersionUID = 1;
public Steppable step;
public TentativeStep(Steppable step)
{
this.step = step;
}
public synchronized void step(SimState state)
{
if (step!=null)
step.step(state);
}
public synchronized void stop()
{
step = null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy