error processing constraint: invalid subscript

6 views
Skip to first unread message

Elena Picazo Gurina

unread,
Nov 2, 2022, 12:04:06 PM11/2/22
to AMPL Modeling Language
Hello, 

My constraints c1 and c2 depend on previous values and my parameter D starts at 1, therefore, I would like that when i=1, cash_end[i-1,j]=cash_end[0,j]=cash_start[j], cash_start[j] is a parameter. But it is not working...any clues?

Error at _cmdno 2 executing "solve" command
error processing constraint cc1[1]:
    invalid subscript cash_end[0,1]


Thank you in advance!!

AMPL mod file:
param D; 
param O; 

param cash_start {1..O} >=0; 
param cash_start_central >=0; 

# decision variables
var trans {1..D,1..O} >= l, <= u integer; 
var cash_end  {1..D,1..O} >=0; 
var cash_end_central {1..D} >=0; 
var w {1..D,1..O} binary; 

# objective function
maximize obj: sum{i in 1..D, j in 1..O} cash_end[i,j]
                        + sum{i in 1..D} cash_end_central[i]
                        ;

#constraints
subject to cc1 {j in 1..O}: cash_end[0,j] = cash_start[j];
subject to cc2: cash_end_central[0] = cash_start_central;

subject to c1 {i in 1..D, j in 1..O}: cash_end[i,j] = cash_end[i-1,j];
                 
subject to c2 {i in 1..D, j in 1..O}: cash_end_central[i] = cash_end_central[i-1];

subject to c3 {i in 1..D, j in 1..O}: trans[i,j] <= w[i,j]*bigM;

AMPL dat file:
param D:=7;
param O:=1;

param cash_start:=
    1   2319;
   
param cash_start_central:=60000000;
param bigM:=1000000000000000000;


  



AMPL Google Group

unread,
Nov 2, 2022, 5:58:03 PM11/2/22
to AMPL Modeling Language
You should define

var cash_end {0..D,1..O} >=0;
var cash_end_central {0..D} >=0


--
Robert Fourer
am...@googlegroups.com
{#HS:2055947031-112606#}
Reply all
Reply to author
Forward
0 new messages