27 #include <Qontrol/Model/GenericModel.hpp>
28 #include <Qontrol/Tasks/GenericTask.hpp>
29 #include <Qontrol/Problem/ControlOutput.hpp>
42 template <Qontrol::ControlOutput output>
class TaskSet {
44 TaskSet(std::shared_ptr<Model::GenericModel> model_library)
45 : model_ptr_{model_library} {
56 std::shared_ptr<Task::GenericTask>
add(std::string task_name,
int task_dimension,
57 double task_weight = 1.0) {
58 if (!
exist(task_name)) {
59 auto base_task_ptr = std::make_shared<Task::GenericTask>(
60 task_name, task_dimension, model_ptr_->getNrOfDegreesOfFreedom());
61 tasks_ptrs_.push_back(base_task_ptr);
62 tasks_names_.push_back(task_name);
63 tasks_weight_.push_back(task_weight);
66 throw std::logic_error(
"Task with name " + task_name +
" already exist.");
78 template <
template <Qontrol::ControlOutput output2>
class ControlInput>
79 std::shared_ptr<ControlInput<output>>
add(std::string task_name,
80 double task_weight = 1.0) {
81 if (!
exist(task_name)) {
82 auto task_ptr = std::shared_ptr<ControlInput<output>>(
83 new ControlInput<output>(task_name, model_ptr_));
85 tasks_ptrs_.push_back(task_ptr);
86 tasks_names_.push_back(task_name);
87 tasks_weight_.push_back(task_weight);
90 throw std::logic_error(
"Task with name " + task_name +
" already exist.");
99 bool exist(std::string task_name) {
100 return (findTaskIterator(task_name) != tasks_names_.end());
108 for (
auto task : tasks_ptrs_)
109 PLOGD <<
"Task name " << task->getName();
117 for (
auto task : tasks_ptrs_) {
127 std::vector<std::shared_ptr<Task::GenericTask>>
getTasks() {
147 if (
exist(task_name)) {
148 auto itr = findTaskIterator(task_name);
149 return std::distance(tasks_names_.begin(), itr);
151 PLOGI <<
"Task " << task_name <<
" doesn't exist. Cannot get it's index.";
161 void remove(std::shared_ptr<Task::GenericTask> task_ptr) {
162 remove(task_ptr->getName());
171 if (
exist(task_name)) {
173 tasks_ptrs_.erase(tasks_ptrs_.begin() + index);
174 tasks_names_.erase(tasks_names_.begin() + index);
175 tasks_weight_.erase(tasks_weight_.begin() + index);
185 bool setTaskWeight(std::shared_ptr<Task::GenericTask> task,
double task_weight) {
196 if (
exist(task_name)) {
197 tasks_weight_.at(
getTaskIndex(task_name)) = task_weight;
200 PLOGW <<
"Task " << task_name <<
" doesn't exist. Cannot set its weight";
206 std::shared_ptr<Model::GenericModel> model_ptr_;
207 std::vector<std::string> tasks_names_;
216 std::vector<std::string>::iterator findTaskIterator(std::string task_name) {
217 return std::find(tasks_names_.begin(), tasks_names_.end(), task_name);
220 std::vector<std::shared_ptr<Task::GenericTask>> tasks_ptrs_;
221 std::vector<double> tasks_weight_;