From ecfdece77eb2c867084e5890557a248499d291d9 Mon Sep 17 00:00:00 2001 From: Torsten Date: Wed, 1 Feb 2017 20:06:37 +0000 Subject: [PATCH 1/2] added agent.MasonScheduledAgent.java --- src/agent/MasonScheduledAgent.java | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/agent/MasonScheduledAgent.java diff --git a/src/agent/MasonScheduledAgent.java b/src/agent/MasonScheduledAgent.java new file mode 100644 index 0000000..7010cbe --- /dev/null +++ b/src/agent/MasonScheduledAgent.java @@ -0,0 +1,33 @@ +/** + * Created by Torsten Heinrich + */ + +package agent; + +import sim.engine.SimState; +import sim.engine.Steppable; + +import inventory.Inventory; +import agent.Agent; +import java.util.List; + +public abstract class MasonScheduledAgent extends Agent implements Steppable{ + + public MasonScheduledAgent(String name, SimState state) { + super(name); + this.scheduleEvent(state); + } + + public void step(SimState state) { + this.scheduleEvent(state); + } + + public void scheduleEvent(SimState state) { + Double eventTime = this.findNextEvent(state); + if (eventTime != null) { + state.schedule.scheduleOnce(eventTime, this); + } + } + + public abstract Double findNextEvent(SimState state); +} From a2923e9a05d408b1d31bb22280e7e6d26f79c0a9 Mon Sep 17 00:00:00 2001 From: Torsten Date: Fri, 24 Feb 2017 12:34:05 +0000 Subject: [PATCH 2/2] re-adding agent.MasonScheduledAgent.java, commenting and renaming of method in MasonScheduledAgent.java --- src/agent/MasonScheduledAgent.java | 50 +++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/src/agent/MasonScheduledAgent.java b/src/agent/MasonScheduledAgent.java index 7010cbe..bb3ce18 100644 --- a/src/agent/MasonScheduledAgent.java +++ b/src/agent/MasonScheduledAgent.java @@ -1,7 +1,3 @@ -/** - * Created by Torsten Heinrich - */ - package agent; import sim.engine.SimState; @@ -11,23 +7,63 @@ import agent.Agent; import java.util.List; +/** + * MasonScheduledAgent are a subclass of Agent, which allows to have events + * for the agent scheduled in Mason. + * + * @author Torsten Heinrich (github.com/x0range) + */ public abstract class MasonScheduledAgent extends Agent implements Steppable{ + /** + * Constructor which sets the agent's name and calls scheduleEvent to + * schedule the first event. + * + * @param name + * the agent's name. + * @param state + * The Mason SimState - contains the scheduler + */ public MasonScheduledAgent(String name, SimState state) { super(name); this.scheduleEvent(state); } + /** + * Implementation of the Steppable interface in Mason. This is the method + * that is called when the Mason scheduler calls the Contract. The method + * will generally be overridden by classes inheriting from this one. + * + * @param state + * The Mason SimState - contains the scheduler + */ public void step(SimState state) { this.scheduleEvent(state); } + /** + * Schedule an Event within Mason. The time for this event is + * obtained from the findNextEvent function which needs to be + * implemented by classes inheriting from this one. + * + * @param state + * The Mason SimState - contains the scheduler + */ public void scheduleEvent(SimState state) { - Double eventTime = this.findNextEvent(state); + Double eventTime = this.getNextEventTime(state); if (eventTime != null) { state.schedule.scheduleOnce(eventTime, this); } } - - public abstract Double findNextEvent(SimState state); + + /** + * Finds the next event. + * + * @param state + * The Mason SimState - contains the scheduler + * + * @return returns the time at which the next event is to take place, + * i.e. when the agent's step function should next be called. + */ + public abstract Double getNextEventTime(SimState state); }