CPLEX OPL using decision variable as float in constraint programming algorithm

∥☆過路亽.° 提交于 2021-01-29 07:58:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!