Skip to main content

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

Answered

Comments

4 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support.
  • Jonasz Staszek
    • 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
    • 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

Post is closed for comments.