Reputation: 377
I have a simple non linear code built in minizinc as follows.
array[1..3] of var 1..10:x;
array[1..3] of var 10.0..20.0:y;
var float:z;
constraint sum(i in 1..3)(x[i]*y[i])=z;
solve minimize z;
If I use Cplex solver in minizinc background I have an error of Float_times.
unable to create linear formulation for the `float_times` constraint. This model instance cannot be solved using a linear solver.
If I convert the same code to OPL and use them in IBM ILOG Cplex IDE It provide the answer.Sample code as follows.
dvar int x[ 1..3] in 1..10;
dvar float y[ 1..3] in 10.0..20.0;
dvar float z;
minimize z;
subject to {
cons1:
sum(i in 1..3)x[i]*y[i]==z;
}
Could you someone explain why it is happening even though I used the same solver in both backends.
Upvotes: 0
Views: 629
Reputation: 10059
your constraint is not linear. When you solve with OPL the presolve did everything but if you remove presolve then you need to change optimality target:
execute
{
cplex.preind=0;
cplex.optimalitytarget=3;
}
dvar int x[ 1..3] in 1..10;
dvar float y[ 1..3] in 10.0..20.0;
dvar float z;
minimize z;
subject to {
cons1:
sum(i in 1..3)x[i]*y[i]==z;
}
works fine
So you could either set that setting "optimality target" through minizinc
Or rely on logical constraints / indicators
execute
{
cplex.preind=0;
//cplex.optimalitytarget=3;
}
dvar int x[ 1..3] in 1..10;
dvar float y[ 1..3] in 10.0..20.0;
dvar float z;
dvar float xy[1..3];
minimize z;
subject to {
cons1:
sum(i in 1..3)xy[i]==z;
forall(i in 1..3) forall(j in 1..10) (x[i]==j) => xy[i]==y[i]*j;
}
works fine too
Upvotes: 2