Skip to main content

Finding all optimal solution for a Multi-objective Optimization

Answered

Comments

3 comments

  • Marika Karbstein
    Gurobi Staff Gurobi Staff

    Hi Purnima,

    You need to set the parameter for each objective. If you have 2 objectives, you can access the environment for both objectives and then set parameters as follows

    env0 = m.getMultiobjEnv(0)
    env1 = m.getMultiobjEnv(1)
    # setting pool parameter for first objective
    env0.setParam('PoolSearchMode', 2)
    env0.setParam('PoolSolutions', 10)
    env0.setParam('PoolGap', 1)
    # setting pool parameter for second objective
    env1.setParam('PoolSearchMode', 2)
    env1.setParam('PoolSolutions', 10)
    env1.setParam('PoolGap', 1)
    # allow the complete pool to contain 10 solutions from first objective
    # and 10 solutions from second objective
    m.setParam('PoolSolutions', 20)

    In this way, Gurobi will search for 10 solutions when optimizing the first objective and 10 solutions when optimizing the second objective. Note that the model with the second objective also contains the constraint for the allowed degradation of the first objective.

    When checking the objectives for all solutions, you probably need to set the parameter ObjNumber in a similar way as you set SolutionNumber.

    I hope this helps,
    Marika

    0
  • Purnima Subramaniam
    Gurobi-versary
    Conversationalist
    First Question

    Hi Marika,

    Thank you for your response. It's still not clear to me on how to use ObjNumber to print all the values of optimal solution for both Obj1 and Obj2.

    m.optimize()
    m.solCount

    for w in range(m.SolCount):
        m.Params.SolutionNumber = w
        print([var.X for var in Obj1.getValue()])
        print([var.X for var in Obj2.getValue()])
        

    If I try to run this piece of code , I get this error : AttributeError: 'float' object has no attribute 'X'

    Could help me figure out how to print all the solution values ?

     

    Thanks,

    Purnima

    0
  • Marika Karbstein
    Gurobi Staff Gurobi Staff

    Hi Purnima,

    You can print the objective values as follows

    for w in range(m.SolCount):
        m.Params.SolutionNumber = w
      # consider all objectives for this solution
        for i in range(2):
            m.Params.ObjNumber = i
          # value of objective i
            print(m.ObjNVal)
            
        # print all variable values for this solution
        m.printAttr('Xn')

    Best regards,
    Marika

    0

Please sign in to leave a comment.