问题
The following set and parameters are written in the AMPL environment. How can they be converted to 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
Also, the following Constraints are written in the AMPL environment. How can they be converted to CPLEX?(Especially the conditional part)
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;
in 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]<= ??;
回答1:
let me help with the syntax
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;;
}
works fine
来源:https://stackoverflow.com/questions/63864348/how-do-i-convert-ampl-to-cplex