![]() |
fpmas 1.6
|
#include <model.h>
Public Member Functions | |
| Neighbors (const std::vector< Neighbor< AgentType > > &neighbors) | |
| iterator | begin () |
| const_iterator | begin () const |
| iterator | end () |
| const_iterator | end () const |
| std::size_t | count () const |
| bool | empty () const |
| Neighbor< AgentType > & | at (std::size_t i) |
| const Neighbor< AgentType > & | at (std::size_t i) const |
| Neighbor< AgentType > & | operator[] (std::size_t i) |
| const Neighbor< AgentType > & | operator[] (std::size_t i) const |
| template<typename Gen > | |
| Neighbors & | shuffle (Gen &gen) |
| Neighbors & | shuffle () |
| template<typename Compare = std::less<AgentType>> | |
| Neighbors & | sort (Compare comp=Compare()) |
| template<typename Filter > | |
| Neighbors & | filter (Filter _filter) |
| template<typename Gen > | |
| Neighbor< AgentType > | random (Gen &gen) |
| Neighbor< AgentType > | random () |
| template<typename Gen > | |
| const Neighbor< AgentType > | random (Gen &gen) const |
| const Neighbor< AgentType > | random () const |
Helper class used to represent Agents neighbors.
Neighbors are defined as Agents contained in neighbors of the node associated to a given Agent.
This class allows to easily iterate over Agents neighbors thanks to predefined iterators and the shuffle() method.
| AgentType | Type of agents in the neighbors set |
|
inline |
Neighbors constructor.
| neighbors | list of agent neighbors |
|
inline |
Begin iterator.
|
inline |
Const begin iterator.
|
inline |
End iterator.
|
inline |
Const end iterator.
|
inline |
Returns the count of neighbors in this list.
|
inline |
Checks if this neighbors list is empty.
|
inline |
Returns a reference to the neighbor at position i, with bounds checking.
| i | neighbor position |
| std::out_of_range | if !(i < count()) |
|
inline |
Returns a reference to the neighbor at position i, with bounds checking.
| i | neighbor position |
| std::out_of_range | if !(i < count()) |
|
inline |
Returns a reference to the neighbor at position i, without bounds checking.
| i | neighbor position |
|
inline |
Returns a reference to the neighbor at position i, without bounds checking.
| i | neighbor position |
|
inline |
Internally shuffles the neighbors list using std::shuffle and the provided random number generator.
Can be used to iterate randomly over the neighbors set.
|
inline |
Shuffles agent using the distributed RandomNeighbors::rd random number generator.
|
inline |
Sorts the neighbor list using the specified comparator.
By default, the comparison is performed on neighbors agents using the operator< on AgentType, that can be user defined.
In consequence, neighbors are sorted is ascending order by default. A custom comparator based on the operator> can be specified to sort neighbros in descending order.
En efficient way of defining other comparison functions is the usage of lambda functions:
More generally, Compare must be a type that defines a method with the following signature:
| Compare | comparator type |
| comp | comparator instance |
|
inline |
Filters the neighbor list.
The specified Filter must be an unary predicate such that for each agent in the current neighbor list, agent is kept only if _filter(agent) returns true.
| _filter | filter to apply |
|
inline |
Selects a random element of this neighbors list, using the specified random number generator.
Fails if count() == 0.
|
inline |
Selects a ramdom element of this neighbors list, using the distributed RandomNeighbors::rd random number generator.
|
inline |
Selects a random element of this neighbors list, using the specified random number generator.
Fails if count() == 0.
|
inline |
Selects a ramdom element of this neighbors list, using the distributed RandomNeighbors::rd random number generator.