A set of goals. Maps integer identifiers to instances of goals.
More...
#include <GoalSet.h>
|
| GoalSet () |
| Default constructor.
|
|
| ~GoalSet () |
| Destructor.
|
|
bool | addGoal (size_t id, Goal *goal) |
| Add the given goal with the given id to the set. More...
|
|
Goal * | getGoalByID (size_t id) |
| Returns the goal with the given user-defined identifier. This is the identifier given the behavior specification. More...
|
|
Goal * | getGoalByIDConcurrent (size_t id) |
| Returns the goal with the given user-defined identifier. This is the identifier given the behavior specification. More...
|
|
Goal * | 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. More...
|
|
Goal * | 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. 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...
|
|
Goal * | getRandomGoal () |
| Select a goal randomly from the set with all having equal probability. More...
|
|
Goal * | getRandomWeightedGoal () |
| 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.
|
|
|
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.
|
|
|
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.
|
|
A set of goals. Maps integer identifiers to instances of goals.
bool Menge::BFSM::GoalSet::addGoal |
( |
size_t |
id, |
|
|
Goal * |
goal |
|
) |
| |
Add the given goal with the given id to the set.
- Parameters
-
id | The id for the given goal. |
goal | The 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
-
id | The 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
-
id | The 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
-
i | The 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
-
i | The 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:
- src/menge/MengeCore/BFSM/GoalSet.h
- src/menge/MengeCore/BFSM/GoalSet.cpp