# [AMPL 24527] AMPL question

Hi guys,

When I try to run the following code:
#Part 0 declaration of parameters
param n;
param m;
set N:=1…n; #number of bonds
set M:=0…m; #number of years

param a{N}; #price of bonds
param L{M}; #liabilities
param d{M,N}; #payment structure

#Part 1 declaration of variables
var x{N} >=0, integer; #investment on bonds
var z{M} >=0; #cash on hand

#Part 2 objective function
minimize cost: sum{j in N} a[j]*x[j];

#Part 3 constraints

subject to initial: z=0;
subject to liability {i in M}: z[i-1]-z[i]+sum{j in N}d[i,j]*x[j]>=L[i];

I ran into the error saying

“Error executing “solve” command:
error processing constraint liability:
invalid subscript z[-1]”

Can anyone help me solving this issue? I’m an absolute rookie to AMPL, any help is appreciated!

Your “liability” constraints are defined by

``````subject to liability {i in M}:
z[i-1] - z[i] + sum{j in N} d[i,j] * x[j] >= L[i];
``````

set M is 0…m, so there is a constraint liability that is

`z[-1] - z + sum {j in N} d[0,j] * x[j] >= L;`

But you have defined “var z{M} >=0;”, so there is no variable z[-1], and as a result you are getting the “invalid subscript z[-1]” error. One way to fix this is to write instead

``````subject to liability {i in M diff {0}}:
z[i-1] - z[i] + sum{j in N} d[i,j] * x[j] >= L[i];
``````

so that AMPL does not generate a liability constraint.