37 number_of_general_constraints_ = 0;
38 number_of_simple_constraints_ = 0;
40 number_of_equality_constraints_ = 0;
41 number_of_twosided_constraints_ = 0;
57 const bool is_active_set_guessing_enabled)
62 HUMOTO_ASSERT(tasks_.size() > 0,
"No tasks on a hierarchy level.");
64 for ( std::list<TaskInfo>::iterator it = tasks_.begin();
69 it->ptr_->form(sol_structure, model, control_problem);
70 if (is_active_set_guessing_enabled)
72 it->ptr_->guessActiveSet(sol_structure, model, control_problem);
77 std::size_t num_ctr = it->ptr_->getNumberOfConstraints();
79 if (it->ptr_->isEquality())
81 number_of_equality_constraints_ += num_ctr;
84 if (it->ptr_->isTwoSidedInequality())
86 number_of_twosided_constraints_ += num_ctr;
89 if (it->ptr_->isSimple())
93 it->location_ =
Location(number_of_simple_constraints_ + number_of_general_constraints_, num_ctr);
94 number_of_simple_constraints_ += num_ctr;
98 it->location_ =
Location(number_of_general_constraints_, num_ctr);
99 number_of_general_constraints_ += num_ctr;
103 HUMOTO_ASSERT(getNumberOfConstraints() > 0,
"No constraints on a hierarchy level.");
115 for ( std::list<TaskInfo>::const_iterator it = tasks_.begin();
119 it->ptr_->copyActiveSetGuessTo(active_set, it->location_);
132 for ( std::list<TaskInfo>::iterator it = tasks_.begin();
136 it->ptr_->copyActualActiveSetFrom(active_set, it->location_);
151 for ( std::list<TaskInfo>::const_iterator it = tasks_.begin();
155 it->ptr_->determineActiveSet(active_set, it->location_, solution);
170 for ( std::list<TaskInfo>::const_iterator it = tasks_.begin();
174 it->ptr_->computeViolations(violations, it->location_, solution);
186 if (task_pointer->isSimple())
188 tasks_.push_back(
TaskInfo(task_pointer));
192 tasks_.push_front(
TaskInfo(task_pointer));
220 const std::size_t offset = 0,
221 const std::size_t length = 0)
222 : location_(offset, length)
257 return (number_of_general_constraints_
259 number_of_simple_constraints_);
270 return (number_of_simple_constraints_);
281 return (number_of_general_constraints_);
292 return (number_of_equality_constraints_);
303 return (getNumberOfConstraints() - getNumberOfEqualityConstraints());
314 return (getNumberOfInequalityConstraints() + number_of_twosided_constraints_);
325 return (getNumberOfConstraints() == number_of_simple_constraints_);
336 return (getNumberOfConstraints() == number_of_equality_constraints_);
349 eq_constraints.
reset( getNumberOfEqualityConstraints(),
352 std::size_t eq_offset = 0;
354 for ( std::list<TaskInfo>::const_iterator it = tasks_.begin();
358 if (it->ptr_->isEquality())
360 eq_offset = it->ptr_->copyTo(eq_constraints, eq_offset);
375 ineq_constraints.
reset( getNumberOfInequalityConstraintsOneSided(),
378 std::size_t offset = 0;
380 for ( std::list<TaskInfo>::const_iterator it = tasks_.begin();
384 if ( ! (it->ptr_->isEquality()) )
386 offset = it->ptr_->copyTo(ineq_constraints, offset);
401 constraints.
reset(getNumberOfConstraints(),
404 if (getNumberOfConstraints() > 0)
406 std::size_t offset = 0;
407 for ( std::list<TaskInfo>::const_iterator it = tasks_.begin();
408 (it != tasks_.end());
411 offset = it->ptr_->copyTo(constraints, offset);
426 constraints.
reset(getNumberOfGeneralConstraints(),
429 if (getNumberOfGeneralConstraints() > 0)
431 std::size_t offset = 0;
432 for ( std::list<TaskInfo>::const_iterator it = tasks_.begin();
433 (it != tasks_.end()) && (!it->ptr_->isSimple());
436 offset = it->ptr_->copyTo(constraints, offset);
453 constraints.
reset( getNumberOfSimpleConstraints(),
456 if (getNumberOfSimpleConstraints() > 0)
458 std::size_t offset = 0;
459 for ( std::list<TaskInfo>::const_iterator it = tasks_.begin();
460 (it != tasks_.end());
463 if (it->ptr_->isSimple())
465 offset = it->ptr_->copyTo(constraints, offset);
480 Eigen::VectorXd &g)
const 482 for ( std::list<TaskInfo>::const_iterator it = tasks_.begin();
486 if (it == tasks_.begin())
488 it->ptr_->getATAandATb(H, g);
492 it->ptr_->addATAandATb(H, g);
507 const std::string & name =
"")
const 513 for ( std::list<TaskInfo>::const_iterator it = tasks_.begin();
519 it->location_.log(logger, subname_loop);
520 it->ptr_->log(logger, subname_loop,
"");
Container for simple inequality constraints.
Abstract base class (for control problems)
std::size_t getNumberOfVariables() const
Get total number of variables in the solution vector.
Violations corresponding to Constraints class.
std::size_t number_of_equality_constraints_
void reset()
Reset variables.
void guessActiveSet(ActiveSetConstraints &active_set) const
Form active set guess.
#define HUMOTO_GLOBAL_LOGGER_IF_DEFINED
#define HUMOTO_ASSERT(condition, message)
void getGeneralConstraints(constraints::ContainerALU &constraints, const humoto::SolutionStructure &sol_structure) const
Generates objective containing all general constraints on this level.
Analog of 'sol_structure' struct in Octave code. [determine_solution_structure.m].
void getObjective(Eigen::MatrixXd &H, Eigen::VectorXd &g) const
Form objective of a QP.
std::size_t getNumberOfSimpleConstraints() const
Get number of simple constraints.
Container of the solution.
Active set corresponding to Constraints class.
This class represents one level of a hierarchy.
Represents log entry name.
void reset(const std::size_t number_of_constraints=0, const std::size_t number_of_variables=0, const bool initialize_matrices=false)
Initialize constraints.
Location location_
location of the task constraints on a hierarchy level
An optimization problem [initialize_stack.m, simulation_loop.m].
std::size_t getNumberOfInequalityConstraintsOneSided() const
Get number of inequality constraints, two-sided constraints counted twice.
std::size_t number_of_simple_constraints_
std::list< TaskInfo > tasks_
General constraints are added in the beginning, simple – in the end. It is easier to process tasks t...
std::size_t getNumberOfEqualityConstraints() const
Get number of inequality constraints.
HierarchyLevel()
Default constructor.
boost::shared_ptr< humoto::TaskBase > TaskSharedPointer
bool isEquality() const
True if all constraints on this level are equalitites.
Threaded logger: any data sent to this logger is wrapped in a message and pushed to a queue...
Information about a task in a hierarchy.
TaskSharedPointer ptr_
task pointer
void processActiveSet(const humoto::ActiveSetConstraints &active_set)
Process actual active set: extract active sets of individual tasks.
void pushTask(TaskSharedPointer task_pointer)
Add task to the optimization problem.
void getEqualityConstraints(constraints::ContainerAB &eq_constraints, const humoto::SolutionStructure &sol_structure) const
Generates (general) objective containing all equality constraints on this level.
void getAllConstraints(constraints::ContainerALU &constraints, const humoto::SolutionStructure &sol_structure) const
Generates objective containing all constraints on this level.
void getSimpleConstraints(constraints::ContainerILU &constraints, const humoto::SolutionStructure &sol_structure) const
Generates objective containing all simple constraints on this level.
Container for general onesided inequality constraints.
The root namespace of HuMoTo.
void determineActiveSet(ActiveSetConstraints &active_set, const Solution &solution) const
Determine active set based on the solution.
void computeViolations(ViolationsConstraints &violations, const Solution &solution) const
Compute violations based on the solution.
Instances of this class are passed to a virtual method 'humoto::TaskBase::form()', so even though this class is basically useless in its present form we cannot avoid its definition using a template.
std::size_t getNumberOfConstraints() const
Get total number of constraints.
void form(const humoto::SolutionStructure &sol_structure, const humoto::Model &model, const humoto::ControlProblem &control_problem, const bool is_active_set_guessing_enabled)
Form hierarchy.
std::size_t number_of_general_constraints_
Container for general equality constraints.
bool isSimple() const
True if all constraints on this level are simple.
void log(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="") const
Log hierarchy as a set of tasks.
LogEntryName & add(const char *name)
extends entry name with a subname
Location of a data chunk (offset + length).
std::size_t number_of_twosided_constraints_
void getInequalityConstraints(constraints::ContainerAL &ineq_constraints, const humoto::SolutionStructure &sol_structure) const
Generates (general) objective containing all equality constraints on this level.
std::size_t getNumberOfInequalityConstraints() const
Get number of inequality constraints.
TaskInfo(TaskSharedPointer ptr, const std::size_t offset=0, const std::size_t length=0)
Constructor.
std::size_t getNumberOfGeneralConstraints() const
Get number of general constraints.
Container for general inequality constraints.