简体   繁体   中英

With gurobi how can I constraint the domain of a variable in a set of value

This is how I use addVar to add variable into the model:

my_set[j, t] = self.m.addVar(vtype=GRB.INTEGER, lb=min_value, ub=max_value, name='test')

And this can only constraint the value as an integer falling between min_value and max_value, but actually I'd like to constraint the possible value in certain set of integers. How can I make it?

I don't know if it is directly possible (this is not possible in standard ILP, so maybe as an extension of gurobi), but you can add some constraints to your program. Assuming the variable you want to constrained is y and the set of variable is D y = {v 1 , v 2 , ..., v |D y | } , you could add the following x i variables and constraints:

  • y = x i for i in 1 ... |D y |
  • sum (x i for i in 1 ... |D y |) = 1
  • x i = 0 or 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM