0

Is there an easy way to apply a condition into a sum in OPL or to get around this problem ?

For example is it possible to do something like :

 forall (i in Factories)
    forall( j in Time)
        Stock[i][j] == sum (i_ in Factories where j-LeadTime[i_][i]>0) (expression)

The only way I found to get around this problem is to extend my dataset in order to avoid out of range exception but in my case that don't make any sense so I would like to apply a condition into the sum before.

David Nehme
  • 21,379
  • 8
  • 78
  • 117
Soji
  • 177
  • 1
  • 5
  • 17
  • No LeadTime is not a variable. I don't have any errors because I am not using the code above. This code is incorrect as you can't use a where or if conditions into a sum but my question is : Is there a way to do it ? – Soji Jul 24 '14 at 13:41

1 Answers1

3

The : operator is the correct way to add conditions to a sum statement. You want something like the following.

 forall (i in Factories)
    forall( j in Time)
        Stock[i][j] == sum (i_ in Factories : j-LeadTime[i_][i]>0) (expression)

where isn't part of the OPL language.

David Nehme
  • 21,379
  • 8
  • 78
  • 117