0

Trying to figure out a way to write a constraint with N variable to use on CVXPY that fit this:

var1 + var2 + ... + varN = K # K is a constant

All variables objects are instantiated and are stored in a list.

[Variable, Variable, ...]
Rodrigo de Azevedo
  • 1,097
  • 9
  • 17
gerosalesc
  • 2,983
  • 3
  • 27
  • 46

1 Answers1

4

I would write

   constraint = (sum([Variable, Variable, ...]) == K)

Then be sure to include that constraint in your problem.

steven
  • 671
  • 4
  • 8