RepastHPC  2.3.1
Public Types | Public Member Functions | Public Attributes | List of all members
repast::relogo::AgentSet< T > Class Template Reference

Specialized indexable collection class for agents. More...

#include <AgentSet.h>

Public Types

typedef std::vector< T * >::iterator as_iterator
 
typedef std::vector< T * >::const_iterator const_as_iterator
 

Public Member Functions

 AgentSet ()
 Creates an empty agent set.
 
template<typename input_iterator >
 AgentSet (input_iterator start, input_iterator end)
 Creates an agent set and fills with elements from start through end.
 
 AgentSet (const AgentSet &set)
 Copy constructor.
 
template<typename input_iterator >
void addAll (input_iterator begin, input_iterator end)
 Adds all the agents from the start iterator through the end to this AgentSet.
 
void add (T *agent)
 Adds an agent to this AgentSet.
 
template<typename Functor >
void ask (Functor func)
 Calls the Functor on each agent in this AgentSet. More...
 
template<typename Functor , typename P1 >
void ask (Functor func, const P1 &p1)
 Calls the Functor on each agent in this AgentSet, passing the specified argument. More...
 
template<typename Functor , typename P1 >
void ask (Functor func, P1 &p1)
 Calls the Functor on each agent in this AgentSet, passing the specified argument. More...
 
template<typename Functor >
void apply (Functor &func)
 Applies the functor to each each agent in the agent set. More...
 
template<typename Functor >
void apply (const Functor &func)
 Applies the functor to each each agent in the agent set. More...
 
T * at (int index)
 Gets the item at the specified index. More...
 
size_t count () const
 Gets the size of this AgentSet. More...
 
size_t size () const
 Gets the size of this AgentSet. More...
 
T * operator[] (size_t index)
 Gets the item at the specified index without doing any range checking. More...
 
as_iterator begin ()
 Gets an iterator to the begining of this AgentSet. More...
 
const_as_iterator begin () const
 Gets a const iterator to the begining of this AgentSet. More...
 
as_iterator end ()
 Gets an iterator to the end of this AgentSet. More...
 
const_as_iterator end () const
 Gets a const iterator to the end of this AgentSet. More...
 
void clear ()
 Clears this AgentSet of any agents that it contains.
 
template<typename ValueGetter >
T * minOneOf (const ValueGetter &getter)
 Gets the set member that has the minimum value of the number returned by ValueGetter. More...
 
template<typename ValueGetter >
T * maxOneOf (const ValueGetter &getter)
 Gets the set member that has the maximum value of the number returned by ValueGetter. More...
 
template<typename ValueGetter >
void withMin (const ValueGetter &getter, AgentSet< T > &set)
 Gets the set members that have the minimum value of the number returned by ValueGetter, and puts them in the specified set. More...
 
template<typename ValueGetter >
void withMax (const ValueGetter &getter, AgentSet< T > &set)
 Gets the set members that have the maximum value of the number returned by ValueGetter and puts them in the specified set. More...
 
template<typename ValueGetter >
void minNOf (size_t count, const ValueGetter &getter, AgentSet< T > &set, bool initialSetIsSorted=false)
 Gets count number of set members that have the minimum value of the number returned by ValueGetter. More...
 
template<typename ValueGetter >
void maxNOf (size_t count, const ValueGetter &getter, AgentSet< T > &set, bool initialSetIsSorted=false)
 
T * oneOf ()
 Gets one of the members of this AgentSet at random. More...
 
void remove (T *agent)
 Removes all instances of the specified agent from this AgentSet.
 
void shuffle ()
 Randomly shuffles the elements of this AgentSet.
 

Public Attributes

std::vector< T * > agents
 

Detailed Description

template<typename T>
class repast::relogo::AgentSet< T >

Specialized indexable collection class for agents.

This includes methods designed to call arbitrary code on the agents it contains.

Template Parameters
Tthe type of agent the AgentSet contains

Member Function Documentation

◆ apply() [1/2]

template<typename T >
template<typename Functor >
void repast::relogo::AgentSet< T >::apply ( const Functor func)

Applies the functor to each each agent in the agent set.

Template Parameters
Functoran object that implements operator()(T* agent);

◆ apply() [2/2]

template<typename T >
template<typename Functor >
void repast::relogo::AgentSet< T >::apply ( Functor func)

Applies the functor to each each agent in the agent set.

Template Parameters
Functoran object that implements operator()(T* agent);

◆ ask() [1/3]

template<typename T >
template<typename Functor >
void repast::relogo::AgentSet< T >::ask ( Functor  func)

Calls the Functor on each agent in this AgentSet.

Parameters
funca pointer to the method to call each member of the set
Template Parameters
Functorpointer to no-arg method belonging to the type of agent contained by this AgentSet.

◆ ask() [2/3]

template<typename T >
template<typename Functor , typename P1 >
void repast::relogo::AgentSet< T >::ask ( Functor  func,
const P1 &  p1 
)

Calls the Functor on each agent in this AgentSet, passing the specified argument.

Parameters
funca pointer to the method to call each member of the set
p1a reference to a P1 type that is passed to the called method
Template Parameters
Functorpointer to method belonging to the type of agent contained by this AgentSet.
P1the type of the method parameter

◆ ask() [3/3]

template<typename T >
template<typename Functor , typename P1 >
void repast::relogo::AgentSet< T >::ask ( Functor  func,
P1 &  p1 
)

Calls the Functor on each agent in this AgentSet, passing the specified argument.

Parameters
funca pointer to the method to call each member of the set
p1a reference to a P1 type that is passed to the called method
Template Parameters
Functorpointer to method belonging to the type of agent contained by this AgentSet.
P1the type of the method parameter

