I do not understand your pseudocode. What are the min/max functions? Are i and j simply a nesting of foreach loops? It might help to write a function that the condition you want, and then we can show you have to turn it into a constraint.
Thanks for your response.
Exactly, i and j are just a nesting of foreach.
Assume there is an auxiliary array storing the difference between respective elements of pos and neg arrays. Something like:
foreach(aux[i]) aux[i] = pos[i] - neg[i];
Then, the third constraint could be expressed in pseudocode as:
The ‘with’ trick seems to be fine. To meet my requirements I guess it should be modified a bit:
constraint c3 {
(pos.max() with (pos[item.index] - neg[item.index]) - neg.max() with (pos[item.index] - neg[item.index]))
- (pos.min() with (pos[item.index] - neg[item.index]) - neg.min() with (pos[item.index] - neg[item.index]))
<= relative_c; }
However, even modified the solution is getting a compile error. I think the issue is that min/max functions return a queue as a result, so it cant be used further in constraint. I have a min example on Eda Playground.
Sorry, I always forget that min/max return a queue in the case that the input array is empty. I’ll have to think some more about it, but at least I now know exactly what you are looking to do.