Goodmorning.
I am trying to integrate a new constraint inside TEMOA, a python / pyomo based energy system optimization model. The repository is available on GitHub at the following link: https://github.com/TemoaProject/temoa
At this repository, I have added in the model definition file the following elements:
In temoa_model:
M.land_types = Set()
M.LandArea = Param(M.regions, M.land_types, M.time_optimize)
M.LandUseIntensity = Param(M.regions, M.land_types, M.tech_all)
M.LandUseConstraint = Constraint(
M.regions, M.time_optimize, M.land_types,
rule=LandUse_Constraint
)
In temoa_rules:
def LandUse_Constraint(M,r,p,l):
return (0,
sum(
M.V_Capacity[r, S_t, v] * value(M.LandUseIntensity[r, l, S_t]) * 1e10 + 1e10
for S_t in M.LandUseIntensity.sparse_iterkeys()
if (r, p, S_t) in M.processVintages.keys()
for v in M.processVintages[r, p, S_t]
), value(M.LandArea[r, l, p]))
I have inserted 1e10 sum and multiplier, to force the constraint to be false. Neverthless, the model totally neglect the constraint. Is a problem of syntax? Where i have to look to find the core problem?
For t/s purposes, try inserting a line to print the constraint and see if the math looks right.
You want to do this after the model is instantiated with data. So, in the temoa_run.py
file, you can do that at line #354 after the instance is created. Try inserting this line, which will pprint the offending constraint to the terminal:
self.instance.LandUse_Constraint.pprint()
If that looks "believable" you should check what it looks like with the values plugged in after the solve. You can do that around line #384 after the solve command with the "display" pyomo command which plugs in values. Of course, backing up a bit, you should always check the solver status FIRST before looking at this. If it doesn't say "optimal", don't bother, it's gibberish.
self.instance.LandUse_Constraint.display()
Edit: just thought on this again.... It actually doesn't matter where you do the .pprint()
as it is not affected by solve, so you could put them both in the latter spot, but I'd still pop it in earlier so you don't have to wait for solve or if it gets hung up there to inspect.