伙计们。我正在尝试在AMPL中编码p-hub中位数问题,并不断收到各种错误。我可以解决一些问题,但仍然无法解决,将不胜感激。
错误出现在最小化部分:
param n integer > 0;
set I = 1..n;
set J = 1..n;
param cost{I,J};
param passenger{I,J};
param p integer;
param i integer;
param j integer;
var alpha >= 0, <= 1;
var y binary;
var z binary;
var k{1..n} integer;
var m{1..n} integer;
minimize total_cost:sum {i in I, j in J, k in I, m in J} passenger[i,j]*x[i,j,k,m]*(cost[i,k]+cost[m,j]+alpha*c[k,m])
subject to nhubs: sum {k in I} y[k] = p;
subject to y_bin: 0 <= y[k] <= 1 forall k{I};
subject to x_lim:0 <= x[i,j,k,m] <= 1 forall i{I}, j{J}, k{I}, m{J};
subject to hubpair:sum {k in I, m in J} x[i,j,k,m] = 1 forall i{I}, j{J}; # to assure the flow is routed via some hub pair
subject to huballocation: 0 <= z[i,k] <= 1 forall i{I}, k{I};
subject to z: z[i,k] <= y[k] forall i{I}, k{I};
subject to Z:sum {k in I} z[i] >= 1;
subject to demandpointallocation:sum {j in J, m in J} passenger[i,j]*x[i,j,k,m] + passenger[j,i]*x[j,i,m,k] = sum {j in J} z[i,k] * (passenger[i,j] + passenger[j,i]) forall i{I}, k{I};
DATA(数据样本):
data;
param n := 9;
param p := 2;
param i := 2;
param j := 9;
param cost : 1 2 3 4 5 6 7 8 9:=
1 0 3 1 1 3 2 3 1 2
2 3 0 1 2 3 1 1 2 1
3 1 1 0 3 1 1 2 1 2
4 1 2 3 0 1 3 3 1 3
5 3 3 1 1 0 3 2 1 2
6 2 1 1 3 3 0 1 1 3
7 3 1 2 3 2 1 0 2 3
8 1 2 1 1 1 1 2 0 2
9 2 1 2 3 2 3 3 2 0;
param passenger : 1 2 3 4 5 6 7 8 9:=
1 0 182 2 2 167 9 23 63 72
2 91 0 22 2 95 157 186 127 86
3 30 67 0 66 121 21 156 24 170
4 12 135 114 0 131 13 163 178 161
5 75 186 159 197 0 110 163 108 152
6 137 56 151 170 136 0 132 74 81
7 44 18 71 85 196 147 0 60 81
8 176 104 123 109 107 55 78 0 52
9 48 173 182 38 137 5 40 99 0;