Menge
Modular Pedestrian Simulation Framework for Research and Development
|
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. | |
State * | getNode (size_t id) |
Get the pointer for the node with the given identifier. More... | |
State * | getNode (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 Goal * | getGoal (size_t goalSet, size_t goalID) |
Retrieves the given goal from the given goal set. More... | |
const GoalSet * | getGoalSet (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... | |
State * | getCurrentState (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::SimulatorInterface * | getSimulator () 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. | |
FsmContext * | getContext () |
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 | |
FSM * | buildFSM (FSMDescrip &fsmDescrip, Agents::SimulatorInterface *sim, bool VERBOSE) |
Templated function which builds the behavior fsm from the behavior configuration given. More... | |
Templated class for the behavior finite state machine.
Menge::BFSM::FSM::FSM | ( | Agents::SimulatorInterface * | sim | ) |
Constructor.
sim | The simulator to operate on. |
bool Menge::BFSM::FSM::addGoal | ( | size_t | goalSet, |
size_t | goalID, | ||
Goal * | goal | ||
) |
Adds a goal to the indicated goal set.
goalSet | The id of the goal set which receives the goal. |
goalID | The id of the goal in the goal set. |
goal | The goal to add. |
size_t Menge::BFSM::FSM::addNode | ( | State * | node | ) |
Adds a state to the BFSM.
node | The state to add. |
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.
task | A 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).
fromNode | The global identifier from the origin state. |
t | The transition to add. |
|
inline |
Add an velocity modifier to the FSM.
v | The modifier to add |
void Menge::BFSM::FSM::advance | ( | Agents::BaseAgent * | agent | ) |
bool Menge::BFSM::FSM::allFinal | ( | ) | const |
Reports if all agents are in final states (i.e. the simulation is done.)
bool Menge::BFSM::FSM::doStep | ( | ) |
Update the fsm state by one time step.
size_t Menge::BFSM::FSM::getAgentStateID | ( | const Agents::BaseAgent * | agent | ) | const |
Reports the state the given agent is currently in.
agent | A pointer to the agent whose state id is returned. |
size_t Menge::BFSM::FSM::getAgentStateID | ( | size_t | agentID | ) | const |
Reports the state the given agent is currently in.
agentID | The unique id of the agent whose state id is returned. |
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.
State * Menge::BFSM::FSM::getCurrentState | ( | const Agents::BaseAgent * | agt | ) | const |
Gets a pointer to the state the agent is currently in.
agt | The agent. |
const Goal * Menge::BFSM::FSM::getGoal | ( | size_t | goalSet, |
size_t | goalID | ||
) |
Retrieves the given goal from the given goal set.
goalSet | The identifier of the goal set. |
goalID | The identifier of the goal. |
const GoalSet * Menge::BFSM::FSM::getGoalSet | ( | size_t | goalSetID | ) |
Retrives the given goal set.
goalSetID | The identifier of the goal set. |
|
inline |
Returns the goal sets defined in the simulator.
|
inline |
Get the pointer for the node with the given identifier.
id | The state identifier. Id is not validated. |
State * Menge::BFSM::FSM::getNode | ( | const std::string & | name | ) |
Returns the state with the given name.
name | The name of the desired state. |
|
inline |
Reports 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.
count | The number of agents. |
void Menge::BFSM::FSM::setCurrentState | ( | Agents::BaseAgent * | agt, |
size_t | currNode | ||
) |
Sets the current state for the given agent.
agt | The agent whose BFSM state gets set. |
currNode | The unique identifier of the desired state (returned by FSM::addNode). |
|
friend |
Templated function which builds the behavior fsm from the behavior configuration given.
fsmDescrip | The Behavior configuration. |
sim | The simulator which uses the BFSM. |
VERBOSE | The optional argument which causes the construction process to report actions as it goes. |
|
protected |
Number of agents attached to the state machine.
This should be the same as the number of agents in the simulator.