vitro
Class Controller

java.lang.Object
  extended by vitro.Controller
Direct Known Subclasses:
SequentialController, SimultaneousController, ThreadedController

public abstract class Controller
extends Object

A Controller manages the sequencing of turns in a simulation, associates Agents with one or more Actor and provides access to historical records of Actions and Annotations.


Field Summary
protected  Map<Actor,Agent> actorAgents
           
protected  Set<Agent> agents
           
protected  Map<Class,Agent> classAgents
           
 Model model
           
 
Constructor Summary
Controller(Model model)
          Construct a new Controller associated with a given Model.
 
Method Summary
protected  List<Actor> actors()
          Produce a List of Actors which can act during this timestep.
 Map<Annotation,Agent> annotations()
          Obtain a collection of Annotations for the current timestep.
 void bind(Actor actor, Agent agent)
          Associate a specific Actor with a specified Agent.
 void bind(Class c, Agent agent)
          Associate every Actor that is an instance of a given Class with a specified Agent.
protected
<A extends Actor>
Action
getAction(A a)
          Determine the Action a given Actor would choose next.
<A extends Actor>
Agent<A>
getAgent(A a)
          Obtain a reference to the Agent that makes decisions for a specific actor.
 boolean hasNext()
           
 boolean hasPrev()
           
 int index()
           
 void next()
          Advance the simulation.
protected abstract  List<Action> nextRound()
          This method is used to determine the order in which Actions will be applied.
 void prev()
          Restore the simulation to the previous state.
 List<Action> previousActions()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

model

public final Model model

agents

protected final Set<Agent> agents

classAgents

protected final Map<Class,Agent> classAgents

actorAgents

protected final Map<Actor,Agent> actorAgents
Constructor Detail

Controller

public Controller(Model model)
Construct a new Controller associated with a given Model.

Parameters:
model - the model which will be driven by this controller.
Method Detail

bind

public void bind(Class c,
                 Agent agent)
Associate every Actor that is an instance of a given Class with a specified Agent. Said Agent will be consulted every time the Actor has an opportunity to select an Action.

Parameters:
c - the Class of Actors to which the Agent will apply.
agent - the Agent to associate with Actors.

bind

public void bind(Actor actor,
                 Agent agent)
Associate a specific Actor with a specified Agent. These bindings will take priority over any Class-based bindings.

Parameters:
actor - the Actor to which the Agent will apply.
agent - the Agent to associate with an Actor.

getAgent

public <A extends Actor> Agent<A> getAgent(A a)
Obtain a reference to the Agent that makes decisions for a specific actor.

Parameters:
a - an Actor to examine.
Returns:
the Agent associated with the Actor or null if no binding exists.

getAction

protected <A extends Actor> Action getAction(A a)
Determine the Action a given Actor would choose next. This implementation ensures that the resulting Action is a valid choice given the state of the Model.

Parameters:
a - an Actor for which to decide.
Returns:
the selected Action or null.

hasNext

public boolean hasNext()
Returns:
true if the Model can advance to another state or false if the simulation is 'done'.

hasPrev

public boolean hasPrev()
Returns:
true if the Model can be rolled back to a previous state or false if no history exists.

next

public void next()
Advance the simulation.


prev

public void prev()
Restore the simulation to the previous state.


annotations

public Map<Annotation,Agent> annotations()
Obtain a collection of Annotations for the current timestep.

Returns:
a mapping from every Annotation to the Agent which produced it.

previousActions

public List<Action> previousActions()
Returns:
a list of every action carried out in the previous timestep.

actors

protected List<Actor> actors()
Produce a List of Actors which can act during this timestep. If the Model is Factional, Factional Actors will only be listed here if their team() value matches that of the Model.

Returns:
a List of Actors which may act.

index

public int index()
Returns:
the current timestep, counting from 0.

nextRound

protected abstract List<Action> nextRound()
This method is used to determine the order in which Actions will be applied. Controller implementations may provide different behaviors here such as evaluating Actions concurrently or sequentially. The List returned by this method is stored for rollback purposes- the Actions themselves should be applied in the body of this method.

Returns:
a record of Actions applied as the state is advanced.