We don't know of any obvious reason why one of your loops should run much slower than the other. Can you send us a complete example, in AMPL syntax, that we can use to reproduce this behavior on our computers?
Note that the following loop should run faster than either of your examples:
for {i in 1..n: C[i] == 1} {
let A[i] := -1;
let B[i] := -1;
}
Bob Fourer
am...@googlegroups.com
=======
From:
am...@googlegroups.com [mailto:
am...@googlegroups.com] On Behalf Of
yik...@clarkson.edu
Sent: Sunday, November 12, 2017 9:23 PM
To: AMPL Modeling Language
Subject: [AMPL 15086] Code efficiency problem
Recently I observed a wired problem.
My code structure is like:
for {I=1...n}
{
if (C[i]==1)
{
A[i]=-1;
B[i]=-1;
}
}
The execution time of this piece of simple code is about 10 seconds. However, when I just change the order of two assignments like :
for {I=1...n}
{
if (C[i]==1)
{
B[i]=-1;
A[i]=-1;
}
}
the execution time is less than 1 second and the result keeps the same.