Gurobi objective with python dictionary values
问题 I am using Gurobi 6.0 with Python 2.7. I am curious to know if Gurobi allows the objective function to have values coming from a dictionary with indices of the decision variables. Attaching the code: from gurobipy import * d = { (0, 0): 0, (0, 1): -5, (1, 0): 4, (1, 1): 2, (2, 0): 0, (0, 2): 10 } m = Model() x = m.addVar(vtype=GRB.INTEGER) y = m.addVar(vtype=GRB.INTEGER) m.update() m.addConstr(x + y <= 2) m.setObjective(d[(x, y)], GRB.MAXIMIZE) m.optimize() print m.objVal print x.x print y.x