0

I have an array a of type int [0,0,0,0,0] of length l

I want to calculate a sum of all elements with odd indexes to use in a downstream constraint, here some "pseudo" MiniZinc code:

s = sum(i in 1..l | i mod 2 == 0) (a[i]);

solve maximize(s);

How can this be done?

Community
  • 1
  • 1
Romeo Kienzler
  • 3,373
  • 3
  • 36
  • 58

1 Answers1

1

I don't know what a "downstream constraint" is, but you can use "where" to add a condition in the loop:

 constraint
     s = sum(i in 1..l where i mod 2 == 0) (a[i])
 ;
hakank
  • 6,629
  • 1
  • 17
  • 27
  • With "downstream constraint" I mean a constraint basically using "s" as a parameter. Thanks for your answer, it works fine! – Romeo Kienzler Sep 22 '15 at 16:34