Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
* Included tests for "LocalSearchAlgorithm". #41
Browse files Browse the repository at this point in the history
* Fixed bug related with exception handling.
  • Loading branch information
garciparedes committed Sep 1, 2019
1 parent 049e95f commit d8b83c9
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
4 changes: 2 additions & 2 deletions jinete/algorithms/heuristics/insertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Planning,
)
from ...exceptions import (
NonFeasiblePlannedTripException,
StopPlannedTripIterationException,
)
from ..abc import (
Algorithm,
Expand Down Expand Up @@ -46,7 +46,7 @@ def _optimize(self) -> Planning:
while not crosser.completed:
try:
planned_trip = next(crosser)
except NonFeasiblePlannedTripException:
except StopPlannedTripIterationException:
break
route = planned_trip.route
route.append_planned_trip(planned_trip)
Expand Down
27 changes: 21 additions & 6 deletions tests/test_algorithms/test_heuristics/test_insertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,33 @@


class TestInsertionAlgorithm(unittest.TestCase):
job: jit.Job
fleet: jit.Fleet

@classmethod
def setUpClass(cls) -> None:
cls.job = jit.Job(generate_trips(10), objective_cls=jit.DialARideObjective)
cls.fleet = jit.Fleet(generate_vehicles(10))

def test_creation(self):
job = jit.Job(generate_trips(10), objective_cls=jit.DialARideObjective)
fleet = jit.Fleet(generate_vehicles(10))
algorithm = jit.InsertionAlgorithm(
crosser_cls=jit.Crosser,
job=job,
fleet=fleet,
job=self.job,
fleet=self.fleet,
)
self.assertEqual(algorithm.crosser_cls, jit.Crosser)
self.assertEqual(algorithm.job, job)
self.assertEqual(algorithm.fleet, fleet)
self.assertEqual(algorithm.job, self.job)
self.assertEqual(algorithm.fleet, self.fleet)

def test_optimize(self):
algorithm = jit.InsertionAlgorithm(
job=self.job,
fleet=self.fleet,
)
result = algorithm.optimize()

self.assertIsNotNone(result)
self.assertIsInstance(result, jit.Result)


if __name__ == '__main__':
Expand Down
48 changes: 48 additions & 0 deletions tests/test_algorithms/test_heuristics/test_local_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import unittest

import jinete as jit

from tests.utils import (
generate_vehicles,
generate_trips,
)


class TestLocalSearchAlgorithm(unittest.TestCase):
job: jit.Job
fleet: jit.Fleet

@classmethod
def setUpClass(cls) -> None:
cls.job = jit.Job(generate_trips(10), objective_cls=jit.DialARideObjective)
cls.fleet = jit.Fleet(generate_vehicles(10))
algorithm = jit.InsertionAlgorithm(
job=cls.job,
fleet=cls.fleet,
)
cls.initial = algorithm.optimize()

def test_creation(self):
algorithm = jit.LocalSearchAlgorithm(
initial=self.initial,
job=self.job,
fleet=self.fleet,
)
self.assertEqual(algorithm.initial, self.initial)
self.assertEqual(algorithm.job, self.job)
self.assertEqual(algorithm.fleet, self.fleet)

def test_optimize(self):
algorithm = jit.LocalSearchAlgorithm(
initial=self.initial,
job=self.job,
fleet=self.fleet,
)
result = algorithm.optimize()

self.assertIsNotNone(result)
self.assertIsInstance(result, jit.Result)


if __name__ == '__main__':
unittest.main()

0 comments on commit d8b83c9

Please sign in to comment.