error in "repeat until" expression

20 views
Skip to first unread message

nico.te...@gmail.com

unread,
Dec 3, 2016, 9:36:53 AM12/3/16
to AMPL Modeling Language
Dear Bob,

I'd like to calculate the minimum production quantity with respect to a fill rate constraint.

However, I want my algorithm to run until the target service level is reached.

Algorithm:


model C:\AMPL\qopt.mod;
for {tau in Ruestperioden} {    
 
               
 let q[tau] := 0;       
 let qstrich[tau] := -epsilon;

     repeat until BetaLos{t in 1..T} = BetaLosStern {
     repeat while (q[tau] - qstrich[tau]) >= epsilon  
  {
 
 let {t in tau..T: t = tau} I[t] := I[t-1] + q[tau] - D[t];
 let {t in tau..T: t > tau} I[t] := I[t-1] - D[t];
 let {t in 1..T: tau <= t} Iprod[t] := -min(0,I[t-1] + q[tau]);
 let {t in 1..T} Iend[t] := -min(0,I[t]);
 let {t in 1..T} F[t] := Iend[t]-Iprod[t];
 let {t in 1..T: tau <= t} BetaLos[t] := 1 - ((sum{i in tau..t} F[i]) / (sum{i in tau..t} D[i]));

   let qstrich[tau] := q[tau];
   let {t in 1..next(tau, Ruestperioden) -1: tau +1 <= T} deltabeta := BetaLosStern - BetaLos[t]; # evtl 2 Indizes Für BetaLos

 if (deltabeta > 0) then {
     let {t in 1..next(tau, Ruestperioden) -1: tau +1 <= T} q[tau] := q[tau] + deltabeta * D[t];               
 }            }               }}

option solver cplex;
solve;
display q > C:\AMPL\qopt.sol;


Error message:

C:\AMPL\qopt.run, line 13 (offset 236):
 syntax error
context:  repeat until  >>> {BetaLos{ <<< t in 1..T} = BetaLosStern} {



BetaLos was defined as BetaLos{t in 1..T} in the .mod-file

Do you have any idea, how I could solve this problem?

Thanks a lot in advance, best regards.

Robert Fourer

unread,
Dec 4, 2016, 7:02:47 PM12/4/16
to am...@googlegroups.com
"BetaLos{t in 1..T} = BetaLosStern" gives a syntax error, because in that context you can only use an indexing expression like {t in 1..T} together with an operator, such as "sum".

I think you may be trying to create a "for" loop that also has an "until" condition. In that case you need to specify the condition by putting an explicit "break" statement in the loop. The general form would be:

for {t in 1..T} {
if BetaLos[t] = BetaLosStern then break;
...
...
}

By default "break" terminates the innermost loop in which it appears; there's more in chapter 13.5 of the AMPL book (http://ampl.com/BOOK/CHAPTERS/16-script.pdf#page=12).

Bob Fourer
am...@googlegroups.com

=======
Reply all
Reply to author
Forward
0 new messages