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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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.