AMPL 的无效下标 x[2,1,1]

Invalide Subcript x[2,1,1] of AMPL

第一次使用AMPL来解决问题。 谁能告诉我为什么这个程序给我 Invalid Subcript x[2,1,1] ?

谢谢!

param K; #number of customers 
param T; #number of orders
param J; #number of fabs
param I; #number if items


param A {i in 1..I, t in 1..T}; #quantity of item i requested in order t
param P { t in 1..T}; # price of order t if fully fulfilled
param C {i in 1..I, j in 1..J}; #number of items i that can be produced by fab j per hour
param Cap {j in 1..J}; #capacity hours for fab j
set list {j in 1..J}= {i in 1..I: C[i,j] <>0}; #set of items that can be produced by firm j
set nonlist {j in 1..J}= {i in 1..I: C[i,j] =0}; #set of items that cannot be produced by firm j

var x {i in 1..I, j in 1..J, t in i..T}; #optimal quantity of item i produced by fab j for order t 


maximize profit: 
#sum {i in 1..I, j in 1..J, t in 1..T} (P[t]*(x[i,j,t] / (sum{ i in 1..I} A[i,t]))); #written like that doesn't work?!
sum{t in 1..T} (P[t]*((sum{i in 1..I, j in 1..J} x[i,j,t])/(sum {i in 1..I} A[i,t]))); 

subject to limit {i in 1..I, t in 1..T}: sum {j in 1..J} x[i,j,t] <= A[i,t] ; #cannot produce more than ordered for each item i in each order t
subject to capacity {j in 1..J} : sum { t in 1..T, i in list[j]} (x [i,j,t] / C[i,j]) <= Cap [j]; #cannot produce more than maximum capacity for each fab j
subject to realistic {j in 1..J, i in nonlist[j], t in 1..T}: x[i,j,t] =0; # firm j cannot produce item i if C[i,j]=0
subject to nonnegativity {i in 1..I, j in 1..J, t in 1..T}: x[i,j,t] >= 0;

数据文件是

param T := 10;
param J:= 8;
param I:= 12;

param A: 
             1 2 3 4 5 6 7 8 9 10 :=
1 0 1000 0 0 5000 0 0 2000 1500 0 
2 0 2000 0 4000 0 1000 1000 2000 0 0
3 0 0 1500 0 0 3500 500 0 3000 0
4 2000 0 0 0 0 1500 0 500 4000 2000
5 3000 0 0 5000 1500 0 0 1000 500 0
6 0 1000 0 0 2500 0 5000 0 1000 0
7 0 0 5000 0 0 0 0 1000 3000 0
8 0 0 4000 0 0 3000 0 0 2000 2000
9 0  0 6000 8000 2500 0 0 0 500 0
10 5000 0 0 0 0 0 0 2000 3000 3000
11 0 3000 0  2000 0 1500 0 3000 500 0
12 0 0 2000 3000 0 0 500 1000 1500 4000 ;

param P :=

1 5500
2 4300
3 9300
4 8600
5 8000
6 6700
7 4700
8 7000
9 9600
10 7200 ;

param Cap :=

1 840
2 750
3 610
4 470
5 560
6 240
7 1250
8 930;

param C: 
  1 2 3 4 5 6 7 8 :=
1 10 5 0 25 20 40 0 0
2 5 0 20 0 15 0 5 10
3 10 15 30 0 20 40 0 0
4 10 0 5 20 0 50 15 15
5  5 0 0 25 0 50 15 15
6 0 5 10 40 15 0 5 0
7 20 10 0 5 30 0  10 0
8 50 15 10 0  0 30 5  0
9 40 20 30 0 0 0 10 20
10 0 25 15 0 15 45 5 0
11 0 20 0 30 0 20 15 5
12 0 0 30 15 20 0 10 20;

运行 命令给出结果 Invalid Subcript x[2,1,1]:

变量 x[2,1,1] 不存在,因为 x{i in 1..I, j in 1..J, t in i..T} 上建立索引,所以当 i 为 2 时,t 从 2 到T。您应该将 x 的声明更改为

var x {i in 1..I, j in 1..J, t in 1..T};

或更改 profit 声明中的索引,并可能更改与 x.

的索引一致的约束