forked from airbus/discrete-optimization
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix problem of LargeNeighborhoodSearchRCPSP solver :
- problem was happening when trying to call the solver in an instance without addditional constraint and the notebook was failing (silently) - the bug is now fixed and a unit test is added
- Loading branch information
Showing
5 changed files
with
104 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright (c) 2024 AIRBUS and its affiliates. | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
import logging | ||
|
||
from discrete_optimization.generic_rcpsp_tools.large_neighborhood_search_scheduling import ( | ||
LargeNeighborhoodSearchScheduling, | ||
) | ||
from discrete_optimization.generic_tools.cp_tools import ParametersCP | ||
from discrete_optimization.rcpsp.rcpsp_model import RCPSPModel | ||
from discrete_optimization.rcpsp.rcpsp_parser import get_data_available, parse_file | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
|
||
|
||
def example_lns_solver(): | ||
files_available = get_data_available() | ||
file = [f for f in files_available if "j1201_1.sm" in f][0] | ||
rcpsp_problem: RCPSPModel = parse_file(file) | ||
solver = LargeNeighborhoodSearchScheduling(problem=rcpsp_problem) | ||
parameters_cp = ParametersCP.default() | ||
parameters_cp.time_limit_iter0 = 5 | ||
parameters_cp.time_limit = 2 | ||
results = solver.solve( | ||
nb_iteration_lns=100, | ||
skip_first_iteration=False, | ||
stop_first_iteration_if_optimal=False, | ||
parameters_cp=parameters_cp, | ||
nb_iteration_no_improvement=200, | ||
max_time_seconds=100, | ||
) | ||
sol, fit = results.get_best_solution_fit() | ||
assert rcpsp_problem.satisfy(sol) | ||
|
||
|
||
if __name__ == "__main__": | ||
example_lns_solver() |
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
35 changes: 35 additions & 0 deletions
35
tests/rcpsp/solver/test_large_neighborhood_search_solver.py
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,35 @@ | ||
# Copyright (c) 2024 AIRBUS and its affiliates. | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
import pytest | ||
|
||
from discrete_optimization.generic_rcpsp_tools.large_neighborhood_search_scheduling import ( | ||
LargeNeighborhoodSearchScheduling, | ||
) | ||
from discrete_optimization.generic_tools.cp_tools import ParametersCP | ||
from discrete_optimization.rcpsp.rcpsp_model import RCPSPModel | ||
from discrete_optimization.rcpsp.rcpsp_parser import get_data_available, parse_file | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"file_name", | ||
["j1201_1.sm", "j1010_9.mm"], | ||
) | ||
def test_lns_solver(file_name): | ||
files_available = get_data_available() | ||
file = [f for f in files_available if file_name in f][0] | ||
rcpsp_problem: RCPSPModel = parse_file(file) | ||
solver = LargeNeighborhoodSearchScheduling(problem=rcpsp_problem) | ||
parameters_cp = ParametersCP.default() | ||
parameters_cp.time_limit_iter0 = 5 | ||
parameters_cp.time_limit = 2 | ||
results = solver.solve( | ||
nb_iteration_lns=100, | ||
skip_first_iteration=False, | ||
stop_first_iteration_if_optimal=False, | ||
parameters_cp=parameters_cp, | ||
nb_iteration_no_improvement=50, | ||
max_time_seconds=20, | ||
) | ||
sol, fit = results.get_best_solution_fit() | ||
assert rcpsp_problem.satisfy(sol) |