-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solve problem with multi-threads (#918)
* 1. model optimize without gil 2. solveFirstInterruptOthers 3. add copy model method 4. add copy model solution 5. add some Solution methods * 1. model optimize without gil 2. model addOrigVarsConssObjectiveFrom 3. add some Solution methods * Update src/pyscipopt/scip.pxi Co-authored-by: João Dionísio <[email protected]> * remove addOrigVarsConssObjectiveFrom * rename getSolOrigin to getOrigin --------- Co-authored-by: Light1_Lee <[email protected]> Co-authored-by: João Dionísio <[email protected]>
- Loading branch information
1 parent
c24e9df
commit 6876af9
Showing
7 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from concurrent.futures import ThreadPoolExecutor, as_completed | ||
from pyscipopt import Model | ||
from helpers.utils import random_mip_1 | ||
|
||
N_Threads = 4 | ||
|
||
|
||
def test_optimalNogil(): | ||
ori_model = random_mip_1(disable_sepa=False, disable_huer=False, disable_presolve=False, node_lim=2000, small=True) | ||
models = [Model(sourceModel=ori_model) for _ in range(N_Threads)] | ||
for i in range(N_Threads): | ||
models[i].setParam("randomization/permutationseed", i) | ||
|
||
ori_model.optimize() | ||
|
||
with ThreadPoolExecutor(max_workers=N_Threads) as executor: | ||
futures = [executor.submit(Model.optimizeNogil, model) for model in models] | ||
for future in as_completed(futures): | ||
pass | ||
for model in models: | ||
assert model.getStatus() == "optimal" | ||
assert abs(ori_model.getObjVal() - model.getObjVal()) < 1e-6 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters