Gurobi Multiprocessing
進行中I am trying to implement multiprocessing to run 9 scenarios in parallel. I have a single model for which constraints are changed based on each scenario. I am trying to run these scenarios in parallel in every iterations. I found the following code from Silke Horn. However, I need to run these scenarios iteratively and this code requires defining model for each iterations. Is there another way where I can define a model once before iteration starts and use this for multiprocessing?
import multiprocessing as mp
import gurobipy as gp
def solve_model(input_data):
with gp.Env() as env, gp.Model(env=env) as model:
# define model
model.optimize()
# retrieve data from model
if __name__ == '__main__':
with mp.Pool() as pool:
pool.map(solve_model, [input_data1, input_data2, input_data3]
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Sanjeev,
It's not entirely clear to me what you are asking for. If the scenarios are to be run iteratively then they cannot be run parallel.
You might be interested in Gurobi's multi-scenario feature: Multiple Scenarios (gurobi.com)
Concerning your original question: It is not possible to share the same model across multiple seeds. You should always open a separate environment for each new thread.
Cheers,
Matthias0 -
Thank you Matthias for your comment. I am implementing Benders Decomposition algorithm. I need to solve sub problem 9 times in each iteration till the stopping criteria is met. Solving subproblem for s=1 is independent of solving sub problem for s=2. Following is my code snippet.
Start
mdlSP = gurobipy.model('Model')
r=1
for s in range(1,10):
mdlSP.setAttr("RHS",constraint,newvalue[r,s])
model.update()
model.optimize()
Check for stopping criteria
r=r+1
End
Thanks,
Sanjeev
0
投稿コメントは受け付けていません。
コメント
3件のコメント