You can use AMPL's "named problem" feature for this situation. For example, define
problem P {i in 1..N}: x[i], y[i], fun[i], x_upper[i], y_upper[i];
and then solve with
for {i in 1..N} {
problem P[i];
solve;
}
Optionally you can combine "problem P[i]; solve;" into "solve P[i];". For a complete description of named problems see sections 14.4 and 14.5 in the AMPL book (beginning at
http://ampl.com/BOOK/CHAPTERS/17-solvers.pdf#page=30).
Bob Fourer
am...@googlegroups.com
=======
From:
am...@googlegroups.com [mailto:
am...@googlegroups.com] On Behalf Of Yongning Zhao
Sent: Friday, January 20, 2017 10:34 AM
To: AMPL Modeling Language
Subject: [AMPL 13404] Separate the objective and constraints into loops
Hi everyone, I have a high dimensional formulation, I want to solve the objectives separately with their corresponding constraints in a for loop. To make it clear to you, I simplify the original formulation:
param a {i in 1..N};
param b {i in 1..N};
minimize fun: sum { i in N } (x[i]-y[i]);
subject to x_upper { i in 1..N }: x[i]<=a[i];
subject to y_upper { i in 1..N }: y[i]<=b[i];
.......