如何将 AMPL 转换为 CPLEX
How do I convert AMPL to CPLEX
以下设置和参数是在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
另外,以下Constraints是在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;
在 Cplex 中:
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]<= ??;
让我帮助语法
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;;
}
工作正常
以下设置和参数是在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
另外,以下Constraints是在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;
在 Cplex 中:
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]<= ??;
让我帮助语法
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;;
}
工作正常