Question: Suppose I have a set of weeks

```
{string} weeks ={"Week 1","Week 2","Week 3","Week 4"}

```

Then I define a variable for each of the weeks

```
dvar boolean x[weeks];

```

If I want to, for all `w in Weeks`, sum over all weeks up to the week w, how can you do that? What I want to do is the following, which does not work as I cannot compare strings like this

```
forall ( w in weeks )
{
  sum ( ww in weeks : ww<=w ) x[ww] >= rhs[w];
}

```

Where `rhs[w]` is just some right hand side.

Answer: 
By coincidence I stumbled across a page in the [OPL manual](https://www.ibm.com/docs/sv/icos/12.9.0?topic=functions-ord), describing the function `ord()` which seems to be a way forward. `ord(Set,element)` returns the position of the element in the set. Hence the code in the question should be

```
forall ( w in weeks )
{
  sum ( ww in weeks : ord(weeks,ww)<=ord(weeks,w) ) x[ww] >= rhs[w];
}

```
In fact you can compare strings in OPL so

```
{string} weeks ={"Week 1","Week 2","Week 3","Week 4"};

float rhs[weeks]=[1,2,3,4];

dvar boolean x[weeks];

subject to
{
  forall ( w in weeks )
   {
     sum ( ww in weeks : ww<=w ) x[ww] >= rhs[w];
   }
}

execute
{
  for(var w1 in weeks) for(var w2 in weeks) if (w1<=w2) writeln(w1," <= ",w2);
}

```

works fine and gives

```
Week 1 <= Week 1
Week 1 <= Week 2
Week 1 <= Week 3
Week 1 <= Week 4
Week 2 <= Week 2
Week 2 <= Week 3
Week 2 <= Week 4
Week 3 <= Week 3
Week 3 <= Week 4
Week 4 <= Week 4

```