'How to write if condition in gurobi 9.5?

Any example for using if statement in gurobi 9.5 ?

its my first time to use gurobi. I am trying to implement the following code via if statement however i keep getting error or infeasible model.

m.addConstrs(p2g[t]==0 for t in range(A) if pv_generation[t]<=load[t] pfor t in range(A) )

m.addConstrs(p2g[t]==p2g[t] for t in range(A) if pv_generation[t]>load[t] for t in range(A))

I've checked the gurobi documentation but it doesn't provide any clear example



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source