Gurobi objective with python dictionary values

前端 未结 1 2016
醉话见心
醉话见心 2020-12-22 00:15

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 vari

相关标签:
1条回答
  • 2020-12-22 01:08

    For a somewhat complex causal chain d[(x,y)] in your code is equivalent to d[(0,1)], so the constant -5 winds up being your objective function. The reasons are

    • gurobi.Var has __hash__ defined
    • gurobi.Var has __cmp__ defined. It always returns a truthy object
    • In your case, x and y have hash values of 0 and 1
    • The python dictionary lookup algorithm resolves d[(x,y)] to d[(0,1)]

    What you are trying to do doesn't fit into the integer programming framework. The best way to put this into gurobi is to add indicator variables that x and y take on specific values.

    0 讨论(0)
提交回复
热议问题