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::GoalSet Class Reference

A set of goals. Maps integer identifiers to instances of goals. More...

#include <GoalSet.h>

Public Member Functions

 GoalSet ()
 Default constructor.
 
 ~GoalSet ()
 Destructor.
 
bool addGoal (size_t id, Goal *goal)
 Add the given goal with the given id to the set. More...
 
GoalgetGoalByID (size_t id)
 Returns the goal with the given user-defined identifier. This is the identifier given the behavior specification. More...
 
GoalgetGoalByIDConcurrent (size_t id)
 Returns the goal with the given user-defined identifier. This is the identifier given the behavior specification. More...
 
GoalgetIthGoal (size_t i)
 Returns the ith available goal (doesn't necessarily correlate with the user-defined identifier). Merely the order in which the goals are ordered in the set. More...
 
GoalgetIthGoalConcurrent (size_t i)
 Returns the ith available goal (doesn't necessarily correlate with the user-defined identifier). Merely the order in which the goals are ordered in the set. More...
 
size_t size () const
 Reports the number of goals in the set. Not thread safe. More...
 
size_t sizeConcurrent () const
 Reports the number of goals in the set. Thread safe version. More...
 
GoalgetRandomGoal ()
 Select a goal randomly from the set with all having equal probability. More...
 
GoalgetRandomWeightedGoal ()
 Select a goal randomly, based on the relative weights of the goals. More...
 
void lockRead ()
 Locks the goal set for a read-only operations.
 
void releaseRead ()
 Unlocks the goal set from read-only operations.
 

Protected Member Functions

void setGoalFull (const Goal *goal) const
 Informs the goal set that the given goal has reached its capacity and should no longer be considered.
 
void setGoalAvailable (const Goal *goal) const
 Informs the goal set that the given goal, previously with full capacity, now has capacity to be assigned to a new agent.
 

Protected Attributes

std::map< size_t, Goal * > _goals
 The underlying mapping from user-specified goal identifier to goal.
 
std::vector< size_t > _goalIDs
 A vector of valid identifiers in the goal set.
 
float _totalWeight
 The sum of all goal weights.
 
UniformFloatGenerator _randVal
 The random die to select random and weighted goals.
 
ReadersWriterLock _lock
 The lock to maintain readers-writer access to the structure which control available goals.
 

Friends

class Goal
 

Detailed Description

A set of goals. Maps integer identifiers to instances of goals.

Member Function Documentation

bool Menge::BFSM::GoalSet::addGoal ( size_t  id,
Goal goal 
)

Add the given goal with the given id to the set.

Parameters
idThe id for the given goal.
goalThe goal to add to the set.
Returns
A boolean reporting succes on adding the goal. If the id does not already exist in the set, the goal is added and true is returned. Otherwise, nothing is changed and false is returned. Once a goal is added to the GoalSet, the GoalSet takes responsibility for freeing the memory.
Goal * Menge::BFSM::GoalSet::getGoalByID ( size_t  id)

Returns the goal with the given user-defined identifier. This is the identifier given the behavior specification.

This operation is not thread-safe. It should only be used in a context that is known to be "safe".

Parameters
idThe identifier of the desired goal.
Returns
A pointer to the desired goal. If the goal doesn't exist, NULL is returned. Also, if the goal has reached capacity, NULL is returned.
Goal * Menge::BFSM::GoalSet::getGoalByIDConcurrent ( size_t  id)

Returns the goal with the given user-defined identifier. This is the identifier given the behavior specification.

This operation is thread-safe. But it should not be called in the same thread that has already called GoalSet::lockRead.

Parameters
idThe identifier of the desired goal.
Returns
A pointer to the desired goal. If the goal doesn't exist, NULL is returned. Also, if the goal has reached capacity, NULL is returned.
Goal * Menge::BFSM::GoalSet::getIthGoal ( size_t  i)

Returns the ith available goal (doesn't necessarily correlate with the user-defined identifier). Merely the order in which the goals are ordered in the set.

This operation is not thread-safe. It should only be used in a context that is known to be "safe".

Parameters
iThe ith goal in the set – order is undefined.
Returns
A pointer to the desired goal. NULL is returned if the index exceeds the number of available goals.
Goal * Menge::BFSM::GoalSet::getIthGoalConcurrent ( size_t  i)

Returns the ith available goal (doesn't necessarily correlate with the user-defined identifier). Merely the order in which the goals are ordered in the set.

This operation is thread-safe. But it should not be called in the same thread that has already called GoalSet::lockRead.

Parameters
iThe ith goal in the set – order is undefined.
Returns
A pointer to the desired goal. NULL is returned if the index exceeds the number of available goals.
Goal * Menge::BFSM::GoalSet::getRandomGoal ( )

Select a goal randomly from the set with all having equal probability.

Returns
A pointer to the randomly selected goal
Goal * Menge::BFSM::GoalSet::getRandomWeightedGoal ( )

Select a goal randomly, based on the relative weights of the goals.

Returns
A pointer to the randomly selected goal
size_t Menge::BFSM::GoalSet::size ( ) const
inline

Reports the number of goals in the set. Not thread safe.

Returns
The number of goals in the set.
size_t Menge::BFSM::GoalSet::sizeConcurrent ( ) const

Reports the number of goals in the set. Thread safe version.

Returns
The number of goals in the set.

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