问题
I am trying to run the following code, but there is an error in dvar float+
using CP;
int rows=3;
int columns=3;
range para=1..rows*columns;
float model1[para]=...;
dvar float+ model0[para];
maximize
sum(p in para) model0[p]*(lg(model0[p]/model1[p]));
subject to{
c1:
sum(p in para)
model0[p]==3.0;
}
回答1:
Decision variables with CPOptimizer cannot be float.
As can be seen in the example floatexpr.mod you can use a float dexpr in order to use decimal values computed out of a integer decision variables.
In your case:
using CP;
execute
{
cp.param.timelimit=10;
}
int scale=1000;
int rows=3;
int columns=3;
range para=1..rows*columns;
float model1[p in para]=p/10;
dvar int+ scalemodel0[para];
dexpr float model0[p in para]=scalemodel0[p]/scale;
maximize
sum(p in para) model0[p]*(lg(model0[p]/model1[p]));
subject to{
c1:
sum(p in para)
model0[p]==3.0;
}
来源:https://stackoverflow.com/questions/58334041/cplex-opl-using-decision-variable-as-float-in-constraint-programming-algorithm