This repository has been archived by the owner on May 10, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from garciparedes/master
Issue 37
- Loading branch information
Showing
80 changed files
with
2,509 additions
and
437 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
coverage: | ||
status: | ||
project: | ||
default: | ||
threshold: 1 | ||
patch: | ||
default: | ||
threshold: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
VERSION = (0, 0, 10) | ||
VERSION = (0, 0, 11) | ||
|
||
__version__ = '.'.join(map(str, VERSION)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
from .insertion import ( | ||
InsertionAlgorithm, | ||
) | ||
from .local_search import ( | ||
LocalSearchAlgorithm, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from copy import deepcopy | ||
from typing import TYPE_CHECKING | ||
|
||
from ...exceptions import ( | ||
NonFeasiblePlannedTripException, | ||
) | ||
from ...models import ( | ||
Planning, | ||
) | ||
from ..abc import ( | ||
Algorithm, | ||
) | ||
from ..utils.breeders import ( | ||
FlipBreeder | ||
) | ||
|
||
if TYPE_CHECKING: | ||
from typing import ( | ||
Set, | ||
) | ||
from ...models import ( | ||
Result, | ||
Route, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class LocalSearchAlgorithm(Algorithm): | ||
|
||
def __init__(self, initial: Result, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.initial = initial | ||
self.args = args | ||
self.kwargs = kwargs | ||
self.breeder_cls = FlipBreeder | ||
|
||
@property | ||
def initial_planning(self) -> Planning: | ||
return self.initial.planning | ||
|
||
@property | ||
def initial_routes(self) -> Set[Route]: | ||
return self.initial_planning.routes | ||
|
||
def _optimize(self) -> Planning: | ||
best = self.initial | ||
|
||
again = True | ||
while again: | ||
current = self.breeder_cls(best).improve() | ||
best = self.objective.best(best, current) | ||
again = best == current | ||
|
||
assert best is not None | ||
|
||
return best.planning |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
from .grasp import ( | ||
GraspAlgorithm, | ||
) | ||
from .iterative import ( | ||
IterativeAlgorithm, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from random import Random | ||
from typing import TYPE_CHECKING | ||
|
||
from ...models import ( | ||
Planning, | ||
MAX_INT, | ||
) | ||
from ..abc import ( | ||
Algorithm, | ||
) | ||
from ..heuristics import ( | ||
InsertionAlgorithm, | ||
) | ||
|
||
if TYPE_CHECKING: | ||
from typing import ( | ||
Type, | ||
Optional, | ||
) | ||
from ...models import ( | ||
Result, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class IterativeAlgorithm(Algorithm): | ||
|
||
def __init__(self, episodes: int = 100, algorithm_cls: Type[Algorithm] = None, seed: int = 56, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
if algorithm_cls is None: | ||
algorithm_cls = InsertionAlgorithm | ||
self.episodes = episodes | ||
self.algorithm_cls = algorithm_cls | ||
self.random = Random(seed) | ||
|
||
self.args = args | ||
self.kwargs = kwargs | ||
|
||
def build_algorithm(self, *args, **kwargs) -> Algorithm: | ||
args = (*self.args, *args) | ||
kwargs.update(self.kwargs) | ||
|
||
return self.algorithm_cls(*args, **kwargs) | ||
|
||
def _optimize(self) -> Planning: | ||
best: Optional[Result] = None | ||
for i in range(self.episodes): | ||
seed = self.random.randint(0, MAX_INT) | ||
current = self.build_algorithm(seed=seed).optimize() | ||
best = self.objective.best(best, current) | ||
|
||
assert best is not None | ||
return best.planning |
Oops, something went wrong.