Skip to main content

How to make a deep copy of a linear expression using gurobipy

Answered

Comments

1 comment

  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    The best way to make a copy of your objective is to generate an additional one during construction. For example

    [...]
    origobj = gp.LinExpr([1,2,-1],[x,y,z])
    modobj = gp.LinExpr([1,2,-1],[x,y,z])
    model.setObjective(modobj)
    # do something with current objective
    # after finishing, set the objective to origobj
    model.setObjective(origobj)

    Best regards, 
    Jaromił

    0

Please sign in to leave a comment.