Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added agent.MasonScheduledAgent.java #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions src/agent/MasonScheduledAgent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package agent;

import sim.engine.SimState;
import sim.engine.Steppable;

import inventory.Inventory;
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.getNextEventTime(state);
if (eventTime != null) {
state.schedule.scheduleOnce(eventTime, this);
}
}

/**
* 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);
}