◆ at()

template<typename T >
T * repast::relogo::AgentSet< T >::at ( int  index)

Gets the item at the specified index.

Parameters
indexthe index of the agent to get
Returns
the agent at the specified index

◆ begin() [1/2]

template<typename T >
as_iterator repast::relogo::AgentSet< T >::begin ( )
inline

Gets an iterator to the begining of this AgentSet.

Returns
an iterator to the beginning of this AgentSet.

◆ begin() [2/2]

template<typename T >
const_as_iterator repast::relogo::AgentSet< T >::begin ( ) const
inline

Gets a const iterator to the begining of this AgentSet.

Returns
a const iterator to the beginning of this AgentSet.

◆ count()

template<typename T >
size_t repast::relogo::AgentSet< T >::count ( ) const
inline

Gets the size of this AgentSet.

Returns
the size of this AgentSet.

◆ end() [1/2]

template<typename T >
as_iterator repast::relogo::AgentSet< T >::end ( )
inline

Gets an iterator to the end of this AgentSet.

Returns
an iterator to the end of this AgentSet.

◆ end() [2/2]

template<typename T >
const_as_iterator repast::relogo::AgentSet< T >::end ( ) const
inline

Gets a const iterator to the end of this AgentSet.

Returns
a const iterator to the end of this AgentSet.

◆ maxNOf()

template<typename T >
template<typename ValueGetter >
void repast::relogo::AgentSet< T >::maxNOf ( size_t  count,
const ValueGetter &  getter,
AgentSet< T > &  set,
bool  initialSetIsSorted = false 
)
  Gets count number of set members that have the maximum value of
  the number returned by ValueGetter. If there are not enough
  to satisfy the count then members with the second lowest
  value are returned and so on.

  @param getter the ValueGetter to use in retreiving the
  value used in the max comparison

  @tparam ValueGetter a function or functor that takes a
  member of this agentset and returns a double value. This
  double value is used in the max comparison.
Parameters
initialSetIsSortedOptional performance parameter; if false (the default), a call to this function must sort an entire copy of the original set; if true, the function assumes the original set is already sorted. Useful if the same set is to be used repeatedly.

◆ maxOneOf()

template<typename T >
template<typename ValueGetter >
T * repast::relogo::AgentSet< T >::maxOneOf ( const ValueGetter &  getter)

Gets the set member that has the maximum value of the number returned by ValueGetter.

If more than one agent has the minimum value, then return one of those at random.

Parameters
getterthe ValueGetter to use in retreiving the value used in the max comparison
Template Parameters
ValueGettera function or functor that takes a member of this agentset and returns a double value. This double value is used in the max comparison.

◆ minNOf()

template<typename T >
template<typename ValueGetter >
void repast::relogo::AgentSet< T >::minNOf ( size_t  count,
const ValueGetter &  getter,
AgentSet< T > &  set,
bool  initialSetIsSorted = false 
)

Gets count number of set members that have the minimum value of the number returned by ValueGetter.

If there are not enough to satisfy the count then members with the second lowest value are returned and so on.

Parameters
getterthe ValueGetter to use in retreiving the value used in the min comparison
Template Parameters
ValueGettera function or functor that takes a member of this agentset and returns a double value. This double value is used in the min comparison.
Parameters
initialSetIsSortedOptional performance parameter; if false (the default), a call to this function must sort an entire copy of the original set; if true, the function assumes the original set is already sorted. Useful if the same set is to be used repeatedly.

◆ minOneOf()

template<typename T >
template<typename ValueGetter >
T * repast::relogo::AgentSet< T >::minOneOf ( const ValueGetter &  getter)

Gets the set member that has the minimum value of the number returned by ValueGetter.

If more than one agent has the minimum value, then return one of those at random.

Parameters
getterthe ValueGetter to use in retreiving the value used in the min comparison
Template Parameters
ValueGettera function or functor that takes a member of this agentset and returns a double value. This double value is used in the min comparison.

◆ oneOf()

template<typename T >
T * repast::relogo::AgentSet< T >::oneOf

Gets one of the members of this AgentSet at random.

If the set is empty, this returns 0.

◆ operator[]()

template<typename T >
T * repast::relogo::AgentSet< T >::operator[] ( size_t  index)

Gets the item at the specified index without doing any range checking.

Parameters
indexthe index of the agent to get
Returns
the agent at the specified index

◆ size()

template<typename T >
size_t repast::relogo::AgentSet< T >::size ( ) const
inline

Gets the size of this AgentSet.

Returns
the size of this AgentSet.

◆ withMax()

template<typename T >
template<typename ValueGetter >
void repast::relogo::AgentSet< T >::withMax ( const ValueGetter &  getter,
AgentSet< T > &  set 
)

Gets the set members that have the maximum value of the number returned by ValueGetter and puts them in the specified set.

Parameters
getterthe ValueGetter to use in retreiving the value used in the max comparison
Template Parameters
ValueGettera function or functor that takes a member of this agentset and returns a double value. This double value is used in the max comparison.

◆ withMin()

template<typename T >
template<typename ValueGetter >
void repast::relogo::AgentSet< T >::withMin ( const ValueGetter &  getter,
AgentSet< T > &  set 
)

Gets the set members that have the minimum value of the number returned by ValueGetter, and puts them in the specified set.

Parameters
getterthe ValueGetter to use in retreiving the value used in the min comparison
Template Parameters
ValueGettera function or functor that takes a member of this agentset and returns a double value. This double value is used in the min comparison.

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