From 92a006a12ab38d637dcddc768c4ce9c9f4bcfe7f Mon Sep 17 00:00:00 2001 From: PatrickOHara Date: Thu, 7 Jan 2021 18:18:58 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=9A=9A=20=20name=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + tests/test_complete.py | 4 ++-- tests/test_profits_problem.py | 18 +++++++++--------- tests/test_sparsity.py | 4 ++-- tests/test_utils.py | 8 ++++---- tspwplib/types.py | 14 +++++++------- tspwplib/utils.py | 6 +++--- 7 files changed, 28 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index e45693c..63f7b13 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ # python cache *.egg-info __pycache__ +.eggs # misc .vscode diff --git a/tests/test_complete.py b/tests/test_complete.py index a0aa29b..343bb60 100644 --- a/tests/test_complete.py +++ b/tests/test_complete.py @@ -25,9 +25,9 @@ def test_is_complete_with_self_loops(): assert is_complete_with_self_loops(graph) -def test_tsplib_is_complete(tsplib_root, instance_name): +def test_tsplib_is_complete(tsplib_root, graph_name): """Test each instance of TSPLIB95 is a complete graph""" - filepath = build_path_to_tsplib_instance(tsplib_root, instance_name) + filepath = build_path_to_tsplib_instance(tsplib_root, graph_name) problem = tsplib95.load(filepath) graph = problem.get_graph() assert is_complete_with_self_loops(graph) diff --git a/tests/test_profits_problem.py b/tests/test_profits_problem.py index ae397e8..e35414f 100644 --- a/tests/test_profits_problem.py +++ b/tests/test_profits_problem.py @@ -7,10 +7,10 @@ from tspwplib.utils import build_path_to_oplib_instance -def test_parse_profits_problem(oplib_root, generation, instance_name, alpha): +def test_parse_profits_problem(oplib_root, generation, graph_name, alpha): """Test an OP instance can be parsed""" filepath = build_path_to_oplib_instance( - oplib_root, generation, instance_name, alpha=alpha + oplib_root, generation, graph_name, alpha=alpha ) assert "COST_LIMIT" in ProfitsProblem.fields_by_keyword assert "NODE_SCORE_SECTION" in ProfitsProblem.fields_by_keyword @@ -19,22 +19,22 @@ def test_parse_profits_problem(oplib_root, generation, instance_name, alpha): assert problem.is_complete() -def test_get_cost_limit(oplib_root, generation, instance_name, alpha): +def test_get_cost_limit(oplib_root, generation, graph_name, alpha): """Test we can get the cost limit""" filepath = build_path_to_oplib_instance( - oplib_root, generation, instance_name, alpha=alpha + oplib_root, generation, graph_name, alpha=alpha ) problem = ProfitsProblem.load(filepath) expected_cost_limit = math.ceil( - OptimalSolutionTSP[instance_name] * (alpha.value / 100.0) + OptimalSolutionTSP[graph_name] * (alpha.value / 100.0) ) assert problem.get_cost_limit() == expected_cost_limit -def test_get_node_score(oplib_root, generation, instance_name, alpha): +def test_get_node_score(oplib_root, generation, graph_name, alpha): """Test every node has a prize""" filepath = build_path_to_oplib_instance( - oplib_root, generation, instance_name, alpha=alpha + oplib_root, generation, graph_name, alpha=alpha ) problem = ProfitsProblem.load(filepath) node_scores = problem.get_node_score() @@ -45,10 +45,10 @@ def test_get_node_score(oplib_root, generation, instance_name, alpha): assert value >= 0 -def test_get_graph(oplib_root, generation, instance_name, alpha): +def test_get_graph(oplib_root, generation, graph_name, alpha): """Test we can load a graph with prizes""" filepath = build_path_to_oplib_instance( - oplib_root, generation, instance_name, alpha=alpha + oplib_root, generation, graph_name, alpha=alpha ) problem = ProfitsProblem.load(filepath) graph = problem.get_graph() diff --git a/tests/test_sparsity.py b/tests/test_sparsity.py index 24d1716..6ceb100 100644 --- a/tests/test_sparsity.py +++ b/tests/test_sparsity.py @@ -8,10 +8,10 @@ def test_remove_random_edges_from_graph( - tsplib_root, instance_name, edge_removal_probability + tsplib_root, graph_name, edge_removal_probability ): """Test the right number of edges are removed""" - filepath = build_path_to_tsplib_instance(tsplib_root, instance_name) + filepath = build_path_to_tsplib_instance(tsplib_root, graph_name) problem = StandardProblem.load(filepath) complete_graph = problem.get_graph() assert is_complete_with_self_loops(complete_graph) diff --git a/tests/test_utils.py b/tests/test_utils.py index 5901396..a73e9ce 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -3,13 +3,13 @@ from tspwplib.utils import build_path_to_oplib_instance, build_path_to_tsplib_instance -def test_build_path_to_oplib_instance(oplib_root, generation, instance_name, alpha): +def test_build_path_to_oplib_instance(oplib_root, generation, graph_name, alpha): """Test path building""" assert build_path_to_oplib_instance( - oplib_root, generation, instance_name, alpha=alpha + oplib_root, generation, graph_name, alpha=alpha ).exists() -def test_build_path_to_tsplib_instance(tsplib_root, instance_name): +def test_build_path_to_tsplib_instance(tsplib_root, graph_name): """Test path building for tsplib""" - assert build_path_to_tsplib_instance(tsplib_root, instance_name).exists() + assert build_path_to_tsplib_instance(tsplib_root, graph_name).exists() diff --git a/tspwplib/types.py b/tspwplib/types.py index 0ce8462..9d8801f 100644 --- a/tspwplib/types.py +++ b/tspwplib/types.py @@ -17,7 +17,7 @@ class EdgeFunctionName(str, Enum): weight = "weight" -class InstanceName(str, Enum): +class GraphName(str, Enum): """Names of TSPlib instances""" eil76 = "eil76" @@ -26,16 +26,16 @@ class InstanceName(str, Enum): vm1748 = "vm1748" -class Generation(Enum): +class Generation(str, Enum): """Generations of TSPwP problem instances""" - one = "gen1" - two = "gen2" - three = "gen3" - four = "gen4" + gen1 = "gen1" + gen2 = "gen2" + gen3 = "gen3" + gen4 = "gen4" -class Alpha(Enum): +class Alpha(IntEnum): """Ratio between profit/cost limit and profit/cost of TSP solution""" fifty = 50 diff --git a/tspwplib/utils.py b/tspwplib/utils.py index b6d83f1..d800930 100644 --- a/tspwplib/utils.py +++ b/tspwplib/utils.py @@ -1,13 +1,13 @@ """Useful functions for parsing""" from pathlib import Path -from .types import Alpha, Generation, InstanceName +from .types import Alpha, Generation, GraphName def build_path_to_oplib_instance( oplib_root: Path, generation: Generation, - name: InstanceName, + name: GraphName, alpha: Alpha = Alpha.fifty, ) -> Path: """Build a filepath to a oplib instance""" @@ -15,7 +15,7 @@ def build_path_to_oplib_instance( return oplib_root / "instances" / generation.value / filename -def build_path_to_tsplib_instance(tsplib_root: Path, name: InstanceName) -> Path: +def build_path_to_tsplib_instance(tsplib_root: Path, name: GraphName) -> Path: """Build a filepath to a tsplib instance""" filename = name.value + ".tsp" return tsplib_root / filename From 1efced98fa2fbfe360da9778b204f23ea0b05b12 Mon Sep 17 00:00:00 2001 From: PatrickOHara Date: Thu, 7 Jan 2021 18:43:37 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=96=20Bump=20version=20of=20pytest?= =?UTF-8?q?-tspwplib?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a5fab3c..f045f84 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,4 @@ mkdocs-material>=6.0.2 mypy>=0.782 pylint>=2.6.0 pytest>=6.1.1 -pytest-tspwplib>=0.2.0b1 \ No newline at end of file +pytest-tspwplib>=0.2.3 \ No newline at end of file