在约束规划算法中使用决策变量作为浮点数的CPLEX OPL [英] CPLEX OPL using decision variable as float in constraint programming algorithm
本文介绍了在约束规划算法中使用决策变量作为浮点数的CPLEX OPL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试运行以下代码,但是dvar float +中有错误
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;
}
推荐答案
使用CPOptimizer的决策变量不能为浮点数.
Decision variables with CPOptimizer cannot be float.
在示例floatexpr.mod中可以看到,可以使用float dexpr来使用从整数决策变量中计算出的十进制值.
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.
在您的情况下:
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;
}
这篇关于在约束规划算法中使用决策变量作为浮点数的CPLEX OPL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文