Search code examples
ampl

Sum over constrained set element syntax error in AMPL


I have a model for an optimization problem using three different sets of ordered pairs. Using this constraint:

subject to Constraint8 {t in T, j in J, a in A}: 
    sum{i in I: (i,j) in LINKS} l[i,t,a] >= sum{v in V, (ih,jh) in REV:(ih,j) not in LINKS} x[ih,j,v,t,a]+1;    

Actually works and gives a correct solution. I want to alter this constraint though, so I comment it out, and then write the modified version:

subject to Constraint8 {t in T, j in J, a in A}:
    sum{i in I: (i,j) in LINKS} l[i,t,a] >= sum{g in T: g <= t, v in V, (ih,jh) in REV: (ih,j) not in LINKS} x[ih,j,v,g,a] +1;  

(with the difference that x is now summed over the set T as well, however on the element g in T: g <= t. However, AMPL does not seem to like this and this gives a syntax error. I've been trying it on some different "places" within the sum, but it does not work.

Does anyone have a clue regarding this error?


Solution

  • In AMPL, as well as in mathematical notation, you should specify the "such that" condition at the end of the indexing expression:

    subject to Constraint8 {t in T, j in J, a in A}:
      sum{i in I: (i,j) in LINKS} l[i,t,a] >=
        sum{g in T, v in V, (ih,jh) in REV: g <= t and (ih,j) not in LINKS}
          x[ih,j,v,g,a] + 1;