# 14.2.8 Class Constraint¶

mosek::fusion::Constraint

An abstract constraint object. This is the base class for all constraint types in Fusion.

The Constraint object can be an interface to the normal model constraint, e.g. LinearConstraint and ConicConstraint, to slices of other constraints or to concatenations of other constraints.

Primal and dual solution values can be accessed through the Constraint object.

Members

Constraint.dual – Get the dual solution values of the constraint.

Constraint.getModel – Return the model that the constraint belongs to.

Constraint.getND – Return the number of dimensions in the constraint shape.

Constraint.getShape – Return the constraint’s shape.

Constraint.getSize – Return the total number of elements in the constraint.

Constraint.index – Get a single element from a constraint.

Constraint.level – Get the primal solution values of the constraint.

Constraint.remove – Remove the constraint from the model.

Constraint.slice – Create a slice constraint.

Constraint.toString – Create a human readable string representation of the constraint.

Constraint.update – Update part of a constraint.

Static members

Constraint.hstack – Stack a number of constraints horizontally.

Constraint.stack – Stack a number of constraints.

Constraint.vstack – Stack a number of constraints vertically.

Implemented by
Constraint.dual
shared_ptr<ndarray<double,1>> dual()


Get the dual solution values of the constraint or its slice. When the selected slice is multi-dimensional, this corresponds to the flattened slice of solution values.

Return

(double[])

Constraint.getModel
Model::t getModel()


Return the model that the constraint belongs to.

Return
Constraint.getND
int getND()


Return the number of dimensions in the constraint shape.

Return

(int)

Constraint.getShape
shared_ptr<ndarray<int,1>> getShape()


Return the constraint’s shape.

Return

(int[])

Constraint.getSize
int getSize()


Return the total number of elements in the constraint.

Return

(int)

Constraint.hstack
Constraint::t Constraint::hstack(Constraint::t v1, Constraint::t v2)
Constraint::t Constraint::hstack(Constraint::t v1, Constraint::t v2, Constraint::t v3)
Constraint::t Constraint::hstack(shared_ptr<ndarray<Constraint::t,1>> clist)


Stack a number of constraints horizontally.

Parameters
Return
Constraint.index
Constraint::t index(int idx)
Constraint::t index(shared_ptr<ndarray<int,1>> idxa)


Get a single element from a one-dimensional constraint.

Parameters
• idx (int) – The index of the element.

• idxa (int[]) – A multi-dimensional index of the element.

Return
Constraint.level
shared_ptr<ndarray<double,1>> level()


Get the primal solution values of the constraint. This amounts to evaluating the $$Ax$$ part of the constraint expression for the relevant solution value. When the selected slice is multi-dimensional, this corresponds to the flattened slice of solution values.

Return

(double[])

Constraint.remove
void remove()


Remove the constraint from the model. Using the constraint object after this method has been called results in undefined behavior.

Constraint.slice
Constraint::t slice(int first, int last)
Constraint::t slice(shared_ptr<ndarray<int,1>> firsta, shared_ptr<ndarray<int,1>> lasta)


Create a slice constraint.

Parameters
• first (int) – Index of the first element in the slice.

• last (int) – Index of the first element after the end of the slice.

• firsta (int[]) – The indexes of first elements in the slice along each dimension.

• lasta (int[]) – The indexes of first elements after the end of the slice along each dimension.

Return
Constraint.stack
Constraint::t Constraint::stack(Constraint::t v1, Constraint::t v2, int dim)
Constraint::t Constraint::stack(Constraint::t v1, Constraint::t v2, Constraint::t v3, int dim)
Constraint::t Constraint::stack(shared_ptr<ndarray<Constraint::t,1>> clist, int dim)


Stack a number of constraints.

Parameters
Return
Constraint.toString
string toString()


Create a human readable string representation of the constraint.

Return

(string)

Constraint.update
void update(Expression::t expr, Variable::t x)
void update(Expression::t expr, Variable::t x, bool bfixupdate)
void update(Expression::t expr)
void update(shared_ptr<ndarray<double,1>> bfix)


Update entire or part of the left-hand side of a constraint (the expression). See Sec. 7.10 (Problem Modification and Reoptimization) for a tutorial.

If only expr is given, replace the entire previous expression with expr. The shape of expr must match the shape of the constraint.

If only bfix is given, replace the constant term of the expression with bfix. The length of bfix must match the size of the expression.

If x is given, replace all columns in the constraint defined by x by terms defined by expr, possibly including constant terms. Currently it is only possible to update linear columns. Attempting to update columns of semidefinite variables will result in an error.

Parameters
• expr (Expression) – The expression to update with.

• x (Variable) – Variable object defining the columns to update.

• bfixupdate (bool) – Whether to include fixed terms as well.

• bfix (double[]) – The fixed term to update with.

Constraint.vstack
Constraint::t Constraint::vstack(Constraint::t v1, Constraint::t v2)
Constraint::t Constraint::vstack(Constraint::t v1, Constraint::t v2, Constraint::t v3)
Constraint::t Constraint::vstack(shared_ptr<ndarray<Constraint::t,1>> clist)


Stack a number of constraints vertically.

Parameters
Return