From 7a4549d89633f960dcf7cf06163672fa40119237 Mon Sep 17 00:00:00 2001 From: heatingma Date: Tue, 3 Dec 2024 02:50:33 +0800 Subject: [PATCH] update tests --- codecov.yml | 3 +- .../mis_example_cnf/mis/solution/results.json | 16 +++--- tests/test_generator.py | 51 +++++++++---------- tests/test_solver.py | 30 +---------- 4 files changed, 37 insertions(+), 63 deletions(-) diff --git a/codecov.yml b/codecov.yml index 444e445..fcc03d1 100644 --- a/codecov.yml +++ b/codecov.yml @@ -15,4 +15,5 @@ coverage: ignore: - ml4co_kit/solver/tsp/pyconcorde/setup.py - ml4co_kit/learning/** - - ml4co_kit/solver/tsp/concorde_large.py \ No newline at end of file + - ml4co_kit/solver/tsp/concorde_large.py + - ml4co_kit/utils/tsplib95 \ No newline at end of file diff --git a/tests/data_for_tests/solver/mis/mis_example_cnf/mis/solution/results.json b/tests/data_for_tests/solver/mis/mis_example_cnf/mis/solution/results.json index b68caf3..a797d67 100644 --- a/tests/data_for_tests/solver/mis/mis_example_cnf/mis/solution/results.json +++ b/tests/data_for_tests/solver/mis/mis_example_cnf/mis/solution/results.json @@ -406,8 +406,8 @@ 1205, 1206 ], - "solution_time": 2.69139, - "total_time": 10.091511537786573, + "solution_time": 3.95078, + "total_time": 10.109251855872571, "vertices": 403 }, "CBS_k3_n100_m418_b10_927": { @@ -832,8 +832,8 @@ 1249, 1253 ], - "solution_time": 2.94431, - "total_time": 10.111215078271925, + "solution_time": 4.32438, + "total_time": 10.103654897771776, "vertices": 418 }, "CBS_k3_n100_m429_b50_1": { @@ -1269,8 +1269,8 @@ 1282, 1285 ], - "solution_time": 2.66076, - "total_time": 10.174272296018898, + "solution_time": 3.94799, + "total_time": 10.140570020768791, "vertices": 429 }, "CBS_k3_n100_m449_b70_15": { @@ -1726,8 +1726,8 @@ 1342, 1346 ], - "solution_time": 3.19248, - "total_time": 10.16194302868098, + "solution_time": 4.51694, + "total_time": 10.111564490944147, "vertices": 449 } } \ No newline at end of file diff --git a/tests/test_generator.py b/tests/test_generator.py index 5dfc2ce..74ccf98 100644 --- a/tests/test_generator.py +++ b/tests/test_generator.py @@ -5,7 +5,6 @@ import shutil from ml4co_kit import * -GUROBI_LICENCE = "your gurobi licence" GUROBI_TEST = False @@ -218,7 +217,7 @@ def _test_mcl_gurobi( os.makedirs(save_path) # solver - solver = MClGurobiSolver(licence_path=GUROBI_LICENCE, time_limit=5.0) + solver = MClGurobiSolver(time_limit=5.0) # create MClDataGenerator using gurobi solver mcl_data_gurobi = MClDataGenerator( @@ -243,10 +242,10 @@ def test_mcl(): """ Test MCLDataGenerator """ - _test_mcl_gurobi(nodes_num_min=600, nodes_num_max=700, data_type="er") - _test_mcl_gurobi(nodes_num_min=600, nodes_num_max=700, data_type="ba") - _test_mcl_gurobi(nodes_num_min=600, nodes_num_max=700, data_type="hk") - _test_mcl_gurobi(nodes_num_min=600, nodes_num_max=700, data_type="ws") + _test_mcl_gurobi(nodes_num_min=50, nodes_num_max=100, data_type="er") + _test_mcl_gurobi(nodes_num_min=50, nodes_num_max=100, data_type="ba") + _test_mcl_gurobi(nodes_num_min=50, nodes_num_max=100, data_type="hk") + _test_mcl_gurobi(nodes_num_min=50, nodes_num_max=100, data_type="ws") ############################################## @@ -268,7 +267,7 @@ def _test_mcut_gurobi( os.makedirs(save_path) # solver - solver = MCutGurobiSolver(licence_path=GUROBI_LICENCE, time_limit=5.0) + solver = MCutGurobiSolver(time_limit=5.0) # create MCutDataGenerator using gurobi solver mcut_data_gurobi = MCutDataGenerator( @@ -293,10 +292,10 @@ def test_mcut(): """ Test MVCDataGenerator """ - _test_mcut_gurobi(nodes_num_min=600, nodes_num_max=700, data_type="er") - _test_mcut_gurobi(nodes_num_min=600, nodes_num_max=700, data_type="ba") - _test_mcut_gurobi(nodes_num_min=600, nodes_num_max=700, data_type="hk") - _test_mcut_gurobi(nodes_num_min=600, nodes_num_max=700, data_type="ws") + _test_mcut_gurobi(nodes_num_min=50, nodes_num_max=100, data_type="er") + _test_mcut_gurobi(nodes_num_min=50, nodes_num_max=100, data_type="ba") + _test_mcut_gurobi(nodes_num_min=50, nodes_num_max=100, data_type="hk") + _test_mcut_gurobi(nodes_num_min=50, nodes_num_max=100, data_type="ws") ############################################## @@ -316,7 +315,7 @@ def _test_mis_kamis( os.makedirs(save_path) # create MISDataGenerator using KaMIS solver - solver = KaMISSolver(time_limit=5.0) + solver = KaMISSolver(time_limit=1.0) if recompile_kamis: solver.recompile_kamis() mis_data_kamis = MISDataGenerator( @@ -352,7 +351,7 @@ def _test_mis_gurobi( os.makedirs(save_path) # solver - solver = MISGurobiSolver(licence_path=GUROBI_LICENCE, time_limit=5.0) + solver = MISGurobiSolver(time_limit=5.0) # create MISDataGenerator using gurobi solver mis_data_gurobi = MISDataGenerator( @@ -378,16 +377,16 @@ def test_mis(): Test MISDataGenerator """ _test_mis_kamis( - nodes_num_min=600, nodes_num_max=700, data_type="er", recompile_kamis=True + nodes_num_min=50, nodes_num_max=100, data_type="er", recompile_kamis=True ) - _test_mis_kamis(nodes_num_min=600, nodes_num_max=700, data_type="ba") - _test_mis_kamis(nodes_num_min=600, nodes_num_max=700, data_type="hk") - _test_mis_kamis(nodes_num_min=600, nodes_num_max=700, data_type="ws") + _test_mis_kamis(nodes_num_min=50, nodes_num_max=100, data_type="ba") + _test_mis_kamis(nodes_num_min=50, nodes_num_max=100, data_type="hk") + _test_mis_kamis(nodes_num_min=50, nodes_num_max=100, data_type="ws") - _test_mis_gurobi(nodes_num_min=600, nodes_num_max=700, data_type="er") - _test_mis_gurobi(nodes_num_min=600, nodes_num_max=700, data_type="ba") - _test_mis_gurobi(nodes_num_min=600, nodes_num_max=700, data_type="hk") - _test_mis_gurobi(nodes_num_min=600, nodes_num_max=700, data_type="ws") + _test_mis_gurobi(nodes_num_min=50, nodes_num_max=100, data_type="er") + _test_mis_gurobi(nodes_num_min=50, nodes_num_max=100, data_type="ba") + _test_mis_gurobi(nodes_num_min=50, nodes_num_max=100, data_type="hk") + _test_mis_gurobi(nodes_num_min=50, nodes_num_max=100, data_type="ws") ############################################## @@ -409,7 +408,7 @@ def _test_mvc_gurobi( os.makedirs(save_path) # solver - solver = MVCGurobiSolver(licence_path=GUROBI_LICENCE, time_limit=5.0) + solver = MVCGurobiSolver(time_limit=5.0) # create MVCDataGenerator using gurobi solver mvc_data_gurobi = MVCDataGenerator( @@ -434,10 +433,10 @@ def test_mvc(): """ Test MVCDataGenerator """ - _test_mvc_gurobi(nodes_num_min=600, nodes_num_max=700, data_type="er") - _test_mvc_gurobi(nodes_num_min=600, nodes_num_max=700, data_type="ba") - _test_mvc_gurobi(nodes_num_min=600, nodes_num_max=700, data_type="hk") - _test_mvc_gurobi(nodes_num_min=600, nodes_num_max=700, data_type="ws") + _test_mvc_gurobi(nodes_num_min=50, nodes_num_max=100, data_type="er") + _test_mvc_gurobi(nodes_num_min=50, nodes_num_max=100, data_type="ba") + _test_mvc_gurobi(nodes_num_min=50, nodes_num_max=100, data_type="hk") + _test_mvc_gurobi(nodes_num_min=50, nodes_num_max=100, data_type="ws") diff --git a/tests/test_solver.py b/tests/test_solver.py index 9e1685f..804c630 100644 --- a/tests/test_solver.py +++ b/tests/test_solver.py @@ -28,7 +28,7 @@ def test_atsp_base_solver(): shutil.rmtree("tests/data_for_tests/solver/atsp/atsp50_tsplib_instance") shutil.rmtree("tests/data_for_tests/solver/atsp/atsp50_tsplib_solution") solver.to_txt( - filename="tests/data_for_tests/solver/atsp/atsp50.txt", + file_path="tests/data_for_tests/solver/atsp/atsp50.txt", apply_scale=False, to_int=False, ) @@ -50,8 +50,6 @@ def _test_atsp_lkh_solver(show_time: bool, num_threads: int): def test_atsp_lkh_solver(): _test_atsp_lkh_solver(True, 1) - _test_atsp_lkh_solver(True, 2) - _test_atsp_lkh_solver(False, 1) _test_atsp_lkh_solver(False, 2) @@ -100,8 +98,6 @@ def _test_cvrp_hgs_solver(show_time: bool, num_threads: int): def test_cvrp_hgs_solver(): _test_cvrp_hgs_solver(True, 1) - _test_cvrp_hgs_solver(True, 2) - _test_cvrp_hgs_solver(False, 1) _test_cvrp_hgs_solver(False, 2) @@ -121,8 +117,6 @@ def _test_cvrp_lkh_solver(show_time: bool, num_threads: int): def test_cvrp_lkh_solver(): _test_cvrp_lkh_solver(True, 1) - _test_cvrp_lkh_solver(True, 2) - _test_cvrp_lkh_solver(False, 1) _test_cvrp_lkh_solver(False, 2) @@ -142,8 +136,6 @@ def _test_cvrp_pyvrp_solver(show_time: bool, num_threads: int): def test_cvrp_pyvrp_solver(): _test_cvrp_pyvrp_solver(True, 1) - _test_cvrp_pyvrp_solver(True, 2) - _test_cvrp_pyvrp_solver(False, 1) _test_cvrp_pyvrp_solver(False, 2) @@ -198,8 +190,6 @@ def _test_mis_gurobi_solver(show_time: bool, num_threads: int): def test_mis_gurobi_solver(): _test_mis_gurobi_solver(True, 1) - _test_mis_gurobi_solver(True, 2) - _test_mis_gurobi_solver(False, 1) _test_mis_gurobi_solver(False, 2) @@ -260,8 +250,6 @@ def _test_mcut_gurobi_solver(show_time: bool, num_threads: int): def test_mcut_gurobi_solver(): _test_mcut_gurobi_solver(True, 1) - _test_mcut_gurobi_solver(True, 2) - _test_mcut_gurobi_solver(False, 1) _test_mcut_gurobi_solver(False, 2) @@ -297,8 +285,6 @@ def _test_mcl_gurobi_solver(show_time: bool, num_threads: int): def test_mcl_gurobi_solver(): _test_mcl_gurobi_solver(True, 1) - _test_mcl_gurobi_solver(True, 2) - _test_mcl_gurobi_solver(False, 1) _test_mcl_gurobi_solver(False, 2) @@ -352,8 +338,6 @@ def _test_mis_gurobi_solver(show_time: bool, num_threads: int): def test_mis_gurobi_solver(): _test_mis_gurobi_solver(True, 1) - _test_mis_gurobi_solver(True, 2) - _test_mis_gurobi_solver(False, 1) _test_mis_gurobi_solver(False, 2) @@ -414,8 +398,6 @@ def _test_mvc_gurobi_solver(show_time: bool, num_threads: int): def test_mvc_gurobi_solver(): _test_mvc_gurobi_solver(True, 1) - _test_mvc_gurobi_solver(True, 2) - _test_mvc_gurobi_solver(False, 1) _test_mvc_gurobi_solver(False, 2) @@ -446,7 +428,7 @@ def test_tsp_base_solver(): shutil.rmtree("tests/data_for_tests/solver/tsp/tsp50_tsplib_instance") shutil.rmtree("tests/data_for_tests/solver/tsp/tsp50_tsplib_solution") solver.to_txt( - filename="tests/data_for_tests/solver/tsp/tsp50.txt", + file_path="tests/data_for_tests/solver/tsp/tsp50.txt", apply_scale=False, to_int=False, ) @@ -468,8 +450,6 @@ def _test_tsp_concorde_solver(show_time: bool, num_threads: int): def test_tsp_concorde_solver(): _test_tsp_concorde_solver(True, 1) - _test_tsp_concorde_solver(True, 2) - _test_tsp_concorde_solver(False, 1) _test_tsp_concorde_solver(False, 2) @@ -489,8 +469,6 @@ def _test_tsp_ga_eax_solver(show_time: bool, num_threads: int): def test_tsp_ga_eax_solver(): _test_tsp_ga_eax_solver(True, 1) - _test_tsp_ga_eax_solver(True, 2) - _test_tsp_ga_eax_solver(False, 1) _test_tsp_ga_eax_solver(False, 2) @@ -510,8 +488,6 @@ def _test_tsp_ga_eax_large_solver(show_time: bool, num_threads: int): def test_tsp_ga_eax_large_solver(): _test_tsp_ga_eax_large_solver(True, 1) - _test_tsp_ga_eax_large_solver(True, 2) - _test_tsp_ga_eax_large_solver(False, 1) _test_tsp_ga_eax_large_solver(False, 2) @@ -531,8 +507,6 @@ def _test_tsp_lkh_solver(show_time: bool, num_threads: int): def test_tsp_lkh_solver(): _test_tsp_lkh_solver(True, 1) - _test_tsp_lkh_solver(True, 2) - _test_tsp_lkh_solver(False, 1) _test_tsp_lkh_solver(False, 2)