I have a problem with AMPL. I want to create a main so that, depending on a value entered by a user, a different .run is executed. I tried with the following instructions:
param choice;
read choice <-;
if (choice == 1) then include initFirst.run;
if (choice == 2) then include initSecond.run;
But they don't work! The two .run are both executed regardless of the value of choice. Can you help me? Thank you!
Try replacing "include" with "commands" in both places.
Chapter 16 of the AMPL Book discusses the difference between these two. "include" effectively substitutes the contents of the included file at that point in the code, which can lead to weird results - for instance, the included code might contain something that terminates the "if choice == 2" statement, resulting in execution of any subsequent code even if the "if" evaluated to false.
(Also, thanks for asking this question, because it helped me realise that I'd been using "include" where I really should've had "commands"!)