Skip to main content

Form a new variable from the subset of original variable (maximum values)

Answered

Comments

3 comments

  • Jonasz Staszek
    • Community Moderator Community Moderator
    • Gurobi-versary
    • Thought Leader
    • First Question

    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
    Jonasz

    0
  • Luka Herc
    • Gurobi-versary
    • First Comment
    • First Question

    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
  • Jonasz Staszek
    • Community Moderator Community Moderator
    • Gurobi-versary
    • Thought Leader
    • First Question

    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
    Jonasz

    0

Please sign in to leave a comment.