Skip to content

Model specification efficiency  #1

@rileyjmurray

Description

@rileyjmurray

All line numbers are with respect to dc6735c

Lines 38 to 53 can be reduced to three CVXPY constraint objects by using appropriate logical / block indexing.

Lines 56 to 65 can be reduced to a single CVXPY constraint object. The trick would be to generate a list of CVXPY Expression objects, where each element of the list was the expression defined from lines 59 to 64 (for appropriate k). Once that list is built you can turn it into one big CVXPY Expression object via "vstack"; this will give you the RHS of the constraint. You should then be able to write X_[range(K-1), :] == RHS.

The general pattern is

  • Build two lists of CVXPY Expression objects "left_hand_sides", "right_hand_sides" by looping over your problem data.
  • Define LHS = vstack(left_hand_sides), RHS = vstack( right_hand_sides ).
  • Append "LHS <= RHS" or "LHS == RHS" to your list of CVXPY Constraint objects.

The function "vstack" can be found at cvxpy.atoms.affine.vstack.vstack( [list of expressions] ). It requires all arguments to have the same number of columns, so you may have to use the above pattern several times for different groups of constraints, depending on their dimensions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions