Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
heatingma committed Dec 2, 2024
1 parent 3134245 commit 7a4549d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 63 deletions.
3 changes: 2 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ coverage:
ignore:
- ml4co_kit/solver/tsp/pyconcorde/setup.py
- ml4co_kit/learning/**
- ml4co_kit/solver/tsp/concorde_large.py
- ml4co_kit/solver/tsp/concorde_large.py
- ml4co_kit/utils/tsplib95
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -1726,8 +1726,8 @@
1342,
1346
],
"solution_time": 3.19248,
"total_time": 10.16194302868098,
"solution_time": 4.51694,
"total_time": 10.111564490944147,
"vertices": 449
}
}
51 changes: 25 additions & 26 deletions tests/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import shutil
from ml4co_kit import *

GUROBI_LICENCE = "your gurobi licence"
GUROBI_TEST = False


Expand Down Expand Up @@ -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(
Expand All @@ -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")


##############################################
Expand All @@ -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(
Expand All @@ -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")


##############################################
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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")


##############################################
Expand All @@ -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(
Expand All @@ -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")



Expand Down
30 changes: 2 additions & 28 deletions tests/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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)


Expand Down Expand Up @@ -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)


Expand All @@ -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)


Expand All @@ -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)


Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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,
)
Expand All @@ -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)


Expand All @@ -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)


Expand All @@ -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)


Expand All @@ -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)


Expand Down

0 comments on commit 7a4549d

Please sign in to comment.