Form a new variable from the subset of original variable (maximum values)
AnsweredHello,
I have the code that outputs achieved prices for multiple generators for each hour(period) and year in modelling horizon.
Is there a way to form a new variable (meritorder[period, year]) that will include only subset of the original variable (gencosth[genco, period, year]), but include only the maximum values for each hour and year?
Pseudocode would look something like this:
merit_order =ucp.addConstrs((gencosth[genco, period, year] for genco in units)==
meritorder[period, year]
for period in periods for year in years)
-
Hi Luka,
you may be after generating one variable for each subset for which you look for a maximum and then adding a max general constraint.
I would try something along the lines of:
meritorder = gp.tupledict()
for period in periods:
for year in years:
meritorder[period, year] = ucp.addVar(vtype="C", name=f"meritorder_{period}_{year}") # I assume the variables are continuous
ucp.addConstr(meritorder[period, year] == gp.max_([gencosth[genco, period, year] for genco in units]))Hope this helps.
Best regards
Jonasz0 -
Thank you very much! It seams to work.
With the code you presented, I got an error "NameError: name 'max_' is not defined".
Therefore, I had to call the "max_()" function via Gurobipy and the final part of the script is:
meritorder = gp.tupledict()
for period in periods:
for year in years:
meritorder[period, year] = ucp.addVar(vtype="C", name=f"meritorder_{period}_{year}")
ucp.addConstr(meritorder[period, year] == gp.max_([gencosth[genco, period, year] for genco in units]))
Best regards,
Luka
0 -
Thanks for pointing this out - my code was meant to be a rough guideline. Now, we have a correct piece of code for future reference.
Best regards
Jonasz0
Please sign in to leave a comment.
Comments
3 comments