1

With X a vector of binary variables, and W a vector of float variables, I want to write a constraint such that if W[i] > 0, then I should have X[i] = 1.

dvar boolean X[I]; // we choosed stocks i or not
dvar float W[I];    // weight of stocks i in portfolio

How can I state this constraint?

Xavier Nodet
  • 5,033
  • 2
  • 37
  • 48

1 Answers1

1

You could use logical constraints. Let me give you a small example out of the portfolio example that is in the OPL CPLEX examples.

You may read:

dvar float  Allocation[Investments] in FloatRange;  // Investment Level

and then you could add:

dvar boolean X[Investments];

and then in the subject to block you could add:

forall(i in Investments) X[i]==(Allocation[i]>=0.001);
halfer
  • 19,824
  • 17
  • 99
  • 186
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15