# [AMPL 24428] Solve objective from a series of constraint

Hello. I am new to AMPL and I want to solve the same objective function but under different constraints where the only difference is MR[r], which is a vector. I have tried different variations similar to the one below, but it will only display r = 13. How do I display objective function for all r = 1…13?

My .mod file
minimize Objective {r in 1…13}:
sum {i in 1…n,j in 1…n} Mu[i]*Mu[j]*Cov[i,j];

subject to Constraint {r in 1…13}:
sum {i in 1…n} Mu[i]*ER[i] >= MR[r];

My .run file
for {r in 1…13}{
objective Objective[r];
solve;
printf ‘%8.5f’ , sum {i in 1…n} Mu[i]*ER[i];
}

The simplest was to do this is to define only one objective function and one constraint:

``````param MR {1..13};
param MR_val;

minimize Objective:
sum {i in 1..n,j in 1..n} Mu[i]*Mu[j]*Cov[i,j];

subject to Constraint:
sum {i in 1..n} Mu[i]*ER[i] >= MR_val;
``````

Then in each pass through the loop, assign one of the MR[r] values to MR_val:

``````for {r in 1..13} {
let MR_val := MR[r];
solve;
printf '%8.5f\n', sum {i in 1..n} Mu[i]*ER[i];
}
``````