Question

In short, we are now trying to change the IQP into the ILP. It took about 2 days with the old implementation to finish, now with linear tools -- it should speed up. Basically the problem is to maximize (with about 50 binary vars):

$$\sum_{g=1}^{5}sum_{p=1}^{10} ( S[p]x[g][p]-Tiredness[g][p]-Sleepness[g][p] )$$

Update

I think David is on the right track but when I try to maximize the expression with bonus -variables, they are zero every time, why? Below some code, scores could be like S[1..10]=[1,2,3,4,5,6,7,8,9,10];.

int S[1..10] = ...; // Scores per player =s

dvar int x1[1..10] in 0..1;
dvar int x2[1..10] in 0..1;
dvar int x3[1..10] in 0..1;
dvar int x4[1..10] in 0..1;
dvar int x5[1..10] in 0..1;

dvar int b1[1..10] in 0..100;
dvar int b2[1..10] in 0..100;


//ERR: the values of b1 and b2 should be maximized...
// WHY not here so?

maximize 
sum(i in 1..10) 
(
S[i] *
    (
    (x1[i]+x2[i]+x3[i]+x4[i]+x5[i]) 
    - 1/10 * ( b1 +b2) 
    )
);

subject to 
{
    //We must play in 5 games.
    //It means that there are 5 players in each game.
    sum(i in 1..10) x1[i]==5;
    sum(i in 1..10) x2[i]==5;
    sum(i in 1..10) x3[i]==5;
    sum(i in 1..10) x4[i]==5;
    sum(i in 1..10) x5[i]==5;

    // IQP problem into ILP -problem

    forall (i in 1..10)
    {
        //ERROR HERE!
        //it returns zero for b1 and b2, they should be maximized... 
        //I am trying to use the tip by David here, see his answer.

        // EQ1: x2[i] * (x1[i]+x3[i])
        b1 <= 2*x2[i];
        b1 <= x1[i]+x3[i];

        // EQ2: x4[i] * (x3[i]+x5[i]+x1[i])
        b2 <= 3*x4[i];
        b2 <= x3[i]+x5[i]+x1[i];

    }

};
Was it helpful?

Solution

Expressions like

x1 * x2

are quadratic if x1, x2 are both variables. You have a 50-variable integer quadratic programming problem. Also, your objective function isn't concave so CPLEX is going to have an especially hard time.
However, since you have all 0-1 variables, you can convert this into an linear problem by adding an additional variable, say bonus for the expression with positive coefficients and penalty for those with negative coefficients, putting them in the objective function instead of the quadratic terms and adding the following constraints

bonus <= x1
bonus <= x2

or in case of a negative coeficient

penalty >= x1 + x2 - 1

Since you are maximizing, cplex will force bonus or penalty to the correct values at optimal solutions. The penalty and bonus variables should be declared to be non-negative

dvar float+ penalty;
dvar float+ bonus;

Do this for for all the quadratic expressions and your problem will become a linear integer problem and solve much faster.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top