简体   繁体   中英

Multiprocessing with Gurobi

I am trying to use multiprocessing for my optimization problem. I have a number of jobs (10, 20, 30) that need to be assigned to machines.

I am just inserting a rough outline of the optimization code, because it is way to long:

def solve(jobs):
    def load_data(jobs):
        df = pd.read_csv(path_jobs)
    def create_model():
        model = pg.Model(env)
        
        sets ...
        variables ...
        constraints...
        objective ...
       
        model.optimize()

        print(results of optimization) 
        export_results = results.to_csv

    

     results = create_model()
     

This is the code for the multiprocessing:

import multiprocessing as mp
if __name__ == '__main__':
   with mp.Pool() as pool:
      jobs= [10, 20, 30]
      result = pool.map(solve, jobs)
      print(result)

When executing the model with the multiprocessing it stops after "model.optimize". So it is not printing or exporting the results. Additionally, I get this error message:

MaybeEncodingError: Error sending result: '<multiprocessing.pool.ExceptionWithTraceback object at 0x7f7bd8fdb890>'. Reason: 'TypeError("can't pickle PyCapsule objects")'

I would be greatful for any ideas. The optimization problem itself is working perfectly.

> Try With this type of Method

from multiprocessing import Pool

def cube(x):
    return x * x * x


def main():
    threadObj = Pool(5)
    arr = [1, 2, 3, 4]
    outPut = []
    for loop in threadObj.map(cube, arr):
        outPut.append(loop)
    print(outPut)


main()

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