2

I want to add the following constraint:

@addConstraint(m, sum{sum{x[:alpha, d, s], s in S}, d in D} >= 5)

where x is a decision variable and

D = [1:50]

but I want the sum to be calculated only for d less than 10.
Is there a built-in way or do I have to find some workaround?

HAL9000
  • 3,562
  • 3
  • 25
  • 47

2 Answers2

4

Should be able to just do d in D; d < 10, i.e.

@addConstraint(m, sum{sum{x[:alpha, d, s], s in S}, d in D; d < 10} >= 5)

For completeness, here is the link to the relevant section of the manual, which could be structured better. We'll work on that!

IainDunning
  • 11,546
  • 28
  • 43
0

I'm not familiar with your application, but some simple arithmetic can give you the sum, assuming that the elements are unique consecutive integers, which you didn't clarify in your question. This was supposedly discovered by Gauss:

The sum of n consecutive integers (starting at 1) is given by: (n(n + 1))/2

Odds are that this is faster and simpler than any built in summation function, but again, there are constraints which your question didn't clarify.

user2105505
  • 686
  • 1
  • 9
  • 18
  • Thank you, I added a description of x, which is a decision variable, so your solution is not feasible, sorry. – HAL9000 Jul 20 '14 at 16:00