Can you vectorize Decision Variable and Constraint generation in Python

70 views
Skip to first unread message

taylor leonard

unread,
Mar 1, 2019, 9:55:01 AM3/1/19
to Gurobi Optimization
Hello, 

I generate a large number of iterations of various MIPs and am curious if there is vectorized code in Python for generating the Decision Variables and Constraints, or if they all need to be looped through individually.

Thank you, 

Taylor

Robert Luce

unread,
Mar 4, 2019, 9:33:31 AM3/4/19
to Gurobi Optimization
Hello Taylor,

you can create whole batches of decision variables in gurobipy using the Model.addVars() function.  If you can phrase batches of your constraints as a generator expression, you can add them all at once to the model using Model.addConstrs() function.

Best,

Robert

taylor leonard

unread,
Mar 4, 2019, 10:13:52 AM3/4/19
to Gurobi Optimization
Hi Robert, 

Thank you for the reply and the solution, I should have been able to figure that out.  I've already implemented it and it works great.  

Thank you, 

Taylor
Reply all
Reply to author
Forward
0 new messages