Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Menge::BFSM::State Class Reference

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...
 
StatetestTransitions (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...
 
GoalSelectorgetGoalSelector ()
 Returns a pointer to the goal selector. More...
 
void clearGoalSelector ()
 Clears the state's current goal selector.
 

Protected Member Functions

StatetestTransitions (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
 

Detailed Description

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.

Constructor & Destructor Documentation

Menge::BFSM::State::State ( const std::string &  name)

Constructor.

Parameters
nameThe name of this state.

Member Function Documentation

void Menge::BFSM::State::addAction ( Action a)
inline

Add an action to the state.

Parameters
aThe action to add.
void Menge::BFSM::State::addTransition ( Transition t)
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.

Parameters
tThe transition to add.
void Menge::BFSM::State::addVelModifier ( VelModifier v)
inline

Add an velocity modifier to the state.

Parameters
vThe modifier to add
void Menge::BFSM::State::enter ( Agents::BaseAgent agent)
virtual

Automatically called when an agent enters the state.

Parameters
agentThe agent who entered the state.
bool Menge::BFSM::State::getFinal ( ) const
inline

Reports if the state is final or not.

Returns
True if the state is a final state, false otherwise.
GoalSelector* Menge::BFSM::State::getGoalSelector ( )
inline

Returns a pointer to the goal selector.

Returns
Pointer to the state's goal selector.
size_t Menge::BFSM::State::getID ( ) const
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).

Returns
The state's identifier.
std::string Menge::BFSM::State::getName ( ) const
inline

Returns the name of the state.

Returns
The state's name.
size_t Menge::BFSM::State::getPopulation ( ) const

Returns the number of agents in this state.

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.

Parameters
agentThe agent for which a preferred velocity is computed.
velocityThe 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.

Parameters
fsmA pointer to the fsm. Tasks are fed to the fsm.
void Menge::BFSM::State::leave ( Agents::BaseAgent agent)
virtual

Automatically called when an agent leaves the state.

Parameters
agentThe agent who left the state.
void Menge::BFSM::State::setFinal ( bool  isFinal)
inline

Set whether the state is final or not.

Parameters
isFinalIf 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.

Parameters
selectorA pointer to the goal selector.
void Menge::BFSM::State::setVelComponent ( VelComponent vc)
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.

Parameters
vcThe 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.

Parameters
agentThe agent to test w.r.t. the transitions.
Returns
A pointer to the next state if a transition is active, otherwise, it returns NULL, meaning the agent remains in this state.
State * Menge::BFSM::State::testTransitions ( Agents::BaseAgent agent,
std::set< State * > &  visited 
)
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.

Parameters
agentThe agent to test w.r.t. the transitions.
visitedThe set of states visited during transition testing. Used to prevent cycles.
Returns
A pointer to the next state if a transition is active, otherwise, it returns NULL, meaning the agent remains in this state.

The documentation for this class was generated from the following files: