Skip to content

Commit

Permalink
Small changes to basemethods and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ggsdc committed Sep 26, 2023
1 parent f7e7208 commit 42e01db
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"Operating System :: OS Independent",
"Development Status :: 2 - Pre-Alpha",
],
python_requires=">=3.8",
python_requires=">=3.7",
include_package_data=True,
install_requires=required,
extras_require=extra_required,
Expand Down
4 changes: 2 additions & 2 deletions tsp_solvers/methods/ga.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# Import from internal modules
from tsp_solvers.initializers import NearestNeighbor, RandomInitializer
from tsp_solvers.methods.base import BaseMethod
from tsp_solvers.methods.base import BaseSolver


class Individual:
Expand Down Expand Up @@ -80,7 +80,7 @@ def __str__(self):
return str(self.genes)


class GeneticAlgorithm(BaseMethod):
class GeneticAlgorithm(BaseSolver):
def __init__(
self,
graph,
Expand Down
4 changes: 2 additions & 2 deletions tsp_solvers/methods/lp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

from pulp import *

from tsp_solvers.methods.base import BaseMethod
from tsp_solvers.methods.base import BaseSolver


class LinearIntegerProgram(BaseMethod):
class LinearIntegerProgram(BaseSolver):
def __init__(self, graph, max_time, plot=False):
super().__init__()
self.graph = graph
Expand Down
4 changes: 2 additions & 2 deletions tsp_solvers/methods/lp_dantzig.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
PULP_CBC_CMD,
)
from pytups import SuperDict
from tsp_solvers.methods.base import BaseMethod
from tsp_solvers.methods.base import BaseSolver


class LinearIntegerDantzig(BaseMethod):
class LinearIntegerDantzig(BaseSolver):
def __init__(self, graph, max_time, plot=False):
super().__init__()
self.graph = graph
Expand Down
4 changes: 2 additions & 2 deletions tsp_solvers/methods/three_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from datetime import datetime

from tsp_solvers.initializers import NearestNeighbor, RandomInitializer
from tsp_solvers.methods.base import BaseMethod
from tsp_solvers.methods.base import BaseSolver


class ThreeOpt(BaseMethod):
class ThreeOpt(BaseSolver):
def __init__(self, graph, max_time, init="random", plot=False):
super().__init__()
self.graph = graph
Expand Down
4 changes: 2 additions & 2 deletions tsp_solvers/methods/three_opt_annealing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from random import random

from tsp_solvers.initializers import NearestNeighbor, RandomInitializer
from tsp_solvers.methods.base import BaseMethod
from tsp_solvers.methods.base import BaseSolver


class SimulatedAnnealingThreeOpt(BaseMethod):
class SimulatedAnnealingThreeOpt(BaseSolver):
def __init__(self, graph, max_time, init="random", plot=False):
super().__init__()
self.graph = graph
Expand Down
4 changes: 2 additions & 2 deletions tsp_solvers/methods/two_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

# Import from internal modules
from tsp_solvers.initializers import NearestNeighbor, RandomInitializer
from tsp_solvers.methods.base import BaseMethod
from tsp_solvers.methods.base import BaseSolver


class TwoOpt(BaseMethod):
class TwoOpt(BaseSolver):
def __init__(self, graph, max_time, init="random", plot=False):
super().__init__()
self.graph = graph
Expand Down
4 changes: 2 additions & 2 deletions tsp_solvers/methods/two_opt_annealing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

# Import from internal modules
from tsp_solvers.initializers import NearestNeighbor, RandomInitializer
from tsp_solvers.methods.base import BaseMethod
from tsp_solvers.methods.base import BaseSolver


class SimulatedAnnealingTwoOpt(BaseMethod):
class SimulatedAnnealingTwoOpt(BaseSolver):
def __init__(self, graph, max_time, init="random", plot=False):
super().__init__()
self.graph = graph
Expand Down
9 changes: 9 additions & 0 deletions tsp_solvers/tests/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
"""
This file contains the solution of each method
"""
import os

# Method to get the files
path_to_tests_dir = os.path.dirname(os.path.abspath(__file__))


def get_test_file(relative_path):
return os.path.join(path_to_tests_dir, relative_path)


# For the 10 vertex problem
GA_V10_COST = 54.557082002939914
Expand Down
5 changes: 3 additions & 2 deletions tsp_solvers/tests/test_ga.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
GA_V10_GENES,
GA_V100_COST,
GA_V100_GENES,
get_test_file,
)
from tsp_solvers import Graph
from tsp_solvers import GeneticAlgorithm
Expand All @@ -24,14 +25,14 @@ def tearDown(self):
pass

def test_ga_10(self):
self.g.create_graph_from_json("./tsp_solvers/tests/data/10v.json")
self.g.create_graph_from_json(get_test_file("./data/10v.json"))
ga = GeneticAlgorithm(self.g, 200, 100, 0.1, 120, "nearest")
ga.run()
self.assertListEqual(ga.best_genes, GA_V10_GENES)
self.assertEqual(ga.best_cost, GA_V10_COST)

def test_ga_100(self):
self.g.create_graph_from_json("./tsp_solvers/tests/data/100v.json")
self.g.create_graph_from_json(get_test_file("./data/100v.json"))
ga = GeneticAlgorithm(self.g, 200, 100, 0.1, 120, "nearest")
ga.run()
self.assertListEqual(ga.best_genes, GA_V100_GENES)
Expand Down

0 comments on commit 42e01db

Please sign in to comment.