CVXGEN: Code Generation for Convex Optimization

Constraints

You can create constraints in two ways: following an objective and the words subject to, or in a dedicated constraints block. Dimensions and convexity will be automatically checked. A constraint is an expression, a relation sign (<=, == or >=) and another expression. You can also index constraints.

Valid constraints have one of three forms:

  • convex <= concave

  • concave <= convex

  • affine == affine

Some examples:

constraints
  x >= 0
  sum(x) <= 5

  # Constraint on sum of indexed variables:
  sum[i=1..3](z[i]) <= Ztotal

  # Constraint on fourth and fifth elements of z:
  z[3] == z[4]
end

For convenience, you can also use two-sided constraints of the following form:

constraints
  x_min <= x <= x_max
end

You can index constraints in conjunction with indexed variables or parameters. For example:

constraints
  x_min <= x[t] <= x_max, t=0..T
  A[i]*x <= b[i], i=1..3
  A[i]*sum[j=0..5](w[j]) == 0, i=1..3
end

Notes

  • You can define a relation with vector <= scalar (say); this is equivalent to vector <= scalar*all_ones_vector.