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

Commit

Permalink
Merge pull request #87 from garciparedes/master
Browse files Browse the repository at this point in the history
Issue #86
  • Loading branch information
garciparedes authored Jan 21, 2020
2 parents 190fc23 + c52da1e commit a8cbd5e
Show file tree
Hide file tree
Showing 82 changed files with 1,411 additions and 738 deletions.
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ coverage:
threshold: 1
patch:
default:
threshold: 1
threshold: 15
37 changes: 8 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,15 @@ import jinete as jit

file_path = './res/datasets/hashcode/a_example.in'

class MyLoader(jit.FileLoader):
def __init__(self, *args, **kwargs):
super().__init__(
file_path=file_path,
formatter_cls=jit.HashCodeLoaderFormatter,
*args, **kwargs,
)

class MyAlgorithm(jit.InsertionAlgorithm):
def __init__(self, *args, **kwargs):
super().__init__(
crosser_cls=jit.BestStatelessCrosser,
*args, **kwargs
)

class MyStorer(jit.PromptStorer):
def __init__(self, *args, **kwargs):
super().__init__(
formatter_cls=jit.ColumnarStorerFormatter,
*args, **kwargs,
)

dispatcher = jit.StaticDispatcher(
MyLoader,
MyAlgorithm,
MyStorer,
solver = jit.Solver(
loader=jit.FileLoader,
loader_kwargs={
'file_path': file_path,
'formatter_cls': jit.HashCodeLoaderFormatter
},
algorithm=jit.InsertionAlgorithm,
)

result = dispatcher.run()

result = solver.solve()
# ...

```
Expand Down
56 changes: 19 additions & 37 deletions examples/cordeau/example_grasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,26 @@ def main():

file_path = DATASETS_PATH / 'cordeau-laporte' / 'a2-16.txt'

class MyLoader(jit.FileLoader):
def __init__(self, *args, **kwargs):
super().__init__(
file_path=file_path,
formatter_cls=jit.CordeauLaporteLoaderFormatter,
*args, **kwargs,
)

class MyAlgorithm(jit.GraspAlgorithm):
def __init__(self, *args, **kwargs):
super().__init__(
*args, **kwargs,
)

class MyStorer(jit.PromptStorer):
def __init__(self, *args, **kwargs):
super().__init__(
formatter_cls=jit.ColumnarStorerFormatter,
*args, **kwargs,
)

class MyStorerSet(jit.StorerSet):
def __init__(self, *args, **kwargs):
super().__init__(
storer_cls_set={
MyStorer,
jit.GraphPlotStorer,
},
*args, **kwargs,
)

dispatcher = jit.StaticDispatcher(
MyLoader,
MyAlgorithm,
MyStorerSet,
solver = jit.Solver(
loader_kwargs={
'file_path': file_path,
},
algorithm=jit.GraspAlgorithm,
algorithm_kwargs={
'first_solution_kwargs': {
'episodes': 1,
'strategy_cls': jit.IntensiveInsertionStrategy,
}
},
storer=jit.StorerSet,
storer_kwargs={
'storer_cls_set': {
jit.PromptStorer,
jit.GraphPlotStorer,
},
}
)

result = dispatcher.run() # noqa
result = solver.solve() # noqa

logger.info('Finished...')

Expand Down
54 changes: 16 additions & 38 deletions examples/cordeau/example_insertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,23 @@ def main():

file_path = DATASETS_PATH / 'cordeau-laporte' / 'a2-16.txt'

class MyLoader(jit.FileLoader):
def __init__(self, *args, **kwargs):
super().__init__(
file_path=file_path,
formatter_cls=jit.CordeauLaporteLoaderFormatter,
*args, **kwargs,
)

class MyAlgorithm(jit.InsertionAlgorithm):
def __init__(self, *args, **kwargs):
super().__init__(
conjecturer_cls=jit.IntensiveConjecturer,
*args, **kwargs,
)

class MyStorer(jit.PromptStorer):
def __init__(self, *args, **kwargs):
super().__init__(
formatter_cls=jit.ColumnarStorerFormatter,
*args, **kwargs,
)

class MyStorerSet(jit.StorerSet):
def __init__(self, *args, **kwargs):
super().__init__(
storer_cls_set={
MyStorer,
jit.GraphPlotStorer,
},
*args, **kwargs,
)

dispatcher = jit.StaticDispatcher(
MyLoader,
MyAlgorithm,
MyStorerSet,
solver = jit.Solver(
loader_kwargs={
'file_path': file_path,
},
algorithm=jit.InsertionAlgorithm,
algorithm_kwargs={
'strategy_cls': jit.IntensiveInsertionStrategy,
},
storer=jit.StorerSet,
storer_kwargs={
'storer_cls_set': {
jit.PromptStorer,
jit.GraphPlotStorer,
},
}
)

result = dispatcher.run() # noqa
result = solver.solve() # noqa

logger.info('Finished...')

Expand Down
62 changes: 20 additions & 42 deletions examples/cordeau/example_milp_three_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,27 @@ def main():

file_path = DATASETS_PATH / 'cordeau-laporte' / 'a2-16.txt'

class MyLoader(jit.FileLoader):
def __init__(self, *args, **kwargs):
super().__init__(
file_path=file_path,
formatter_cls=jit.CordeauLaporteLoaderFormatter,
*args, **kwargs,
)

class MyAlgorithm(jit.MilpAlgorithm):
def __init__(self, *args, **kwargs):
super().__init__(
# solver=lp.XPRESS(msg=1, path=str(BASE_PATH / 'tmp' / 'xpressmp' / 'bin' / 'optimizer')),
# solver=lp.GUROBI_CMD(msg=1),
# solver=lp.CPLEX_CMD(msg=1, path=str(BASE_PATH / 'tmp' / 'cplex' / 'bin' / 'x86-64_osx' / 'cplex')),
solver=lp.SCIP(msg=1),
# solver=lp.PULP_CBC_CMD(msg=1, threads=4),
*args, **kwargs,
)

class MyStorer(jit.PromptStorer):
def __init__(self, *args, **kwargs):
super().__init__(
formatter_cls=jit.ColumnarStorerFormatter,
*args, **kwargs,
)

class MyStorerSet(jit.StorerSet):
def __init__(self, *args, **kwargs):
super().__init__(
storer_cls_set={
MyStorer,
jit.GraphPlotStorer,
},
*args, **kwargs,
)

dispatcher = jit.StaticDispatcher(
MyLoader,
MyAlgorithm,
MyStorerSet,
solver = jit.Solver(
loader_kwargs={
'file_path': file_path,
},
algorithm=jit.MilpAlgorithm,
algorithm_kwargs={
# 'solver': lp.XPRESS(msg=1, path=str(BASE_PATH / 'tmp' / 'xpressmp' / 'bin' / 'optimizer')),
# 'solver': lp.GUROBI_CMD(msg=1),
# 'solver': lp.CPLEX_CMD(msg=1, path=str(BASE_PATH / 'tmp' / 'cplex' / 'bin' / 'x86-64_osx' / 'cplex')),
'solver': lp.SCIP(msg=1),
# 'solver' :lp.PULP_CBC_CMD(msg=1, threads=4),
},
storer=jit.StorerSet,
storer_kwargs={
'storer_cls_set': {
jit.PromptStorer,
jit.GraphPlotStorer,
},
}
)

result = dispatcher.run() # noqa
result = solver.solve() # noqa

logger.info('Finished...')

Expand Down
40 changes: 11 additions & 29 deletions examples/hashcode/example_insertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,18 @@ def main():

file_path = DATASETS_PATH / 'hashcode' / FILES['b']

class MyLoader(jit.FileLoader):
def __init__(self, *args, **kwargs):
super().__init__(
file_path=file_path,
formatter_cls=jit.HashCodeLoaderFormatter,
*args, **kwargs,
)

class MyAlgorithm(jit.InsertionAlgorithm):
def __init__(self, *args, **kwargs):
super().__init__(
neighborhood_max_size=None,
criterion_cls=jit.HashCodeRouteCriterion,
*args, **kwargs,
)

class MyStorer(jit.PromptStorer):
def __init__(self, *args, **kwargs):
super().__init__(
formatter_cls=jit.ColumnarStorerFormatter,
*args, **kwargs,
)

dispatcher = jit.StaticDispatcher(
MyLoader,
MyAlgorithm,
MyStorer,
solver = jit.Solver(
loader_kwargs={
'file_path': file_path,
'formatter_cls': jit.HashCodeLoaderFormatter,
},
algorithm=jit.InsertionAlgorithm,
algorithm_kwargs={
'criterion': jit.HashCodeRouteCriterion,
'neighborhood_max_size': None,
},
)

result = dispatcher.run() # noqa
result = solver.solve() # noqa

logger.info('Finished...')

Expand Down
24 changes: 13 additions & 11 deletions jinete/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,24 @@
GraspAlgorithm,
MilpAlgorithm,
IterativeAlgorithm,
Crosser,
StatelessCrosser,
BestStatelessCrosser,
OrderedCrosser,
RandomizedCrosser,
Breeder,
FlipBreeder,
Conjecturer,
SamplingConjecturer,
IntensiveConjecturer,
InsertionIterator,
StatelessInsertionIterator,
BestStatelessInsertionIterator,
RankingInsertionIterator,
LocalSearchStrategy,
OneShiftLocalSearchStrategy,
ReallocationLocalSearchStrategy,
InsertionStrategy,
SamplingInsertionStrategy,
IntensiveInsertionStrategy,
)

from .exceptions import (
JineteException,
StopPlannedTripIterationException,
NonFeasiblePlannedTripException,
NonFeasibleRouteException,
PreviousStopNotInRouteException,
)
from .solvers import (
Solver,
)
2 changes: 1 addition & 1 deletion jinete/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION = (0, 0, 13)
VERSION = (0, 0, 14)

__version__ = '.'.join(map(str, VERSION))
22 changes: 10 additions & 12 deletions jinete/algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
from .heuristics import (
InsertionAlgorithm,
LocalSearchAlgorithm,
InsertionIterator,
StatelessInsertionIterator,
BestStatelessInsertionIterator,
RankingInsertionIterator,
LocalSearchStrategy,
OneShiftLocalSearchStrategy,
ReallocationLocalSearchStrategy,
InsertionStrategy,
SamplingInsertionStrategy,
IntensiveInsertionStrategy,
)
from .metaheuristics import (
GraspAlgorithm,
Expand All @@ -15,15 +25,3 @@
from .exacts import (
MilpAlgorithm,
)
from .utils import (
Crosser,
StatelessCrosser,
BestStatelessCrosser,
OrderedCrosser,
RandomizedCrosser,
Breeder,
FlipBreeder,
Conjecturer,
SamplingConjecturer,
IntensiveConjecturer,
)
11 changes: 11 additions & 0 deletions jinete/algorithms/heuristics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
from .insertion import (
InsertionAlgorithm,

InsertionIterator,
StatelessInsertionIterator,
BestStatelessInsertionIterator,
RankingInsertionIterator,
InsertionStrategy,
SamplingInsertionStrategy,
IntensiveInsertionStrategy,
)
from .local_search import (
LocalSearchAlgorithm,
LocalSearchStrategy,
OneShiftLocalSearchStrategy,
ReallocationLocalSearchStrategy,
)
Loading

0 comments on commit a8cbd5e

Please sign in to comment.