Setting an specific variable value in a non defind Set Value

8 views
Skip to first unread message

The Flying Raccoons GT

unread,
Sep 24, 2017, 6:10:07 PM9/24/17
to AMPL Modeling Language
Hello,
I’m having the following problem, which can be reduced from my code to:

set t:= 1..5; #Time periods
set e:= 1..2; #Intentory 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!

Robert Fourer

unread,
Sep 25, 2017, 10:46:25 AM9/25/17
to am...@googlegroups.com
Replace "sum{g in e} Iq[j,g,i-1]" by "if i > 0 then sum {g in e} Iq[j,g,i-1] else 0". (Actually you can omit the "else 0" since that is assumed by default.)

If you name your sets T, E, P, then you can use t, e, p for the summation indices, and your constraints will be a lot easier to read:

subject to inventory_balance {p in P, t in T}:
sum {e in E} Iq[p,e,t] = ...

Bob Fourer
am...@googlegroups.com

=======
Reply all
Reply to author
Forward
0 new messages