Originally posted by: davidoff
Excellent !
Thanks for the workaround
In order to avoid loosing precision with rounding float values, I consider multiplying and dividing by 100000 the fractional part of the coefficients (see code below)
using CP;
int dig = 6;
//how many digits do we keep range r = 1..2;
float dual[r] = [1567.2389, 3.000678];
int ent[i in r] = ftoi(round(dual[i]));
float res[i in r] = dual[i]- round(dual[i]);
int resd[i in r] = ftoi(round(pow(10,dig)*res[i])); dvar
int coeffEnt[i in r] in ent[i]..ent[i]; dvar
int coeffRest[i in r] in resd[i]..resd[i]; dexpr
float coeff[i in r] = coeffEnt[i] + pow(10,-dig)*coeffRest[i]; dvar int+ x[r]; minimize sum(i in r) coeff[i]* x[i]; subject to
{ sum(i in r) x[i] >=1;
} execute
{
//postprocess writeln(x);
} main
{ thisOplModel.generate();
if (cp.solve())
{ writeln(
"RUN 1 objvalue = ",cp.getObjValue()); thisOplModel.postProcess();
} writeln(
"update bounds"); thisOplModel.coeffEnt[1].LB= 2;
//change dual[1] to 2.2389 thisOplModel.coeffEnt[1].UB= 2;
//change dual[1] to 2.2389
if (cp.solve())
{ writeln(
"RUN 1 objvalue = ",cp.getObjValue()); thisOplModel.postProcess();
}
}
This code simply picks up the item with the smallest coefficient. The first coefficients are 1567.2389, 3.000678 and later I change them in 2.2389, 3.000678 . The result is correct :
RUN 1 objvalue = 3.000678 [0 1] update bounds RUN 1 objvalue = 2.2389 [1 0]
#DecisionOptimization#OPLusingCPOptimizer