【问题标题】:How do I convert AMPL to CPLEX如何将 AMPL 转换为 CPLEX
【发布时间】:2020-12-30 23:56:23
【问题描述】:

以下集合和参数是在 AMPL 环境中编写的。如何将它们转换为 CPLEX?

set B;      #set of all blocks
set T;      #set of time periods
set BI{B};  #set of blocks that overlie a block
set BY{T};  #set of blocks that can be excavated in time period t
param C_min;        #minimum processing capacity of a mill
param g{B};     #average grade for block
param x_cord{B};    #x-coordinate of a block
param r{B} symbolic;
param early{B} default 1;
var alpha{B,T} binary;  # indicator for which sequencing constraint 6 won't be met

此外,以下约束是在 AMPL 环境中编写的。如何将它们转换为 CPLEX?(尤其是条件部分)

subject to processing{t in T}:  C_min <= sum{b in B: early[b] <= t}(if g[b] > total[b]  
then total[b] else 0)*y[b,t];

subject to sequencing{b in B, vb in B, t in T: early [b] <= t  and (x_cord[b]=x_cord[vb]) 
and 
(y_cord[b]=y_cord[vb]) and (z_cord[b] = z_cord[vb]-1)}: y[b,t] <= sum{u in 
early[vb]..t}y[vb,u];

subject to logic:sum{b in B, t in T} alpha[b,t] <= card(T)*card(B)-1;

在复杂的:

forall (t in T) {
processing:
C_min<=sum(b in B: early[b] <= t) 
[(g[b] > total[b])=> (total[b])(g[b] <= total[b])=>(0)]*y[b][t];
}

forall (b in B)
  forall (vb in B)
        forall (t in T:early [b] <= t  &&  
        (x_cord[b]==x_cord[vb]) && (y_cord[b]==y_cord[vb]) && (z_cord[b] == z_cord[vb]-1)){
        sequencing:                             
            y[b][t]<=sum(u in early[vb]..t) y[vb][u];
}   

logic:                          
        sum(b in B)sum(t in T) alpha[b][t]<= ??;

【问题讨论】:

  • CPLEX 到底是什么意思?你是说OPL吗?或者您的意思是在编程 API 中编写这些东西?您是否查看过 CPLEX 的示例和教程?例如,请参见此处:ibm.com/support/knowledgecenter/SSSA5P_12.10.0/…
  • 我的意思是 OPL。我以前读过 CPLEX 指南,我知道 CPLEX。我只是在转换上述限制时遇到了麻烦。
  • 您必须显示C_minalphag 是什么。它们是决策变量还是参数?还请显示您目前拥有的 OPL 模型。对于您的条件中的if,您是否检查了“隐含”运算符=&gt;
  • 请求的参数和变量以及约束已在 CPLEX 环境中提交。

标签: cplex ampl


【解决方案1】:

让我帮忙看看语法

range B=1..4;
range T=1..3;
{int} BT[t in T]=asSet(1..t);
int early[b in B]=b;

int C_min=0;

dvar boolean y[B][T];
dvar boolean alpha[B][T];
dvar int g[B];
int total[B];
int x_cord[B];
int y_cord[B];
int z_cord[B];

subject to
{
  
  forall (t in T) {
processing:
C_min<=sum(b in B: early[b] <= t) 
((g[b] >= total[b])=> (total[b]*g[b] <= total[b]*y[b][t]));
}

forall (b in B)
  forall (vb in B)
        forall (t in T:early [b] <= t  &&  
        (x_cord[b]==x_cord[vb]) && (y_cord[b]==y_cord[vb]) && (z_cord[b] == z_cord[vb]-1)){
        sequencing:                             
            y[b][t]<=sum(u in early[vb]..t) y[vb][u];
}   

logic:                          
        sum(b in B)sum(t in T) alpha[b][t]<= card(asSet(T))*card(asSet(B))-1;;


 
} 

工作正常

【讨论】:

  • g [b] 是一个参数,不是变量,不应在第一个约束 g[b] 中给出。 c_min 的值不能为零。第一个约束似乎不完全等效。
  • 我试图帮助您了解语法。如果 g 是数据而不是决策变量,则更改 dvar int g[B];进入 int g[B];
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多