1

I'm trying to create an optimization problem in the following form using lpSolveAPI.

max 10(x1 + x2) * S1 + 20(x1 + x2) * S2

sub.to. S1 + S2 <= 1 # These are binary variables.

2 * x1 + 3 * x2 <= 30

1 * x1 + 2 * x2 <= 10

x1 & x2 are integers.

My problem is how to create this multiplicative variable? All the examples I'm coming across variables are linearly assigned. As mentioned earlier I'm using lpSolveAPI from R.

josliber
  • 43,891
  • 12
  • 98
  • 133
Beta
  • 1,638
  • 5
  • 33
  • 67
  • 1
    You could tackle the cases `S1=0,S2=1` and `S1=1,S2=0` separately and take the solution with the larger result. – Axel Kemper Dec 31 '17 at 13:29
  • @AxelKemper: Thanks for the great suggestion! I didn't think about it. But one issue is if my S are say 50. Then I've to do 50 separate optimization, which will be bit difficult to do. And my S are actually more than 2. – Beta Dec 31 '17 at 13:32
  • 1
    Perhaps, you can make use of [linearization](https://www.leandro-coelho.com/linearization-product-variables/). – Axel Kemper Dec 31 '17 at 13:44
  • @AxelKemper: Thanks for this suggestion! Will surely look into it. – Beta Dec 31 '17 at 13:56

1 Answers1

1

It sounds like you have a sum like (10*x1 + 10*x2) * S1 + (20*x1 + 20*x2) * S2 + ... with binary S1, S2, ... and you are trying to maximize this term.

One way to do this would be to define variables V1, V2, ..., with one for each of the S1, S2, ... variables. You can then add the following constraints:

V1 <= 10*x1 + 10*x2
V1 <= M*S1
V2 <= 20*x1 + 20*x2
V2 <= M*S2
...

Here, M is a large positive constant. No matter the value of S1, the variable V1 must satisfy V1 <= 10*x1 + 10*x2. If S1=0, then we additionally have V1 <= 0. If S1=1, then we additionally have V1 <= M. However if M is large enough, then this will never be a binding constraint.

Now, we can replace the objective with:

max V1 + V2 + ...

Since we are maximizing, the V variables will take value 0 when their corresponding S variable is not set, and it will take the value you want in the objective otherwise.

josliber
  • 43,891
  • 12
  • 98
  • 133