是否可以在 CPLEX 中对 MILP 执行灵敏度分析?
Is it possible to perform a sensitivity analysis in CPLEX fo a MILP?
我正忙着尝试在 CPLEX IDE 中对我的 MILP 问题执行灵敏度分析。我在我的代码中收到一个错误,因为它回复说此脚本不适用于 MILP 问题。
有人知道另一种进行(部分)敏感性分析的方法吗?或者知道我的代码有什么问题吗?
这是我用来查找约束的松弛变量的代码。
Mod
int Time = ...;
int Prod = ...;
range T=0..Time;
range J=1..Prod;
// Parameters
int d [T][J] = ...; // demand in period t
int K[J] = ...; // fixed order cost in period t
int h = ...; // unit holding cost in period t
int p = ...; // fixed cost of increasing WH size in period t
int q = ...; // fixed cost of increasing WH size in period t
int e = ...; // variable cost of increasing WH size in period t
int c = ...; // variable cost of decreasing WH size in period t
int r = ...; // WH rental cost per unit in period t
dvar int+ x[T][J]; //order quantity in period t
dvar int+ i[T][J]; //inventory lvl at the end of period t
dvar int+ w[T]; // warehouse size at the end of period t
dvar int+ u[T]; // warehouse size expansion at beginning of period t
dvar int+ v[T]; // warehouse size contraction at beginning of period t
dvar boolean y[T][J]; // binary variable for ordering in period t dvar int+ y[T][J]; //// this constraint assumes that only 1 order can be placed in t
dvar boolean z1[T]; // binary variable for WH expansion in period t
dvar boolean z2[T]; // binary variable for WH contraction in period t
//objecTive funcTion
dexpr int Cost = sum(t in T,j in J)
(K[j]*y[t][j]+h*i[t][j]+p*z1[t]+e*u[t]+q*z2[t]+c*v[t]+r*w[t]);
minimize Cost;
//constraints
subject to {
forall(t in 1..Time, j in J) {
c1: i[t-1][j] + x[t][j] - d[t][j] == i[t][j]; //Inventory balance constraint
c2: w[t-1] + u[t] - v[t] == w[t]; //warehouse balance constraint
c3:sum(j in J)i[t][j] <= w[t]; // inventory should be max. the warehouse level
c4:x[t][j] <= (sum(t1 in t..Time)d[t1][j])*y[t][j]; // dtT Cumulative demand from t to end T
c5:u[t] <= (sum(t in T)d[t][j])*z1[t]; // Total demand from 1 to T * z1 u[t] <= dtot*z1[t];
c6:v[t] <= (sum(t in T)d[t][j])*z2[t]; // Total demand from 1 to T *z2 v[t] <= dtot*z2[t]; or v[t] <= (sum(t in T,j in J)d[t][j])*z2[t];
c7:w[t] <= 14000; // WH max available capacity
c8:x[t][1] <= 8000; // production capacity prod 1 in a period t
c9:x[t][2] <= 9000; // production capacity prod2 in a period t
c10:i[0][1]==100; // initial inv prod 1
c11:i[0][2]==500; // initial inv prod 2
c12:w[0]==1000; //initial warehouse size
}
}
//display solution identifier
// Post Processing Code
execute {
if(cplex.getCplexStatus()==1){
writeln("Slack variable for c1=",c1.slack);
writeln("Slack variable for c2=",c2.slack);
writeln("Slack variable for c3=",c3.slack);
writeln("Slack variable for c4=",c4.slack);
writeln("Slack variable for c5=",c5.slack);
writeln("Slack variable for c6=",c6.slack);
writeln("Slack variable for c7=",c7.slack);
writeln("Slack variable for c8=",c8.slack);
writeln("Slack variable for c9=",c9.slack);
writeln("Slack variable for c10=",c10.slack);
writeln("Slack variable for c11=",c11.slack);
writeln("Slack variable for c12=",c12.slack);
}
else {
writeln("Solution not found");
}
}
数据
Time=4;
Prod=2;
d = [[0,0],[1500,500],[4000,2000],[200,3000],[2000,2000]];
K = [100000,200000]; // ordering costs
h = 1; // holding costs
p = 300; // fixed cost increasing size
q = 300; // fixed cost decreasing size
e = 1; // variable costs per unit increase
c = 2; // variable cost per unit decrease
r = 4; // WH rent costs
您遇到错误,因为 c1 是约束数组而不是约束。
如果你写
//display solution identifier
range T1=1..Time;
// Post Processing Code
execute {
if(cplex.getCplexStatus()==1){
for (t in T1) for ( j in J) writeln("Slack variable for c1=",c1[t][j].slack);
}
else {
writeln("Solution not found");
}
}
相反,你会得到一个漂亮的显示
我正忙着尝试在 CPLEX IDE 中对我的 MILP 问题执行灵敏度分析。我在我的代码中收到一个错误,因为它回复说此脚本不适用于 MILP 问题。
有人知道另一种进行(部分)敏感性分析的方法吗?或者知道我的代码有什么问题吗?
这是我用来查找约束的松弛变量的代码。
Mod
int Time = ...;
int Prod = ...;
range T=0..Time;
range J=1..Prod;
// Parameters
int d [T][J] = ...; // demand in period t
int K[J] = ...; // fixed order cost in period t
int h = ...; // unit holding cost in period t
int p = ...; // fixed cost of increasing WH size in period t
int q = ...; // fixed cost of increasing WH size in period t
int e = ...; // variable cost of increasing WH size in period t
int c = ...; // variable cost of decreasing WH size in period t
int r = ...; // WH rental cost per unit in period t
dvar int+ x[T][J]; //order quantity in period t
dvar int+ i[T][J]; //inventory lvl at the end of period t
dvar int+ w[T]; // warehouse size at the end of period t
dvar int+ u[T]; // warehouse size expansion at beginning of period t
dvar int+ v[T]; // warehouse size contraction at beginning of period t
dvar boolean y[T][J]; // binary variable for ordering in period t dvar int+ y[T][J]; //// this constraint assumes that only 1 order can be placed in t
dvar boolean z1[T]; // binary variable for WH expansion in period t
dvar boolean z2[T]; // binary variable for WH contraction in period t
//objecTive funcTion
dexpr int Cost = sum(t in T,j in J)
(K[j]*y[t][j]+h*i[t][j]+p*z1[t]+e*u[t]+q*z2[t]+c*v[t]+r*w[t]);
minimize Cost;
//constraints
subject to {
forall(t in 1..Time, j in J) {
c1: i[t-1][j] + x[t][j] - d[t][j] == i[t][j]; //Inventory balance constraint
c2: w[t-1] + u[t] - v[t] == w[t]; //warehouse balance constraint
c3:sum(j in J)i[t][j] <= w[t]; // inventory should be max. the warehouse level
c4:x[t][j] <= (sum(t1 in t..Time)d[t1][j])*y[t][j]; // dtT Cumulative demand from t to end T
c5:u[t] <= (sum(t in T)d[t][j])*z1[t]; // Total demand from 1 to T * z1 u[t] <= dtot*z1[t];
c6:v[t] <= (sum(t in T)d[t][j])*z2[t]; // Total demand from 1 to T *z2 v[t] <= dtot*z2[t]; or v[t] <= (sum(t in T,j in J)d[t][j])*z2[t];
c7:w[t] <= 14000; // WH max available capacity
c8:x[t][1] <= 8000; // production capacity prod 1 in a period t
c9:x[t][2] <= 9000; // production capacity prod2 in a period t
c10:i[0][1]==100; // initial inv prod 1
c11:i[0][2]==500; // initial inv prod 2
c12:w[0]==1000; //initial warehouse size
}
}
//display solution identifier
// Post Processing Code
execute {
if(cplex.getCplexStatus()==1){
writeln("Slack variable for c1=",c1.slack);
writeln("Slack variable for c2=",c2.slack);
writeln("Slack variable for c3=",c3.slack);
writeln("Slack variable for c4=",c4.slack);
writeln("Slack variable for c5=",c5.slack);
writeln("Slack variable for c6=",c6.slack);
writeln("Slack variable for c7=",c7.slack);
writeln("Slack variable for c8=",c8.slack);
writeln("Slack variable for c9=",c9.slack);
writeln("Slack variable for c10=",c10.slack);
writeln("Slack variable for c11=",c11.slack);
writeln("Slack variable for c12=",c12.slack);
}
else {
writeln("Solution not found");
}
}
数据
Time=4;
Prod=2;
d = [[0,0],[1500,500],[4000,2000],[200,3000],[2000,2000]];
K = [100000,200000]; // ordering costs
h = 1; // holding costs
p = 300; // fixed cost increasing size
q = 300; // fixed cost decreasing size
e = 1; // variable costs per unit increase
c = 2; // variable cost per unit decrease
r = 4; // WH rent costs
您遇到错误,因为 c1 是约束数组而不是约束。
如果你写
//display solution identifier
range T1=1..Time;
// Post Processing Code
execute {
if(cplex.getCplexStatus()==1){
for (t in T1) for ( j in J) writeln("Slack variable for c1=",c1[t][j].slack);
}
else {
writeln("Solution not found");
}
}
相反,你会得到一个漂亮的显示