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 Attributes | Friends | List of all members
Menge::BFSM::FSM Class Reference

Templated class for the behavior finite state machine. More...

#include <FSM.h>

Public Member Functions

 FSM (Agents::SimulatorInterface *sim)
 Constructor. More...
 
 ~FSM ()
 Destructor.
 
void collectTasks ()
 Collects all tasks from the FSM elements.
 
void addTask (Task *task)
 Adds a task to the set. More...
 
void setAgentCount (size_t count)
 Initializes the memory required for the number of agents included in the FSm. More...
 
void advance (Agents::BaseAgent *agent)
 Advances the FSM based on the current state for the given agent. More...
 
void computePrefVelocity (Agents::BaseAgent *agent)
 Computes the preferred velocity for the given agent based on the FSM's record of which state the agent is in.
 
StategetNode (size_t id)
 Get the pointer for the node with the given identifier. More...
 
StategetNode (const std::string &name)
 Returns the state with the given name. More...
 
size_t getNodeCount () const
 Reports the number of states in the FSM. More...
 
size_t addNode (State *node)
 Adds a state to the BFSM. More...
 
bool addTransition (size_t fromNode, Transition *t)
 Adds the given transition to the FSM. More...
 
bool addGoal (size_t goalSet, size_t goalID, Goal *goal)
 Adds a goal to the indicated goal set. More...
 
const GoalgetGoal (size_t goalSet, size_t goalID)
 Retrieves the given goal from the given goal set. More...
 
const GoalSetgetGoalSet (size_t goalSetID)
 Retrives the given goal set. More...
 
bool doStep ()
 Update the fsm state by one time step. More...
 
void setCurrentState (Agents::BaseAgent *agt, size_t currNode)
 Sets the current state for the given agent. More...
 
StategetCurrentState (const Agents::BaseAgent *agt) const
 Gets a pointer to the state the agent is currently in. More...
 
size_t getAgentStateID (const Agents::BaseAgent *agent) const
 Reports the state the given agent is currently in. More...
 
size_t getAgentStateID (size_t agentID) const
 Reports the state the given agent is currently in. More...
 
bool allFinal () const
 Reports if all agents are in final states (i.e. the simulation is done.) More...
 
const Agents::SimulatorInterfacegetSimulator () const
 Retrieve the simulator.
 
void doTasks ()
 Performs the work in the FSM's tasks.
 
size_t getTaskCount () const
 Returns the number of registered tasks.
 
void finalize ()
 Finalize the FSM.
 
FsmContextgetContext ()
 Returns the BFSM Context for this FSM. More...
 
std::map< size_t, GoalSet * > & getGoalSets ()
 Returns the goal sets defined in the simulator. More...
 
void addVelModifier (VelModifier *v)
 Add an velocity modifier to the FSM. More...
 

Protected Attributes

Agents::SimulatorInterface_sim
 The simulator on which the FSM acts.
 
size_t _agtCount
 Number of agents attached to the state machine. More...
 
State ** _currNode
 The active state for each agent in the system.
 
std::vector< State * > _nodes
 The states in the BFSM.
 
std::vector< Task * > _tasks
 The set of tasks to perform at each time step.
 
std::map< size_t, GoalSet * > _goalSets
 Mapping from goal set identifier to GoalSet.
 
std::vector< VelModifier * > _velModifiers
 A list of velocity modifiers to be applied to all states in the simulator.
 

Friends

FSMbuildFSM (FSMDescrip &fsmDescrip, Agents::SimulatorInterface *sim, bool VERBOSE)
 Templated function which builds the behavior fsm from the behavior configuration given. More...
 

Detailed Description

Templated class for the behavior finite state machine.

Constructor & Destructor Documentation

Menge::BFSM::FSM::FSM ( Agents::SimulatorInterface sim)

Constructor.

Parameters
simThe simulator to operate on.

Member Function Documentation

bool Menge::BFSM::FSM::addGoal ( size_t  goalSet,
size_t  goalID,
Goal goal 
)

Adds a goal to the indicated goal set.

Parameters
goalSetThe id of the goal set which receives the goal.
goalIDThe id of the goal in the goal set.
goalThe goal to add.
Returns
A boolean reporting success (true) or failure (false)
size_t Menge::BFSM::FSM::addNode ( State node)

Adds a state to the BFSM.

Parameters
nodeThe state to add.
Returns
A unique identifier for the newly added state.
void Menge::BFSM::FSM::addTask ( Task task)

Adds a task to the set.

