1

I have a CVXPY optimization script, with a variable made of 14 elements. The first 2 need be integer, the other 12 don't.

The CVXPY documentation says:

integer (bool or list of tuple) – Is the variable integer? The semantics are the same as the boolean argument.

For the boolean attribute, they say:

boolean (bool or list of tuple) – Is the variable boolean (i.e., 0 or 1)? True, which constrains the entire variable to be boolean, False, or a list of indices which should be constrained as boolean, where each index is a tuple of length exactly equal to the length of shape.

If I use the following (forcing all elements to be integer) the script works flawlessy:

opt_contracts = cp.Variable(14, integer=True)

But if I try the following:

opt_contracts = cp.Variable(14, integer=[0,1])

I get the follwing TypeError: 'int' object is not iterable. What am I doing wrong? Thanks

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
younggotti
  • 762
  • 2
  • 15

1 Answers1

2

I got it:

opt_contracts = cp.Variable(N, integer=[[0],[1]])
younggotti
  • 762
  • 2
  • 15