Menge
Modular Pedestrian Simulation Framework for Research and Development
|
The basic state of the behavior finite state machine. More...
#include <State.h>
Public Member Functions | |
State (const std::string &name) | |
Constructor. More... | |
~State () | |
Destructor. | |
void | getTasks (FSM *fsm) |
Gets the tasks for all of the state's FSM elements. More... | |
void | getPrefVelocity (Agents::BaseAgent *agent, Agents::PrefVelocity &velocity) |
Modifies the input preferred velocity to reflect a velocity for the agent specified. More... | |
void | setFinal (bool isFinal) |
Set whether the state is final or not. More... | |
bool | getFinal () const |
Reports if the state is final or not. More... | |
State * | testTransitions (Agents::BaseAgent *agent) |
Test the transitions out of this state for the given agent. More... | |
virtual void | enter (Agents::BaseAgent *agent) |
Automatically called when an agent enters the state. More... | |
virtual void | leave (Agents::BaseAgent *agent) |
Automatically called when an agent leaves the state. More... | |
void | addTransition (Transition *t) |
Add a transition to the state. More... | |
void | setVelComponent (VelComponent *vc) |
Sets the velocity component to the state. More... | |
void | addAction (Action *a) |
Add an action to the state. More... | |
void | addVelModifier (VelModifier *v) |
Add an velocity modifier to the state. More... | |
size_t | getID () const |
Returns the globally unique state identifier. More... | |
std::string | getName () const |
Returns the name of the state. More... | |
size_t | getPopulation () const |
Returns the number of agents in this state. More... | |
void | setGoalSelector (GoalSelector *selector) |
Sets the goal selector for the state. More... | |
GoalSelector * | getGoalSelector () |
Returns a pointer to the goal selector. More... | |
void | clearGoalSelector () |
Clears the state's current goal selector. | |
Protected Member Functions | |
State * | testTransitions (Agents::BaseAgent *agent, std::set< State * > &visited) |
Test the transitions out of this state, tracking cycles. More... | |
Protected Attributes | |
VelComponent * | _velComponent |
The single velocity component associated with this state. | |
std::vector< Transition * > | transitions_ |
A priority-ordered list of transitions to determine if the state changes. The order of the transitions in the implicitly defines the testing priority. | |
std::vector< VelModifier * > | velModifiers_ |
A priority-ordered list of velocity modifiers to determine if the state changes. The order of the modifierss in the implicitly defines the testing priority. | |
std::vector< Action * > | actions_ |
Actions to take upon entering and leaving the state. | |
bool | _final |
Determines if the state is a final state (true), or not (false). | |
GoalSelector * | _goalSelector |
The goal selector for this state. | |
HASH_MAP< size_t, Goal * > | _goals |
A mapping from agent id to its per-agent goal. | |
std::string | _name |
The name of the state. | |
size_t | _id |
The globally unique id of state. | |
ReadersWriterLock | _goalLock |
The lock for accessing the goals. | |
Friends | |
class | StateContext |
The basic state of the behavior finite state machine.
A state node in the finite state machine for determining "behaviors". The state requires a velocity component to determine how the preferred velocity is computed (see VelComponent). State's can also include actions, taken on an agent when it leaves the state and an optional corresponding action upon leaving the state (see Action). Agents leave the state based on transitions (see Transition).
State's can be marked as "final". Agents can transition out of final states. However, in any given time step, when all agents are in final states the simulation stops.
Menge::BFSM::State::State | ( | const std::string & | name | ) |
Constructor.
name | The name of this state. |
|
inline |
Add an action to the state.
a | The action to add. |
|
inline |
Add a transition to the state.
It is assumed that the transition is already correctly connected to the states as is required (the "to" and "from" states). The order the transitions are added inherently defines their priority.
t | The transition to add. |
|
inline |
Add an velocity modifier to the state.
v | The modifier to add |
|
virtual |
Automatically called when an agent enters the state.
agent | The agent who entered the state. |
|
inline |
Reports if the state is final or not.
|
inline |
Returns a pointer to the goal selector.
|
inline |
Returns the globally unique state identifier.
The identifier is unique w.r.t. all other states (although the same identifier may be used for other entities in their own contexts).
|
inline |
Returns the name of the state.
size_t Menge::BFSM::State::getPopulation | ( | ) | const |
Returns the number of agents in this state.
void Menge::BFSM::State::getPrefVelocity | ( | Agents::BaseAgent * | agent, |
Agents::PrefVelocity & | velocity | ||
) |
Modifies the input preferred velocity to reflect a velocity for the agent specified.
agent | The agent for which a preferred velocity is computed. |
velocity | The preferred velocity object (by reference) to modify reflecting the agent's new velocity |
void Menge::BFSM::State::getTasks | ( | FSM * | fsm | ) |
Gets the tasks for all of the state's FSM elements.
fsm | A pointer to the fsm. Tasks are fed to the fsm. |
|
virtual |
Automatically called when an agent leaves the state.
agent | The agent who left the state. |
|
inline |
Set whether the state is final or not.
isFinal | If true, the state is set to be final, if false, not. |
void Menge::BFSM::State::setGoalSelector | ( | GoalSelector * | selector | ) |
Sets the goal selector for the state.
Once the goal selector is assigned to the state, the state takes ownership of the memory and is responsible for freeing it.
selector | A pointer to the goal selector. |
|
inline |
Sets the velocity component to the state.
Once this is called, the State takes ownership of the velocity component and the caller should not destroy it.
vc | The velocity component to set. |
State * Menge::BFSM::State::testTransitions | ( | Agents::BaseAgent * | agent | ) |
Test the transitions out of this state for the given agent.
The transitions will be tested in priority order. The first transition which is found to be active will be taken.
agent | The agent to test w.r.t. the transitions. |
|
protected |
Test the transitions out of this state, tracking cycles.
The transitions will be tested in priority order. The first transition which is found to be active will be taken.
agent | The agent to test w.r.t. the transitions. |
visited | The set of states visited during transition testing. Used to prevent cycles. |