Elements can blindly add tasks to the finite state machine (including adding a null pointer. If the pointer is null, no work is done. If the pointer is a duplicate of a previous task, it will not be repeatedly added.

The FSM takes possession of the task and is responsible for cleaning the memory.

Parameters
taskA pointer to a task to add.
bool Menge::BFSM::FSM::addTransition ( size_t  fromNode,
Transition t 
)

Adds the given transition to the FSM.

The transition already contains a pointer to the destination state (see Transition).

Parameters
fromNodeThe global identifier from the origin state.
tThe transition to add.
Returns
True if the transition is successfully added, false otherwise.
void Menge::BFSM::FSM::addVelModifier ( VelModifier v)
inline

Add an velocity modifier to the FSM.

Parameters
vThe modifier to add
void Menge::BFSM::FSM::advance ( Agents::BaseAgent agent)

Advances the FSM based on the current state for the given agent.

Parameters
agentThe agent to advance the FSM for.
bool Menge::BFSM::FSM::allFinal ( ) const

Reports if all agents are in final states (i.e. the simulation is done.)

Returns
True if all agents are in a final state, false otherwise.
bool Menge::BFSM::FSM::doStep ( )

Update the fsm state by one time step.

Returns
A boolean reporting if all agents are in a final state (true) or not (false).
size_t Menge::BFSM::FSM::getAgentStateID ( const Agents::BaseAgent agent) const

Reports the state the given agent is currently in.

Parameters
agentA pointer to the agent whose state id is returned.
Returns
The id of the state the given agent is in.
size_t Menge::BFSM::FSM::getAgentStateID ( size_t  agentID) const

Reports the state the given agent is currently in.

Parameters
agentIDThe unique id of the agent whose state id is returned.
Returns
The id of the state the given agent is in.
FsmContext * Menge::BFSM::FSM::getContext ( )

Returns the BFSM Context for this FSM.

A new FsmContext will be constructed upon each call to this function. It is the responsibility of the caller to make sure it gets deleted.

Returns
A pointer to a valid fsm context.
State * Menge::BFSM::FSM::getCurrentState ( const Agents::BaseAgent agt) const

Gets a pointer to the state the agent is currently in.

Parameters
agtThe agent.
Returns
A pointer to the agent's current state.
const Goal * Menge::BFSM::FSM::getGoal ( size_t  goalSet,
size_t  goalID 
)

Retrieves the given goal from the given goal set.

Parameters
goalSetThe identifier of the goal set.
goalIDThe identifier of the goal.
Returns
A pointer to the corresponding goal. If no such goal exists NULL is returned.
const GoalSet * Menge::BFSM::FSM::getGoalSet ( size_t  goalSetID)

Retrives the given goal set.

Parameters
goalSetIDThe identifier of the goal set.
Returns
A pointer to the corresponding goal set. If no such goal set exists, NULL is returned.
std::map< size_t, GoalSet * >& Menge::BFSM::FSM::getGoalSets ( )
inline

Returns the goal sets defined in the simulator.

Returns
A reference to the goal set map.
State* Menge::BFSM::FSM::getNode ( size_t  id)
inline

Get the pointer for the node with the given identifier.

Parameters
idThe state identifier. Id is not validated.
Returns
A pointer to the state with the given identifier.
State * Menge::BFSM::FSM::getNode ( const std::string &  name)

Returns the state with the given name.

Parameters
nameThe name of the desired state.
Returns
A pointer to the desired state (if it is found), otherwise, returns null.
size_t Menge::BFSM::FSM::getNodeCount ( ) const
inline

Reports the number of states in the FSM.

Returns
The number of states in the fsm.
void Menge::BFSM::FSM::setAgentCount ( size_t  count)

Initializes the memory required for the number of agents included in the FSm.

Parameters
countThe number of agents.
void Menge::BFSM::FSM::setCurrentState ( Agents::BaseAgent agt,
size_t  currNode 
)

Sets the current state for the given agent.

Parameters
agtThe agent whose BFSM state gets set.
currNodeThe unique identifier of the desired state (returned by FSM::addNode).

Friends And Related Function Documentation

FSM* buildFSM ( FSMDescrip fsmDescrip,
Agents::SimulatorInterface sim,
bool  VERBOSE 
)
friend

Templated function which builds the behavior fsm from the behavior configuration given.

Parameters
fsmDescripThe Behavior configuration.
simThe simulator which uses the BFSM.
VERBOSEThe optional argument which causes the construction process to report actions as it goes.
Returns
A pointer to the resultant FSM. If there is an error in construction, NULL is returned.

Member Data Documentation

size_t Menge::BFSM::FSM::_agtCount
protected

Number of agents attached to the state machine.

This should be the same as the number of agents in the simulator.


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