31 using boost::property_tree::ptree;
36 ParameterExploration::ParameterExploration(
const string& name,
37 const ptree& original,
const ptree& preferences)
38 : Exploration(name, preferences), m_original(original)
42 ParameterExploration::ParameterExploration(
const ptree& pt)
49 :
Exploration(other.m_name, other.m_preferences), m_original(other.m_original)
51 for (
const auto& pair : other.m_sweeps) {
52 m_sweeps.push_back(make_pair(pair.first, pair.second->Clone()));
61 m_original = other.m_original;
63 for (
const auto &pair : m_sweeps) {
68 for (
const auto &pair : other.m_sweeps) {
69 m_sweeps.push_back(make_pair(pair.first, pair.second->Clone()));
78 for (
const auto &pair : m_sweeps) {
90 vector<string> parameters;
91 for (
auto pair : m_sweeps) {
92 parameters.push_back(pair.first);
101 vector<string> values(m_sweeps.size());
103 unsigned int i = m_sweeps.size();
104 for (
auto it = m_sweeps.rbegin(); it != m_sweeps.rend(); it++) {
105 ISweep* sweep = it->second;
108 values[--i] = sweep->
GetValue(index % nrOfValues);
117 unsigned int tasks = 1;
118 for (
auto pair : m_sweeps) {
119 tasks *= pair.second->GetNumberOfValues();
130 vector<string> parameterValues =
GetValues(index);
133 ptree pt(m_original);
134 auto& parameter_pt = pt.get_child(
"vleaf2.parameters");
135 auto value_it = parameterValues.begin();
136 for (
auto it = m_sweeps.begin(); it != m_sweeps.end(); it++) {
141 return new SimTask(index, pt, m_preferences, m_name);
146 vector<string> parameters;
148 parameters.push_back(pair.first);
160 auto entry = find_if(m_sweeps.begin(), m_sweeps.end(),
161 [parameter](
const pair<string, ISweep*>& pair) {
return pair.first == parameter;});
162 if (entry != m_sweeps.end()) {
163 return entry->second;
171 assert(sweep !=
nullptr &&
"The sweep wasn't initialized.");
172 assert(sweep->
GetNumberOfValues() > 0 &&
"The sweep doesn't contain any value.");
175 m_sweeps.push_back(make_pair(parameter, sweep));
180 auto entry = find_if(m_sweeps.begin(), m_sweeps.end(),
181 [parameter](
const pair<string, ISweep*>& pair) {
return pair.first == parameter;});
182 if (entry != m_sweeps.end()) {
183 delete entry->second;
184 m_sweeps.erase(entry);
191 pt.put_child(
"original", m_original);
193 for (
const auto& entry : m_sweeps) {
195 sweep_pt.put(
"parameter", entry.first);
196 for (
auto pair : entry.second->ToPtree()) {
197 sweep_pt.push_back(pair);
199 pt.add_child(
"sweeps.sweep", sweep_pt);
205 void ParameterExploration::ReadPtree(
const boost::property_tree::ptree& pt)
207 m_original = pt.get_child(
"original");
209 for (
const auto& pair : m_sweeps) {
214 const auto &sweeps_pt = pt.get_child_optional(
"sweeps");
216 for (
const auto& pair : sweeps_pt.get()) {
217 assert(pair.first ==
"sweep" &&
"Found ptree in sweeps with that isn't a sweep");
218 if (pair.first !=
"sweep") {
222 const auto &sweep_pt = pair.second;
223 string parameter = sweep_pt.get<
string>(
"parameter");
225 if (sweep_pt.find(
"list") != sweep_pt.not_found()) {
226 m_sweeps.push_back(make_pair(parameter,
new ListSweep(sweep_pt)));
228 else if (sweep_pt.find(
"range") != sweep_pt.not_found()) {
229 m_sweeps.push_back(make_pair(parameter,
new RangeSweep(sweep_pt)));
232 assert(
false &&
"The sweep must be a list or range sweep.");
virtual std::vector< std::string > GetPossibleParameters() const
Returns all the possible parameters for the exploration.
Interface for Exploration.
static const boost::property_tree::ptree & GetIndexedChild(const boost::property_tree::ptree &pt, const std::string &path)
Returns a reference to the subptree in the given ptree, taking indexes of array-elements (of PTreeUti...
virtual unsigned int GetNumberOfTasks() const
Returns the number of tasks the exploration currently contains.
const ISweep * GetSweep(const std::string ¶meter) const
Returns the sweep associated with the given parameter.
A collection of functions for manipulating the structure of ptrees.
ParameterExploration(const std::string &name, const boost::property_tree::ptree &original, const boost::property_tree::ptree &preferences)
Constructor.
virtual std::string GetValue(unsigned int index) const =0
Returns the value on the given index.
static void PutIndexedChild(boost::property_tree::ptree &pt, const std::string &path, const boost::property_tree::ptree &child)
Put the child in the given ptree on the given path.
An interface class for a parameter sweep.
virtual boost::property_tree::ptree ToPtree() const
Convert the exploration to a ptree.
static std::list< std::pair< std::string, std::string > > Flatten(const boost::property_tree::ptree &pt, bool indexedArray=false, const std::string &path="")
Flattens a ptree from a given path.
virtual std::vector< std::string > GetParameters() const
Returns all the parameters in the exploration.
Interface for RangeSweep.
virtual boost::property_tree::ptree ToPtree() const
Convert the exploration to a ptree.
void SetSweep(const std::string ¶meter, ISweep *sweep)
Set a sweep for the given parameter.
virtual unsigned int GetNumberOfValues() const =0
Returns the number of values in the sweep.
Exploration & operator=(const Exploration &other)
Assignment operator.
virtual std::vector< std::string > GetValues(unsigned int index) const
Return the values of a certain task.
virtual ~ParameterExploration()
Destructor.
ParameterExploration & operator=(const ParameterExploration &other)
Assignment operator.
Namespace for SimPT parameter explorer package.
virtual SimTask * CreateTask(unsigned int index) const
Creates a task with the parameters on the given index.
Contains all information needed for a transmitable simulation task.
std::string GetOriginalValue(const std::string ¶meter) const
Returns the original value of the parameter.
Class describing a parameter exploration and its simulation tasks.
Class describing a generic exploration.
void RemoveSweep(const std::string ¶meter)
Removes the sweep (if any) for the given parameter.
Interface for ParameterExploration.
virtual ParameterExploration * Clone() const
Clone function.