RepastHPC  2.3.1
Context.h
1 /*
2  * Repast for High Performance Computing (Repast HPC)
3  *
4  * Copyright (c) 2010 Argonne National Laboratory
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with
8  * or without modification, are permitted provided that the following
9  * conditions are met:
10  *
11  * Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * Neither the name of the Argonne National Laboratory nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TRUSTEES OR
26  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  *
35  * Context.h
36  *
37  * Created on: May 22, 2009
38  * Author: nick
39  */
40 
41 #ifndef CONTEXT_H_
42 #define CONTEXT_H_
43 
44 #include <vector>
45 #include <set>
46 
47 #include <boost/unordered_map.hpp>
48 #include <boost/smart_ptr.hpp>
49 #include <boost/iterator/transform_iterator.hpp>
50 #include <boost/iterator/filter_iterator.hpp>
51 #include <boost/function.hpp>
52 
53 #include "AgentId.h"
54 #include "AgentRequest.h"
55 #include "Random.h"
56 #include "ValueLayer.h"
57 #include "Projection.h"
58 #include "RepastErrors.h"
59 
60 namespace repast {
61 
66 template<typename T>
67 struct SecondElement: public std::unary_function<typename boost::unordered_map<AgentId, boost::shared_ptr<T> >::value_type, boost::shared_ptr<T> > {
68  boost::shared_ptr<T> operator()(const typename boost::unordered_map<AgentId, boost::shared_ptr<T> >::value_type& value) const {
69  const boost::shared_ptr<T>& ptr = value.second;
70  return ptr;
71  }
72 };
73 
74 
81 template<typename T>
82 class Context {
83 
84 private:
85 
86  typedef typename std::vector<Projection<T>*>::iterator ProjPtrIter;
87  typedef typename boost::unordered_map<AgentId, boost::shared_ptr<T>, HashId> AgentMap;
88 
89  typedef typename AgentMap::iterator AgentMapIterator;
90  typedef typename AgentMap::const_iterator AgentMapConstIterator;
91 
92  AgentMap agents;
93  std::map<std::string, BaseValueLayer*> valueLayers;
94 
95 protected:
96  std::vector<Projection<T> *> projections;
97 
98 public:
99 
100  typedef typename boost::transform_iterator<SecondElement<T> , typename AgentMap::const_iterator> const_iterator;
101  typedef typename boost::filter_iterator<IsAgentType<T> , typename Context<T>::const_iterator> const_bytype_iterator;
102 
103  Context();
104 
108  virtual ~Context();
109 
126  T* addAgent(T* agent);
127 
135  virtual void addProjection(Projection<T>* projection);
136 
144  Projection<T>* getProjection(const std::string& name);
145 
151  void removeAgent(const AgentId id);
152 
156  void removeAgent(T* agent);
157 
163  T* getAgent(const AgentId& id);
164 
172  void getRandomAgents(const int count, std::vector<T*>& agents);
173 
181  const_iterator begin() const {
182  return const_iterator(agents.begin());
183  }
184 
192  const_iterator end() const {
193  return const_iterator(agents.end());
194  }
195 
205  const_bytype_iterator byTypeBegin(int typeId) const {
206  return const_bytype_iterator(IsAgentType<T> (typeId), Context<T>::begin(), Context<T>::end());
207  }
208 
218  const_bytype_iterator byTypeEnd(int typeId) const {
219  return const_bytype_iterator(IsAgentType<T> (typeId), Context<T>::end(), Context<T>::end());
220  }
221 
225  bool contains(const AgentId& id);
226 
230  int size() const {
231  return agents.size();
232  }
233 
239  void addValueLayer(BaseValueLayer* valueLayer);
240 
252  template<typename ValueType, typename Borders>
253  DiscreteValueLayer<ValueType, Borders>* getDiscreteValueLayer(const std::string& valueLayerName);
254 
266  template<typename ValueType, typename Borders>
267  ContinuousValueLayer<ValueType, Borders>* getContinuousValueLayer(const std::string& valueLayerName);
268 
292  template<typename filterStruct>
293  boost::filter_iterator<filterStruct, typename Context<T>::const_iterator> filteredBegin(const filterStruct& fStruct);
294 
318  template<typename filterStruct>
319  boost::filter_iterator<filterStruct, typename Context<T>::const_iterator> filteredEnd(const filterStruct& fStruct);
320 
321 
347  template<typename filterStruct>
348  boost::filter_iterator<filterStruct, typename Context<T>::const_bytype_iterator> byTypeFilteredBegin(const int type, const filterStruct& fStruct);
349 
375  template<typename filterStruct>
376  boost::filter_iterator<filterStruct, typename Context<T>::const_bytype_iterator> byTypeFilteredEnd(const int type, const filterStruct& fStruct);
377 
388  void selectAgents(std::set<T*>& selectedAgents, bool remove = false);
389 
400  void selectAgents(std::vector<T*>& selectedAgents, bool remove = false);
401 
417  void selectAgents(int count, std::set<T*>& selectedAgents, bool remove = false);
418 
434  void selectAgents(int count, std::vector<T*>& selectedAgents, bool remove = false);
435 
454  void selectAgents(std::set<T*>& selectedAgents, int type, bool remove = false, int popSize = -1);
455 
474  void selectAgents(std::vector<T*>& selectedAgents, int type, bool remove = false, int popSize = -1);
475 
499  void selectAgents(int count, std::set<T*>& selectedAgents, int type, bool remove = false, int popSize = -1);
500 
524  void selectAgents(int count, std::vector<T*>& selectedAgents, int type, bool remove = false, int popSize = -1);
525 
547  template<typename filterStruct>
548  void selectAgents(std::set<T*>& selectedAgents, filterStruct& filter, bool remove = false, int popSize = -1);
549 
571  template<typename filterStruct>
572  void selectAgents(std::vector<T*>& selectedAgents, filterStruct& filter, bool remove = false, int popSize = -1);
573 
600  template<typename filterStruct>
601  void selectAgents(int count, std::set<T*>& selectedAgents, filterStruct& filter, bool remove = false, int popSize = -1);
602 
629  template<typename filterStruct>
630  void selectAgents(int count, std::vector<T*>& selectedAgents, filterStruct& filter, bool remove = false, int popSize = -1);
631 
654  template<typename filterStruct>
655  void selectAgents(std::set<T*>& selectedAgents, int type, filterStruct& filter, bool remove = false, int popSize = -1);
656 
679  template<typename filterStruct>
680  void selectAgents(std::vector<T*>& selectedAgents, int type, filterStruct& filter, bool remove = false, int popSize = -1);
681 
709  template<typename filterStruct>
710  void selectAgents(int count, std::set<T*>& selectedAgents, int type, filterStruct& filter, bool remove = false, int popSize = -1);
711 
739  template<typename filterStruct>
740  void selectAgents(int count, std::vector<T*>& selectedAgents, int type, filterStruct& filter, bool remove = false, int popSize = -1);
741 
742 
743 
744  // BETA
801  void getProjectionInfo(AgentRequest req, std::map<std::string, std::vector<repast::ProjectionInfoPacket*> >& map,
802  bool secondaryInfo = false, std::set<AgentId>* secondaryIds = 0, int destProc = -1);
803 
810  void setProjectionInfo(std::map<std::string, std::vector<repast::ProjectionInfoPacket*> >& projInfo);
811 
812  void cleanProjectionInfo(std::set<AgentId>& agentsToKeep);
813 
814 };
815 
816 
817 
818 template<typename T>
819 Context<T>::Context() {
820 }
821 
822 template<typename T>
824  agents.erase(agents.begin(), agents.end());
825  for (ProjPtrIter iter = projections.begin(); iter != projections.end(); ++iter) {
826  Projection<T>* proj = *iter;
827  delete proj;
828  }
829  projections.clear();
830 
831  for (std::map<std::string, BaseValueLayer*>::iterator iter = valueLayers.begin(); iter != valueLayers.end(); ++iter) {
832  BaseValueLayer* layer = iter->second;
833  delete layer;
834  }
835  valueLayers.clear();
836 }
837 
838 template<typename T>
840  std::string name = projection->name();
841  for (ProjPtrIter iter = projections.begin(); iter != projections.end(); ++iter){
842  if(name.compare((*iter)->name()) == 0) throw Repast_Error_9(name); // Projection with specified name already in context
843  }
844  for (const_iterator iter = begin(); iter != end(); ++iter) {
845  projection->addAgent(*iter);
846  }
847  projections.push_back(projection);
848 }
849 
850 template<typename T>
851 Projection<T>* Context<T>::getProjection(const std::string& name) {
852  for (ProjPtrIter iter = projections.begin(); iter != projections.end(); ++iter) {
853  Projection<T>* proj = *iter;
854  if (proj->name() == name)
855  return proj;
856  }
857  return NULL;
858 }
859 
860 template<typename T>
862  AgentMapIterator iter = agents.find(id);
863  if (iter == agents.end()) return 0;
864  return iter->second.get();
865 }
866 
867 template<typename T>
868 void Context<T>::getRandomAgents(const int count, std::vector<T*>& agents) {
869  for (int i = 0; i < count; i++) {
871  bool found = false;
872  while (!found) {
873  const_iterator iter = begin();
874  for (int j = 0, n = rnd.next(); j < n; iter++, j++)
875  ;
876  T* agent = iter->get();
877  if (find(agents.begin(), agents.end(), agent) == agents.end()) {
878  agents.push_back(agent);
879  found = true;
880  }
881  }
882  }
883 }
884 
885 template<typename T>
886 T* Context<T>::addAgent(T* agent) {
887  const AgentId& id = agent->getId();
888  typename AgentMap::iterator findIter = agents.find(id);
889  if (findIter != agents.end()) return &*(findIter->second);
890 
891  boost::shared_ptr<T> ptr(agent);
892  agents[id] = ptr;
893 
894  for (ProjPtrIter iter = projections.begin(); iter != projections.end(); ++iter) {
895  Projection<T>* proj = *iter;
896  proj->addAgent(ptr);
897  }
898 
899  return agent;
900 }
901 
902 template<typename T>
903 void Context<T>::removeAgent(T* agent) {
904  removeAgent(agent->getId());
905 }
906 
907 template<typename T>
909  const AgentMapIterator iter = agents.find(id);
910  if (iter != agents.end()) {
911  boost::shared_ptr<T>& ptr = iter->second;
912  for (ProjPtrIter pIter = projections.begin(); pIter != projections.end(); ++pIter) {
913  Projection<T>* proj = *pIter;
914  proj->removeAgent(ptr.get());
915  }
916  agents.erase(iter);
917  }
918 }
919 
920 template<typename T>
921 bool Context<T>::contains(const AgentId& id) {
922  return agents.find(id) != agents.end();
923 }
924 
925 template<typename T>
927  valueLayers[layer->name()] = layer;
928 }
929 
930 template<typename T>
931 template<typename ValueType, typename Borders>
933 
934  std::map<std::string, BaseValueLayer*>::iterator iter = valueLayers.find(valueLayerName);
935  if (iter == valueLayers.end())
936  return 0;
937  return static_cast<DiscreteValueLayer<ValueType, Borders>*> (iter->second);
938 }
939 
940 template<typename T>
941 template<typename ValueType, typename Borders>
943 
944  std::map<std::string, BaseValueLayer*>::iterator iter = valueLayers.find(valueLayerName);
945  if (iter == valueLayers.end())
946  return 0;
947  return static_cast<ContinuousValueLayer<ValueType, Borders>*> (iter->second);
948 }
949 
950 
951 
952 
953 template<typename T>
954 template<typename filterStruct>
955 boost::filter_iterator<filterStruct, typename Context<T>::const_iterator> Context<T>::filteredBegin(const filterStruct& fStruct){
956  return boost::filter_iterator<filterStruct , typename Context<T>::const_iterator> (fStruct, Context<T>::begin(), Context<T>::end());
957 }
958 
959 template<typename T>
960 template<typename filterStruct>
961 boost::filter_iterator<filterStruct, typename Context<T>::const_iterator> Context<T>::filteredEnd(const filterStruct& fStruct){
962  return boost::filter_iterator<filterStruct , typename Context<T>::const_iterator> (fStruct, Context<T>::end(), Context<T>::end());
963 }
964 
965 
966 template<typename T>
967 template<typename filterStruct>
968 boost::filter_iterator<filterStruct, typename Context<T>::const_bytype_iterator> Context<T>::byTypeFilteredBegin(const int type, const filterStruct& fStruct){
969  return boost::filter_iterator<filterStruct , typename Context<T>::const_bytype_iterator> (fStruct, Context<T>::byTypeBegin(type), Context<T>::byTypeEnd(type));
970 }
971 
972 template<typename T>
973 template<typename filterStruct>
974 boost::filter_iterator<filterStruct, typename Context<T>::const_bytype_iterator> Context<T>::byTypeFilteredEnd(const int type, const filterStruct& fStruct){
975  return boost::filter_iterator<filterStruct , typename Context<T>::const_bytype_iterator> (fStruct, Context<T>::byTypeEnd(type), Context<T>::byTypeEnd(type));
976 }
977 
978 
979 
980 
981 
982 
983  /* ****************************** */
984 
985 // Selection
986 
987 template<typename T>
988 void Context<T>::selectAgents(std::set<T*>& selectedAgents, bool remove){
989  selectNElementsAtRandom(begin(), size(), size(), selectedAgents, remove);
990 }
991 
992 template<typename T>
993 void Context<T>::selectAgents(std::vector<T*>& selectedAgents, bool remove){
994  selectNElementsInRandomOrder(begin(), size(), size(), selectedAgents, remove);
995 }
996 
997 template<typename T>
998 void Context<T>::selectAgents(int count, std::set<T*>& selectedAgents, bool remove){
999  selectNElementsAtRandom(begin(), size(), count, selectedAgents, remove);
1000 }
1001 
1002 template<typename T>
1003 void Context<T>::selectAgents(int count, std::vector<T*>& selectedAgents, bool remove){
1004  selectNElementsInRandomOrder(begin(), end(), count, selectedAgents, remove);
1005 }
1006 
1007 template<typename T>
1008 void Context<T>::selectAgents(std::set<T*>& selectedAgents, int type, bool remove, int popSize){
1009  if(popSize <= -1) selectNElementsAtRandom(byTypeBegin(type), byTypeEnd(type), size(), selectedAgents, remove);
1010  else selectNElementsAtRandom(byTypeBegin(type), popSize, size(), selectedAgents, remove);
1011 }
1012 
1013 template<typename T>
1014 void Context<T>::selectAgents(std::vector<T*>& selectedAgents, int type, bool remove, int popSize){
1015  if(popSize <= -1) selectNElementsInRandomOrder(byTypeBegin(type), byTypeEnd(type), size(), selectedAgents, remove);
1016  else selectNElementsInRandomOrder(byTypeBegin(type), popSize, size(), selectedAgents, remove);
1017 }
1018 
1019 template<typename T>
1020 void Context<T>::selectAgents(int count, std::set<T*>& selectedAgents, int type, bool remove, int popSize){
1021  if(popSize <= -1) selectNElementsAtRandom(byTypeBegin(type), byTypeEnd(type), count, selectedAgents, remove);
1022  else selectNElementsAtRandom(byTypeBegin(type), popSize, count, selectedAgents, remove);
1023 }
1024 
1025 template<typename T>
1026 void Context<T>::selectAgents(int count, std::vector<T*>& selectedAgents, int type, bool remove, int popSize){
1027  if(popSize <= -1) selectNElementsInRandomOrder(byTypeBegin(type), byTypeEnd(type), count, selectedAgents, remove);
1028  else selectNElementsInRandomOrder(byTypeBegin(type), popSize, count, selectedAgents, remove);
1029 }
1030 
1031 template<typename T>
1032 template<typename filterStruct>
1033 void Context<T>::selectAgents(std::set<T*>& selectedAgents, filterStruct& filter, bool remove, int popSize){
1034  if(popSize <= -1) selectNElementsAtRandom(filteredBegin<filterStruct>(filter), filteredEnd<filterStruct>(filter), size(), selectedAgents, remove);
1035  else selectNElementsAtRandom(filteredBegin<filterStruct>(filter), popSize, size(), selectedAgents, remove);
1036 }
1037 
1038 template<typename T>
1039 template<typename filterStruct>
1040 void Context<T>::selectAgents(std::vector<T*>& selectedAgents, filterStruct& filter, bool remove, int popSize){
1041  if(popSize <= -1) selectNElementsInRandomOrder(filteredBegin(filter), filteredEnd(filter), size(), selectedAgents, remove);
1042  else selectNElementsInRandomOrder(filteredBegin(filter), popSize, size(), selectedAgents, remove);
1043 }
1044 
1045 template<typename T>
1046 template<typename filterStruct>
1047 void Context<T>::selectAgents(int count, std::set<T*>& selectedAgents, filterStruct& filter, bool remove, int popSize){
1048  if(popSize <= -1) selectNElementsAtRandom(filteredBegin<filterStruct>(filter), filteredEnd<filterStruct>(filter), count, selectedAgents, remove);
1049  else selectNElementsAtRandom(filteredBegin<filterStruct>(filter), popSize, count, selectedAgents, remove);
1050 }
1051 
1052 template<typename T>
1053 template<typename filterStruct>
1054 void Context<T>::selectAgents(int count, std::vector<T*>& selectedAgents, filterStruct& filter, bool remove, int popSize){
1055  if(popSize <= -1) selectNElementsInRandomOrder(filteredBegin(filter), filteredEnd(filter), count, selectedAgents, remove);
1056  else selectNElementsInRandomOrder(filteredBegin(filter), popSize, count, selectedAgents, remove);
1057 }
1058 
1059 template<typename T>
1060 template<typename filterStruct>
1061 void Context<T>::selectAgents(std::set<T*>& selectedAgents, int type, filterStruct& filter, bool remove, int popSize){
1062  if(popSize <= -1) selectNElementsAtRandom(byTypeFilteredBegin(type, filter), byTypeFilteredEnd(type, filter), size(), selectedAgents, remove);
1063  else selectNElementsAtRandom(byTypeFilteredBegin(type, filter), popSize, size(), selectedAgents, remove);
1064 }
1065 
1066 template<typename T>
1067 template<typename filterStruct>
1068 void Context<T>::selectAgents(std::vector<T*>& selectedAgents, int type, filterStruct& filter, bool remove, int popSize){
1069  if(popSize <= -1) selectNElementsInRandomOrder(byTypeFilteredBegin(type, filter), byTypeFilteredEnd(type, filter), size(), selectedAgents, remove);
1070  else selectNElementsInRandomOrder(byTypeFilteredBegin(type, filter), popSize, size(), selectedAgents, remove);
1071 }
1072 
1073 template<typename T>
1074 template<typename filterStruct>
1075 void Context<T>::selectAgents(int count, std::set<T*>& selectedAgents, int type, filterStruct& filter, bool remove, int popSize){
1076  if(popSize <= -1) selectNElementsAtRandom(byTypeFilteredBegin(type, filter), byTypeFilteredEnd(type, filter), count, selectedAgents, remove);
1077  else selectNElementsAtRandom(byTypeFilteredBegin(type, filter), popSize, count, selectedAgents, remove);
1078 }
1079 
1080 template<typename T>
1081 template<typename filterStruct>
1082 void Context<T>::selectAgents(int count, std::vector<T*>& selectedAgents, int type, filterStruct& filter, bool remove, int popSize){
1083  if(popSize <= -1) selectNElementsInRandomOrder(byTypeFilteredBegin(type, filter), byTypeFilteredEnd(type, filter), count, selectedAgents, remove);
1084  else selectNElementsInRandomOrder(byTypeFilteredBegin(type, filter), popSize, count, selectedAgents, remove);
1085 }
1086 
1087 
1088 // Beta
1089 
1090 template<typename T>
1091 void Context<T>::getProjectionInfo(AgentRequest req, std::map<std::string, std::vector<repast::ProjectionInfoPacket*> >& map,
1092  bool secondaryInfo, std::set<AgentId>* secondaryIds, int destProc){
1093  std::vector<AgentId> ids = req.requestedAgents();
1094  for(typename std::vector<Projection<T> *>::iterator iter = projections.begin(), iterEnd = projections.end(); iter != iterEnd; iter++){
1095  std::string projName = (*iter)->name();
1096  map[projName] = std::vector<repast::ProjectionInfoPacket*>(); // New, then inserted into collection
1097  (*iter)->getProjectionInfo(ids, map[projName], secondaryInfo, secondaryIds, destProc);
1098  }
1099 }
1100 
1101 template<typename T>
1102 void Context<T>::setProjectionInfo(std::map<std::string, std::vector<repast::ProjectionInfoPacket*> >& projInfo){
1103  for(std::map<std::string, std::vector<repast::ProjectionInfoPacket*> >::iterator iter = projInfo.begin(), iterEnd = projInfo.end(); iter != iterEnd; iter++)
1104  getProjection(iter->first)->updateProjectionInfo(iter->second, this);
1105 }
1106 
1107 template<typename T>
1108 void Context<T>::cleanProjectionInfo(std::set<AgentId>& agentsToKeep){
1109  for(typename std::vector<Projection<T> *>::iterator iter = projections.begin(), iterEnd = projections.end(); iter != iterEnd; iter++){
1110  (*iter)->cleanProjectionInfo(agentsToKeep);
1111  }
1112 }
1113 
1114 }
1115 #endif /* CONTEXT_H_ */
repast::Context::addAgent
T * addAgent(T *agent)
Adds the agent to the context.
Definition: Context.h:886
repast::Context
Collection of agents of type T with set semantics.
Definition: Context.h:82
repast::BaseValueLayer::name
std::string name() const
Gets the value layer's name.
Definition: ValueLayer.h:76
repast::Context::removeAgent
void removeAgent(const AgentId id)
Removes the specified agent from this context.
Definition: Context.h:908
repast::Context::selectAgents
void selectAgents(std::set< T * > &selectedAgents, bool remove=false)
Gets a set of pointers to all agents in this context.
Definition: Context.h:988
repast::Context::getProjection
Projection< T > * getProjection(const std::string &name)
Get the named Projection.
Definition: Context.h:851
repast::Random::instance
static Random * instance()
Gets the singleton instance of this Random.
Definition: Random.cpp:80
repast::Context::byTypeFilteredEnd
boost::filter_iterator< filterStruct, typename Context< T >::const_bytype_iterator > byTypeFilteredEnd(const int type, const filterStruct &fStruct)
Creates a filtered iterator over the set of agents in this context of the specified type (per their A...
Definition: Context.h:974
repast::DefaultNumberGenerator
Adapts the templated boost::variate_generator to the NumberGenerator interface.
Definition: Random.h:97
repast::AgentId
Agent identity information.
Definition: AgentId.h:60
repast::Context::getAgent
T * getAgent(const AgentId &id)
Gets the specified agent.
Definition: Context.h:861
repast::Context::byTypeEnd
const_bytype_iterator byTypeEnd(int typeId) const
Gets the end of an iterator over agents in this context of the specified type.
Definition: Context.h:218
repast::Context::addValueLayer
void addValueLayer(BaseValueLayer *valueLayer)
Adds a value layer to this context.
Definition: Context.h:926
repast::IsAgentType
Struct that allows filtering by Agent Type.
Definition: AgentId.h:232
repast::Context::setProjectionInfo
void setProjectionInfo(std::map< std::string, std::vector< repast::ProjectionInfoPacket * > > &projInfo)
Sets the projection information as specified.
Definition: Context.h:1102
repast::Context::getContinuousValueLayer
ContinuousValueLayer< ValueType, Borders > * getContinuousValueLayer(const std::string &valueLayerName)
Gets the named continuous value layer from this Context.
Definition: Context.h:942
repast::SecondElement
Unary function used in the transform_iterator that allows context iterators to return the agent maps ...
Definition: Context.h:67
repast::Projection
Abstract base class for all Projections.
Definition: Projection.h:125
repast::Context::getProjectionInfo
void getProjectionInfo(AgentRequest req, std::map< std::string, std::vector< repast::ProjectionInfoPacket * > > &map, bool secondaryInfo=false, std::set< AgentId > *secondaryIds=0, int destProc=-1)
Gets the projection information for all projections in this context, for all agents whose IDs are lis...
Definition: Context.h:1091
repast::Context::addProjection
virtual void addProjection(Projection< T > *projection)
Adds the specified projection to this context.
Definition: Context.h:839
repast::DiscreteValueLayer
Creates ValueLayer whose location coordinates are ints.
Definition: ValueLayer.h:197
repast::ContinuousValueLayer
Continous value layer whose location coordinates are double.
Definition: ValueLayer.h:327
repast::Context::end
const_iterator end() const
Gets the end of an iterator over the agents in this context.
Definition: Context.h:192
repast::Context::byTypeFilteredBegin
boost::filter_iterator< filterStruct, typename Context< T >::const_bytype_iterator > byTypeFilteredBegin(const int type, const filterStruct &fStruct)
Creates a filtered iterator over the set of agents in this context of the specified type (per their A...
Definition: Context.h:968
repast::Context::getRandomAgents
void getRandomAgents(const int count, std::vector< T * > &agents)
Gets at random the specified count of agents and returns them in the agents vector.
Definition: Context.h:868
repast::Context::~Context
virtual ~Context()
Destroys this context and the projections it contains.
Definition: Context.h:823
repast::Context::size
int size() const
Gets the size (number of agents) in this context.
Definition: Context.h:230
repast::AgentRequest
Encapsulates a request made by one process for agents in another.
Definition: AgentRequest.h:59
repast::DefaultNumberGenerator::next
double next()
Gets the "next" number from this Number Generator.
Definition: Random.h:113
repast::Context::getDiscreteValueLayer
DiscreteValueLayer< ValueType, Borders > * getDiscreteValueLayer(const std::string &valueLayerName)
Gets the named discrete value layer from this Context.
Definition: Context.h:932
repast::Context::filteredEnd
boost::filter_iterator< filterStruct, typename Context< T >::const_iterator > filteredEnd(const filterStruct &fStruct)
Creates a filtered iterator over the set of agents in this context and returns it with a value equal ...
Definition: Context.h:961
repast::Context::filteredBegin
boost::filter_iterator< filterStruct, typename Context< T >::const_iterator > filteredBegin(const filterStruct &fStruct)
Definition: Context.h:955
repast::Context::byTypeBegin
const_bytype_iterator byTypeBegin(int typeId) const
Gets the start of an iterator over agents in this context of the specified type.
Definition: Context.h:205
repast::Context::contains
bool contains(const AgentId &id)
Returns true if the specified agent is in this context, otherwise false.
Definition: Context.h:921
repast::HashId
operator() implementation that returns the hashcode of an AgentId.
Definition: AgentId.h:185
repast::Random::createUniIntGenerator
IntUniformGenerator createUniIntGenerator(int from, int to)
Creates a generator that produces ints in the range [from, to].
Definition: Random.cpp:100
repast::BaseValueLayer
Base implementation of a ValueLayer.
Definition: ValueLayer.h:58
repast::Projection::name
const std::string name() const
Gets the name of this projection.
Definition: Projection.h:164
repast::AgentRequest::requestedAgents
const std::vector< AgentId > & requestedAgents() const
Gets a reference to the vector of requested agents.
Definition: AgentRequest.h:136
repast::Context::begin
const_iterator begin() const
Gets the start of iterator over the agents in this context.
Definition: Context.h:181