Problem

16 views
Skip to first unread message

akram mirahmadi

unread,
Nov 21, 2016, 8:28:50 PM11/21/16
to am...@googlegroups.com
Hi there,

I have difficulty to define a decision variable in Ampl. I have x[p,t,n], which p, t and n are parameter. However, n can gets amount from 1 to t each time. it means if for example in one constraint I have x[p,t,n] which p=1,2, t=1,2,3 each time I want n to get amount till t. for example: p=2, t=3, n=1,2,3. How can I define this?

Regards,
Akram

Robert Fourer

unread,
Nov 22, 2016, 10:21:10 AM11/22/16
to am...@googlegroups.com
You can write

param P;
param T;
var x {p in 1..P, t in 1..T, n in 1..t};

Note that n only runs from 1 to t in this indexing expression (not from 1 to T).

Bob Fourer
am...@googlegroups.com

=======

aki

unread,
Nov 28, 2016, 5:21:38 PM11/28/16
to AMPL Modeling Language, 4...@ampl.com
Thanks Bob for your response, 
I have another question as well. I am not sure if I can put an amount of a parameter as the ending number of a loop.
for example: can I have this:

subject to waiting_time {p in 1..Patient}:
sum{t in 1..time, n in 1..waiting[p]} amount[p,t,n]>=0.9*sum{t in 1..time} demand[1,t];
which waiting[p] is a parameter itself.

Thanks.

Robert Fourer

unread,
Nov 29, 2016, 10:43:08 AM11/29/16
to am...@googlegroups.com
This is fine. In general, the operands to .. can be any expressions involving sets and params that evaluate to numbers.

Bob Fourer
am...@googlegroups.com

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