ash25
ash25

Reputation: 113

How to write multiobjective function in Gurobi?

I am working with multi-objective functionality of Gurobi 7.0, I am having two objective functions:

  1. First minimizes the summation of product of Decision Variable with coefficient matrix-1
  2. Second minimizes the summation of product of Decision Variable with coefficient matrix-2

I am using hierarchical or lexicographic approach, in which i set a priority for each objective, and optimize in priority order. I can not use model.setObjective() function here because I will not be able to specify the objective function number and model will get confused. How can I write both of the objective functions?

Upvotes: 1

Views: 1910

Answers (1)

Romerito
Romerito

Reputation: 53

I've been testing this feature.

The documentation is not too much clear about the way we must set the objective functions. However, I did the following:

  • Define Variables associated with the objective function (cost etc.)
  • Then I changed the number of objectives m.NumObj = 3
  • Set the parameters for each objectives.

    m.setParam(GRB.Param.ObjNumber, 0)
    m.ObjNPriority = 5
    m.ObjNName = 'Z'
    m.ObjNRelTol = x/10.0
    m.ObjNAbsTol = 0
    Z.objN = 1.0
    
    m.setParam(GRB.Param.ObjNumber, 1)
    m.ObjNPriority = 4
    m.ObjNName = 'Custo'
    m.ObjNRelTol = x/10.0
    m.ObjNAbsTol = 0
    m.ObjNWeight = -1.0
    Custo.ObjN = 1.0
    
    m.setParam(GRB.Param.ObjNumber, 2)
    m.ObjNPriority = 10
    m.ObjNName = 'Hop'
    m.ObjNRelTol = x/10.0
    m.ObjNWeight = -1.0
    Hop.ObjN = 1.0
    

In my case, there are three objective functions (Z, Custo, Hop).

The parameter GRB.Param.ObjNumber is used to change the objective function you are working on.

Another thing that I concluded is that the the number of the objective is defined based on the order we define the variable associated to it (best of my knowledge).

Details about definition of the objective function

    Custo = m.addVar(vtype=GRB.INTEGER, name="Custo", obj=1)
    m.update ()

    expr  = []
    for k in xrange (1, KSIZE ):
        expr.append ( quicksum (var_y[ (l[0],l[1],k) ] * links[l][0] for l in links.keys()) )
        expr.append ( quicksum (var_y[ (l[1],l[0],k) ] * links[l][0] for l in links.keys()) )
    m.addConstr (quicksum (expr) == Custo, name= ' custo')
    m.update ()

Upvotes: 1

Related Questions