我正在进行CPlex实验,并且“限制数量”约束使问题不可行......
在没有限制约束的情况下成功完成了工作。 我想对连接到集线器dc的经销商进行数量限制。 我好久不知道了。
我的代码:
>
execute PARAMS {
cplex.tilim = 43200;
// cplex.tilim = 10;
}
// parameters
int nDealer = ...;
int nSite = ...;
range dealer = 1..nDealer; // destinations
range site = 1..nSite; // distribution centers (candidate sites for hub and depot)
int numHub = ...;
int numDepot = ...;
int limit = ...;
float flow[dealer] = ...;
float capacity[site] = ...;
float xDealer[dealer] = ...;
float yDealer[dealer] = ...;
float xSite[site] = ...;
float ySite[site] = ...;
float dist[dealer][site];
float distSite[site][site];
float M;
dvar boolean a[dealer][site]; // alpha_ij = 1 if dest i uses DC j
dvar boolean b[site]; // beta_j = 1 if DC (hub) j is established
dvar boolean c[site]; // gamma_k = 1 if DC (depot) k is established
dvar boolean w[site][site]; // w_jk = 1 if hub j is connected to depot k.
dvar float volume[site]; // total flow volume assigned to DC j
dvar boolean z[dealer][site];
execute DISTANCE { // Euclidean Distance
for (var i in dealer) {
for (var j in site) {
dist[i][j] = Opl.sqrt(Opl.pow(xDealer[i] - xSite[j], 2) + Opl.pow(yDealer[i] - ySite[j], 2));
}
}
for (var j in site) {
for (var k in site) {
distSite[j][k] = Opl.sqrt(Opl.pow(xSite[j] - xSite[k], 2) + Opl.pow(ySite[j] - ySite[k], 2));
}
}
M = 0;
for (var i in dealer) {
M += flow[i];
}
}
// models
minimize sum(i in dealer) flow[i]
* (sum(j in site) (dist[i][j] * a[i][j] + sum(k in site) distSite[k][j] * w[k][j]));
/* wrong Obj Func
minimize sum(i in dest, j in DC) (flow[i] * dist[i][j] * a[i][j]
+ (sum(k in DC : j != k) (flow[i] * distDC[j][k] * w[j][k])) ); // sum(f_i * sum(metro + regional))
*/
subject to {
sum(j in site) (b[j]) == numHub;
sum(k in site) (c[k]) == numDepot;
forall(i in dealer) {
sum(j in site) (a[i][j]) == 1;
forall(j in site) {
a[i][j] <= b[j] + c[j];
}
}
// w[j][k] <= b[j] * c[k]
// Hub j can be connected to a single depot.
forall(j in site) {
b[j] + c[j] <= 1;
// capacity restriction
// volume = metro + regional
volume[j] == sum(i in dealer) flow[i]
* (a[i][j] + (sum(k in site : k != j) a[i][k] * w[j][k]));
volume[j] <= capacity[j] + M * (1 - b[j]); // only Hub concerned with its capacity
forall(k in site : j != k) {
2 * w[j][k] <= b[j] + c[k];
}
}
// at least 1 hub must be connected to depot
forall(k in site) {
sum(j in site : j != k) (w[j][k]) == c[k];
}
forall (j in site){
forall (i in dealer){
((a[i][j]+b[j])/2) <= z[i][j];
}
sum(i in dealer) (z[i][j]) <= limit;
}
}
答案 0 :(得分:1)
&gt; CPLEX Studio IDE&gt; IDE教程 你可以看看
放松不可行模型
另外,为了获得帮助,你可以在这里附上.dat
问候
答案 1 :(得分:1)
您没有向我们提供有关您的问题的大小或您尝试施加的限制的信息。你可能只是试图施加太小的限制 - 我们无法分辨。
要尝试两件事:
首先,如果省略限制约束,你得到z [i] [j]变量的值是多少?这些价值看起来合情合理吗?如果没有,也许您在配方或输入数据中有一些错误。
其次,如果您包含限制值较大的限制约束(例如,在无约束的情况下大于z [i] [j]的值),那么您仍应获得相同的解决方案。尝试减少限制值并重新求解。您应该找到问题变得不可行的限制值。探索在该关键限值附近发生的事情,并了解其余解决方案值会发生什么。