I am trying to implement control neutrality constraint. That is, a constraint that requires that if some generator increased power that others decrease (sum is zero).
In this demo test case there are only two variables with data stored in data.cp_gen which is 2 element vector of NamedTuples.
con_en_neutrality1 = constraint(w,1;)
con_en_neutrality2 = constraint!(w, con_en_neutrality1, Pgen[v.i] - v.pg for v in data.cp_gen)
Solution reveals that the constraint is not satisfied despite full solver convergence (using CPU backend).
sum([solution(res,Pgen)[v.i]-v.pg for v in data.cp_gen])
results in -0.031260009999725696
Could you share the full code? One issue I notice is that constraint! needs to be expressed in terms of iterator of Pair. So you might need to make changes, e.g.,
con_en_neutrality2 = constraint!(w, con_en_neutrality1, v.i => Pgen[v.i] - v.pg for v in data.cp_gen)
Unfortunately I can not share the full code (hundreds of lines of code), but this part is very isolated model wise. The issue is only with this constraint. If I remove it, I get exactly the same result with some of my other ampl codes.
I tried using
con_en_neutrality2 = constraint!(w, con_en_neutrality1, 1 => Pgen[v.i] - v.pg for v in data.cp_gen)
as neutrality constraint is single constraint, but I am receiving error:
LoadError: MethodError: objects of type Int64 are not callable
Maybe you forgot to use an operator such as *, ^, %, / etc. ?
I used your approach, but had to put constant 1 into named tuple. Using 1 directly results in an error as shown in my last reply. Not sure why it does not, or should it accept direct 1.
con_en_neutrality2 = constraint!(w, con_en_neutrality1, v.one => Pgen[v.i] - v.pg for v in data.cp_gen)