[英]CPLEX OPL using decision variable as float in constraint programming algorithm
I am trying to run the following code, but there is an error in dvar float+我正在尝试运行以下代码,但 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;
}
Decision variables with CPOptimizer cannot be float. CPOptimizer 的决策变量不能是浮点数。
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.从示例 floatexpr.mod 中可以看出,您可以使用浮点 dexpr 来使用从 integer 决策变量计算出的十进制值。
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.