Two for loops aren't working

5 views
Skip to first unread message

Pascal Friedrich

unread,
Jul 18, 2022, 11:33:22 AM7/18/22
to AMPL Modeling Language
Hello community,
hello Robert,

I have a question with regards two the following error message: 
C:\Users\Littl\Master Study\test.run, line 25 (offset 1111):
    syntax error
context:  for {u  >>> in  <<< ORDERS}
ampl: 

and my simple test code is the following: 
reset;
display "--------------------------------------------------------";
display "RESET";
model basic_model.mod;
option solver Gurobi;
problem Prob2_Knacksack_Problem :
#...following variables are included in the subset of this problem.
var_item_orientation, var_non_overlapping, var_allocation_point,
#...following objective is included in the subset of this problem.
Knacksack_Problem,
#...following constraints are included in the subset of this problem.
item_orientation_constraint_1, item_orientation_constraint_2, item_orientation_constraint_3, containtment_condition_1,
containtment_condition_2, non_overlapping_condition_1, non_overlapping_condition_2, non_overlapping_condition_3,
non_overlapping_condition_4, non_overlapping_condition_5;
let Items_Volume := 2;
let LOOPED_ORDERS := {1};
for {o in ORDERS: o < 200082526}
{
    reset data AXIS_CONTAINER,AXIS_ITEM, length_halved ,item_amount,ITEMS;
    display "current order:"&o ;
    #data ("load_data_order_"&o&".dat");
    display Items_Volume;
       let LOOPED_ORDERS := LOOPED_ORDERS union {o};
       display LOOPED_ORDERS;
       for {u in LOOPED_ORDERS}
       display "current order:"&u ;
           
}


Sadly AMPL does not allow me to utilize the second for loop inside the first one.
I don't know why.
Could you please provide me your guidance?

Best regards,
Pascal

AMPL Google Group

unread,
Jul 18, 2022, 12:05:00 PM7/18/22
to AMPL Modeling Language
The most common cause of a syntax error with "context: for {u >>> in <<< ORDERS}" is that you already have a param or var in the model with the name "u". This can be fixed by using some other name for the index in the inner loop.

If you need more help, however, then I suggest that you also post the model file, because that may provide more information about the reason for the error.


--
Robert Fourer
am...@googlegroups.com
{#HS:1952395487-111053#}

Pascal Friedrich

unread,
Jul 24, 2022, 8:21:35 PM7/24/22
to AMPL Modeling Language
Thank you Robert. I also figured this out by putting in another dummy indice. 
Reply all
Reply to author
Forward
0 new messages