AnswerBun.com

Decision variable transformation in Gurobi

Operations Research Asked on December 5, 2021

I’m trying to find a way of setting the values of a binary MVar object (which is my decision variable) of size n to {-1,1}. Right now I have a vector that can either take values 0 or 1 (due to binary condition), but instead of 0 and 1, I need the variable to take the values -1 and 1. This is what I tried doing, but I don’t think it’s working:

x = m.addMVar(shape = n, vtype = GRB.BINARY, name = 'X') #My decision variable

y = m.addMVar(shape = n, vtype = GRB.INTEGER, name = 'Y') #Auxiliar decision variable

m.addConstr(y == 2*x - 1) #Transformation from {0,1} to {-1,1}

m.setObjective(#function with y as decision variable)

2 Answers

You need to change the lower bound of the auxiliary variables, i.e.,

y = m.addMVar(shape = n, lb = -1, vtype = GRB.INTEGER, name = 'Y').

Note that variables in Gurobi are usually defined between 0 and infinity except binary.

Answered by Sebastian Kraul on December 5, 2021

If the shape n is for example a list of indices, then you need to index the variables when you add the constraints and loop through and each index:

m.addConstrs(y[i] == 2*x[i] - 1 for i in n)

Also note the “s” added to the addConstrs.

Answered by Mason on December 5, 2021

Add your own answers!

Related Questions

CPLEX MIP warm start seems slow down the program?

1  Asked on August 19, 2021 by mengfan-ma

   

Two M/M/1 queues working independently

0  Asked on August 19, 2021 by cookiemonster

 

Scheduling with setup cost

0  Asked on August 19, 2021 by dirk-nachbar

 

MINLP Solution same as Global Optimum?

2  Asked on August 19, 2021 by clement

   

Meta papers on operations research

2  Asked on August 19, 2021 by luke599999

 

How can I use warm start in C#

1  Asked on August 19, 2021 by fhm-ider

   

Feasible sets represented as point clouds

1  Asked on August 19, 2021 by harry-cohen

   

Is this the same as Agent Based DES or something different?

0  Asked on August 19, 2021 by brendan-hill

 

Is there any OR way to solve this problem?

3  Asked on August 19, 2021 by samiczy

 

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP