Problem with IF-THEN-ELSE constraint

27 views
Skip to first unread message

Marco Leonessi

unread,
Mar 8, 2018, 1:45:04 PM3/8/18
to AMPL Modeling Language
Hi!

I have a problem with a constraint with if-then-else.
First of all, I try to explain what I would like to reach.

Index
s - surgical ward;
i - kind of surgical operation;
t -  planning days{1, ..., 20};

Var
N_int_in[i,s,t] - number of operation of kind i belonging to ward s planned for the day t;
N_int_out[i,s,t+deg[i]] - number of patients that leave the hospital after recovery;

Param
deg[i] - deterministic number of days of recovery for the kind of operation;

I need to know how many patients leaves every day the hospital and, if they leave the hospital after 20-days-planning they are added in another variable: N_paz_in_post_pianificazione[s].

subject to CALCOLA_INT_OUT {s in S, t in T, i in I : uo[i] == s} :
if (t+deg[i] <= 20) then { N_int_in[i,s,t] = N_int_out[i,s,t+deg[i]] }
else { N_paz_in_post_pianificazione[s] = N_paz_in_post_pianificazione[s] + N_int_in[i,s,t] };

My problem is that AMPL inform that there is a syntax error in the equal sign:

syntax error
context:  if (t+deg[i] <= 20) then { N_int_in[i,s,t]  >>> =  <<< N_int_out[i,s,t+deg[i]] }

Where is the problem? I made a mistake in writing the constraint?

Thank you for your support!



AMPL Google Group

unread,
Mar 8, 2018, 3:08:28 PM3/8/18
to am...@googlegroups.com
You are defining if-then-else in the constraint, so you are not assigning value of one variable to another. Instead you are telling AMPL to find an optimal solution that satisfies the given constraints.

Regarding syntax error, you don't need curly braces and you need to break your constraint into two constraints:

subject to CALCOLA_INT_OUT {s in S, t in T, i in I : uo[i] == s} :
if (t+deg[i] <= 20) then N_int_in[i,s,t] = N_int_out[i,s,t+deg[i]] ;

subject to c1 {s in S, t in T, i in I : uo[i] == s} : if (t+deg[i] > 20) then N_paz_in_post_pianificazione[s] = N_paz_in_post_pianificazione[s] + N_int_in[i,s,t];


--
Paras Tiwari
am...@googlegroups.com
{#HS:537652890-2164#}
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.



Marco Leonessi

unread,
Mar 22, 2018, 7:14:47 AM3/22/18
to AMPL Modeling Language
Thank you very much for your help!
Reply all
Reply to author
Forward
0 new messages