RepastHPC  2.3.1
SimulationRunner.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  * SimulationRunner.h
36  *
37  * Created on: Sep 17, 2010
38  * Author: nick
39  */
40 
41 #ifndef SIMULATIONRUNNER_H_
42 #define SIMULATIONRUNNER_H_
43 
44 #include <vector>
45 
46 #include <boost/mpi/communicator.hpp>
47 
48 #include "boost/algorithm/string/split.hpp"
49 #include "boost/algorithm/string/classification.hpp"
50 
51 #include "repast_hpc/Properties.h"
52 #include "repast_hpc/RepastProcess.h"
53 
54 #include "RelogoLink.h"
55 #include "WorldCreator.h"
56 #include "WorldDefinition.h"
57 
58 namespace repast {
59 
60 namespace relogo {
61 
62 using namespace boost;
63 using namespace boost::algorithm;
64 
69 protected:
70  boost::mpi::communicator* comm;
71 
72 public:
76  SimulationRunner(boost::mpi::communicator* communicator): comm(communicator) {}
77 
105  template<typename ObserverType, typename PatchType>
106  void run(Properties& props);
107 };
108 
109 template<typename ObserverType, typename PatchType>
111  int minX = strToInt(props.getProperty("min.x"));
112  int minY = strToInt(props.getProperty("min.y"));
113  int maxX = strToInt(props.getProperty("max.x"));
114  int maxY = strToInt(props.getProperty("max.y"));
115  int buffer = strToInt(props.getProperty("grid.buffer"));
116 
117  bool worldIsWrapped = true;
118  if(props.contains("non.toroidal")) worldIsWrapped = false;
119 
121 
122  WorldDefinition def(minX, minY, maxX, maxY, worldIsWrapped, buffer);
123 
124  // Networks
125  if(props.contains("DirectedNetworks")){
126  std::string netList = props.getProperty("DirectedNetworks");
127  std::vector<std::string> directedNetworks;
128  split(directedNetworks, netList, boost::is_any_of(" ,"), boost::token_compress_on);
129  for(unsigned int i = 0; i < directedNetworks.size(); i++){
130  if(directedNetworks[i].compare("default") == 0) def.defineNetwork(true, &rlcm);
131  else def.defineNetwork(directedNetworks[i], true, &rlcm);
132  }
133  }
134 
135  if(props.contains("UndirectedNetworks")){
136  std::string netList = props.getProperty("UndirectedNetworks");
137  std::vector<std::string> undirectedNetworks;
138  split(undirectedNetworks, netList, boost::is_any_of(" ,"), boost::token_compress_on);
139  for(unsigned int i = 0; i < undirectedNetworks.size(); i++){
140  if(undirectedNetworks[i].compare("default") == 0) def.defineNetwork(false, &rlcm);
141  else def.defineNetwork(undirectedNetworks[i], false, &rlcm);
142  }
143  }
144 
145  int processesPerX = strToInt(props.getProperty("proc.per.x"));
146  int processesPerY = strToInt(props.getProperty("proc.per.y"));
147  std::vector<int> procsPerDim;
148  procsPerDim.push_back(processesPerX);
149  procsPerDim.push_back(processesPerY);
150 
151  WorldCreator creator(comm);
152  ObserverType* obs = creator.createWorld<ObserverType, PatchType> (def, procsPerDim);
153  obs->_setup(props);
155  delete obs;
156 }
157 
158 }
159 
160 }
161 
162 #endif /* SIMULATIONRUNNER_H_ */
repast::relogo::SimulationRunner::SimulationRunner
SimulationRunner(boost::mpi::communicator *communicator)
Creates a SimulationRunner.
Definition: SimulationRunner.h:76
repast::relogo::WorldDefinition::defineNetwork
void defineNetwork(std::string name, bool directed, RelogoLinkContentManager *rlcm)
Defines a network with the specified name and whether or not the network is directed.
Definition: WorldDefinition.cpp:61
repast::RepastProcess::getScheduleRunner
ScheduleRunner & getScheduleRunner()
Gets the ScheduleRunner used by this RepastProcess.
Definition: RepastProcess.h:401
repast::relogo::SimulationRunner::run
void run(Properties &props)
Creates and runs the simulation using the properties defined in props.
Definition: SimulationRunner.h:110
repast::Properties::contains
bool contains(const std::string &key) const
Gets whether or not this Properties contains the specified key.
Definition: Properties.cpp:86
repast::relogo::SimulationRunner
Runs a Relogo simulation.
Definition: SimulationRunner.h:68
repast::relogo::WorldCreator
Creates a the relogo world given some parameters.
Definition: WorldCreator.h:65
repast::ScheduleRunner::run
void run()
Starts and runs the simulation schedule.
Definition: Schedule.cpp:182
repast::relogo::WorldDefinition
Defines a Relogo world.
Definition: WorldDefinition.h:61
repast::RepastProcess::instance
static RepastProcess * instance()
Gets this RepastProcess.
Definition: RepastProcess.cpp:126
repast::Properties::getProperty
std::string getProperty(const std::string &key) const
Gets the property with the specified key.
Definition: Properties.cpp:90
repast::relogo::WorldCreator::createWorld
ObsType * createWorld(const WorldDefinition &worldDef, const std::vector< int > &pConfig, PatchCreator &patchCreator)
Creates the Relogo world using the specified parameters and returns an Observer of ObsType.
Definition: WorldCreator.h:116
repast::Properties
Map type object that contains key, value(string) properties.
Definition: Properties.h:77