Q:

Setting an specific variable value in a non defined set value (AMPL)

I’m having the following problem, which can be reduced from my code to:
set t:= 1..5; #Time periods
set e:= 1..2; #Inventory places
set p:= 1..3; #Products

var Iq{p,e,t} >= 0; #Inventory variable

#Moving variables:
# i for sums in t
# g for sums in e
# j for sums in p

subject to inventory_balance {j in p, i in t}:
sum{g in e} Iq[j,g,i] = sum{g in e} Iq[j,g,i-1] + sum{x in k} A[j,i,x] * Mt[i] - DS[i,j] ;

This is the inventory level, which is the sum of "g in e" of the inventory level at time i-1 plus other things.  The problem is the "i-1" time period.  The first iteration will be for time t=1 i.e because of the constraint it will become time t=0.  I know that in that period (t=0) the amount of inventory is 0.  So the thing is, how can I set the variable Iq[p,e,0] be 0 in a constraint?  
Thanks in advance! 

A:

The easiest way to do it from where you are is: 
set t := 0..5;
...
subject to starting_inventory_zero {j in p, k in e}: Iq{j,k,0} = 0;

and then tweak the indexing in inventory_balance to
{j in p, i in t: i > 0}

But if it were my code I'd do it with ordered sets:
set t := 0..5 ordered;
...
subject to starting_inventory_zero {j in p, k in e}: Iq{j,k,first(t)} = 0;
...
subject to inventory_balance {j in p, i in t: ord(i) > 1}:
sum{g in e} Iq[j,g,i] = sum{g in e} Iq[j,g,prev(i)] + sum{x in k} A[j,i,x] * Mt[i] - DS[i,j] ;

This does the same thing, but it generalises better.  For instance, I could define my index set t as {JAN_2001, FEB_2001, ..., DEC_2016} and the code above would still work. ( Unless I've made some typos, which is always possible!)