31 using boost::property_tree::ptree;
35 const unsigned int ExplorationProgress::g_max_tries;
38 : m_exploration(exploration), m_tasks(m_exploration->GetNumberOfTasks())
40 assert(exploration !=
nullptr &&
"The given exploration isn't initialized.");
42 m_task_counts[TaskState::Waiting] = m_tasks.size();
43 for (
unsigned int i = 0; i < m_tasks.size(); ++i) {
44 m_send_queue.push_back(i);
49 : m_exploration(nullptr)
61 assert(
id < m_tasks.size() &&
"This task doesn't exist.");
62 assert(m_tasks[
id].GetState() == TaskState::Waiting &&
"This task isn't in a 'Waiting' state.");
64 m_send_queue.remove(
id);
70 m_task_counts[state] += 1;
79 assert(id < m_exploration->GetNumberOfTasks() &&
"Id/Index out of bounds");
86 auto found = m_task_counts.find(state);
88 if (found == m_task_counts.end()) {
100 unsigned int id = task->
GetId();
101 ChangeState(m_tasks[
id], TaskState::Waiting);
102 m_running_tasks.remove(
id);
103 m_send_queue.push_front(
id);
113 case SimResult::ResultType::Success:
119 case SimResult::ResultType::Failure:
121 m_send_queue.push_back(result.
GetTaskId());
122 ChangeState(taskInfo, TaskState::Waiting);
129 case SimResult::ResultType::Stopped:
137 return m_send_queue.empty() && m_running_tasks.empty();
142 if (m_send_queue.size() == 0)
145 unsigned int id = m_send_queue.front();
146 m_send_queue.pop_front();
147 m_running_tasks.push_back(
id);
155 void ExplorationProgress::ReadPtree(
const ptree& pt)
157 delete m_exploration;
159 m_exploration =
nullptr;
160 if (pt.find(
"parameter_exploration") != pt.not_found()) {
162 }
else if (pt.find(
"file_exploration") != pt.not_found()) {
163 m_exploration =
new FileExploration(pt.get_child(
"file_exploration"));
165 assert(
false &&
"Exploration type unknown.");
168 ptree tasks_pt = pt.get_child(
"tasks");
169 m_tasks = std::vector<ExplorationTask>(tasks_pt.size());
170 m_task_counts.clear();
173 for (
const auto& pair : tasks_pt) {
174 ExplorationTask task(pair.second);
177 m_task_counts[task.
GetState()] += 1;
180 m_running_tasks.push_back(i);
185 m_send_queue.clear();
186 const auto &send_queue_pt = pt.get_child_optional(
"send_queue");
188 for (
const auto& pair : send_queue_pt.get()) {
189 m_send_queue.push_back(pair.second.get_value<
unsigned int>());
196 assert(
id < m_tasks.size() &&
"This task doesn't exist.");
197 assert(m_tasks[
id].GetState() ==
TaskState::Cancelled &&
"This task isn't in a 'Cancelled' state.");
199 m_send_queue.push_back(
id);
200 ChangeState(m_tasks[
id], TaskState::Waiting);
207 if (dynamic_cast<const ParameterExploration*>(m_exploration) !=
nullptr) {
208 pt.put_child(
"parameter_exploration", m_exploration->
ToPtree());
209 }
else if (dynamic_cast<const FileExploration*>(m_exploration) !=
nullptr) {
210 pt.put_child(
"file_exploration", m_exploration->
ToPtree());
212 assert(
false &&
"Exploration type unknown.");
216 pt.add_child(
"tasks.task", task.
ToPtree());
218 for (
unsigned int task_id : m_send_queue) {
219 pt.add(
"send_queue.task_id", task_id);
TaskState
Enumeration describing the state of a single task of the exploration.
void IncrementTries()
Increment the tries of running the task.
bool IsFinished() const
Return true if the exploration has finished.
Interface for Exploration.
The task is waiting to be sent for the first time.
TaskState GetState() const
Gets the state of the task.
ExplorationProgress(const Exploration *exploration)
Constructor.
boost::property_tree::ptree ToPtree() const
Convert the task to a ptree.
Interface for ExplorationTask.
A container class for the final result of a simulation.
The task is being executed.
unsigned int GetNumberOfTries() const
Returns the number of tries.
std::string GetNodeIP() const
Returns the IP of the node that has the result.
boost::property_tree::ptree ToPtree() const
Convert the exploration and progress to a ptree.
void GiveBack(const SimTask *task)
Give a task back to exploration (when it could not have been sent).
int GetTaskId() const
Return the id of the finished task.
ResultType GetResult() const
Check if the simulation was successfully completed.
void ResendCancelledTask(unsigned int id)
Resends a cancelled task.
void Updated()
Signal called when Exploration has changed.
virtual boost::property_tree::ptree ToPtree() const
Convert the exploration to a ptree.
virtual SimTask * CreateTask(unsigned int index) const =0
Creates a task with the parameters on the given index.
unsigned int GetTaskCount(const TaskState &state) const
Returns the number of tasks with the specified state.
virtual ~ExplorationProgress()
Destructor.
void HandleResult(const SimResult &result)
Handles the result of a simulation task.
void ChangeState(const TaskState &state)
Change the state of the task.
SimTask * NextTask()
Return the next task ready to be simulated.
Contains information about task in an exploration.
const ExplorationTask & GetTask(unsigned int id) const
Returns the state of the task with the specified id.
Namespace for SimPT parameter explorer package.
Contains all information needed for a transmitable simulation task.
Class describing a parameter exploration and its simulation tasks.
int GetId() const
Get the id of the task in the exploration.
Class describing a generic exploration.
int GetNodePort() const
Returns the Port of the TCP server of the node that has the result.
Interface for ParameterExploration.
Interface for ExplorationProgress.
void CancelWaitingTask(unsigned int id)
Cancels a waiting task.
The task was cancelled or stopped.
Interface for FileExploration.