Implementing tasks

Table of Contents

Types of tasks

Tasks are composed of two main elements

  • body – a matrix, which multiplies the vector of decision variables 'x';
  • bounds – a vector(s) which constrain result of multiplication of the body by 'x'.

Currently, there are four types of task bodies:

  • A*x – 'x' is multiplied by a dense matrix 'A';
  • A*S*x – a continuous segment of 'x' is selected by matrix S and then mupltiplied by a dense matrix 'A';
  • G*I*x – a set of individual values of 'x' is selected by matrix 'I' and then each of the values is multiplied by a corresponding scalar gain stored in matrix 'G';
  • I*x – 'I' selects values of 'x', no weighting is performed, such tasks are assumed to be satisifed exactly.

Note that the structured matrices 'S', 'G', 'I' are not stored or defined explicitly. Refer to the documentation of tasks to learn how to specifiy them.

Bounds can also be of different types:

  • (L<=, <=U) – lower 'L' and upper 'U' bounds are defined;
  • (<=U) – only upper 'U' bound is defined;
  • (L<=) – only lower 'L' bound is defined;
  • (=B) – equality task: 'B = L = U';
  • (=0) – equality task with 'B = 0';

Various combinations of task bodies and bounds produce the following task types:

Equality (=0) Equality (=B) Lower bounds (L<=) Upper bounds (<=U) Lower and upper bounds
(L<=, <=U)
A*x humoto::TaskAB0 humoto::TaskAB humoto::TaskAL humoto::TaskAU humoto::TaskALU
A*S*x humoto::TaskASB0 humoto::TaskASB humoto::TaskASL humoto::TaskASU humoto::TaskASLU
G*I*x humoto::TaskGIB0 humoto::TaskGIB humoto::TaskGIL humoto::TaskGIU humoto::TaskGILU
I*x humoto::TaskIB0 humoto::TaskIB humoto::TaskIL humoto::TaskIU humoto::TaskILU


Each user-defined task must inherit from one of the task classes whose names are given in the table in the previous section. It is also possible to derive from one of predefined tasks instead.

Each user-defined task must have a unique string id (within a hierarchy) and implement method humoto::TaskBase::form(), which should


Choosing task type

In order to attain the highest performance it is necessary to carefully choose a parent class. While choosing a parent class the programmer should follow several principles:

Active set guessing

For the sake of performance, inequality tasks may also implement humoto::TaskBase::guessActiveSet() method, which should generate guess of active constraints. A default implementation of this method is provided for all tasks and uses the following heuristics

Alternatively, if you are working on an MPC problem, it is reasonable to shift the active set from the previous iteration forward by the number of constraints of the respective task in one interval, marking constraints of the last interval as inactive.