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

Commit

Permalink
Merge pull request #128 from garciparedes/issue-127
Browse files Browse the repository at this point in the history
Issue 127
  • Loading branch information
garciparedes authored Sep 19, 2020
2 parents 7722013 + 58197ad commit 6ed5687
Show file tree
Hide file tree
Showing 33 changed files with 462 additions and 328 deletions.
106 changes: 106 additions & 0 deletions docs/source/_static/algorithms.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
@startuml
skinparam linetype ortho
skinparam nodesep 100
skinparam ranksep 100

hide empty methods
hide empty attributes

entity Job <<models>>
entity Fleet <<models>>

entity Result <<models>>

abstract class Algorithm <<algorithms>>

class MilpAlgorithm <<algorithms>>

abstract class LinearModel <<algorithms>>
class ThreeIndexLinearModel <<algorithms>>

class InsertionAlgorithm <<algorithms>>

class InsertionIterator <<algorithms>>
class RankingInsertionIterator <<algorithms>>
class StatelessInsertionIterator <<algorithms>>

class InsertionStrategy <<algorithms>>
class IntensiveInsertionStrategy <<algorithms>>
class SamplingInsertionStrategy <<algorithms>>
class TailInsertionStrategy <<algorithms>>

class LocalSearchAlgorithm <<algorithms>>

abstract class LocalSearchStrategy <<algorithms>>
class ReallocationLocalSearchStrategy <<algorithms>>
class OneShiftLocalSearchStrategy <<algorithms>>
class TwoOPTLocalSearchStrategy <<algorithms>>

class GRASPAlgorithm <<algorithms>>
class IterativeAlgorithm <<algorithms>>
class SequentialAlgorithm <<algorithms>>


InsertionAlgorithm -up-|> Algorithm
Algorithm <|-- LocalSearchAlgorithm
Algorithm <|-- GRASPAlgorithm
MilpAlgorithm --|> Algorithm
IterativeAlgorithm --|> Algorithm
SequentialAlgorithm --|> Algorithm



InsertionStrategy <|- IntensiveInsertionStrategy
InsertionStrategy <|-- SamplingInsertionStrategy
InsertionStrategy <|-- TailInsertionStrategy

RankingInsertionIterator --|> InsertionIterator
StatelessInsertionIterator --|> InsertionIterator

LinearModel <|-up- ThreeIndexLinearModel

LocalSearchStrategy <|-- ReallocationLocalSearchStrategy
LocalSearchStrategy <|-- OneShiftLocalSearchStrategy
LocalSearchStrategy <|-- TwoOPTLocalSearchStrategy



InsertionAlgorithm -up- InsertionIterator
InsertionAlgorithm -down- InsertionStrategy

MilpAlgorithm -up- LinearModel

LocalSearchAlgorithm -down- LocalSearchStrategy


GRASPAlgorithm -down- LocalSearchAlgorithm
GRASPAlgorithm -down- InsertionAlgorithm


note "composed of" as N1
N1 --o IterativeAlgorithm
Algorithm - N1

note "composed of" as N2
N2 --o SequentialAlgorithm
Algorithm - N2


Job "receives "-o Algorithm
Fleet "receives"-o Algorithm
Result "generates"- Algorithm

Job -down[hidden]- Fleet
Fleet -down[hidden]- Result


ReallocationLocalSearchStrategy -down[hidden]- OneShiftLocalSearchStrategy
OneShiftLocalSearchStrategy -down[hidden]- TwoOPTLocalSearchStrategy

IntensiveInsertionStrategy -down[hidden]- SamplingInsertionStrategy
SamplingInsertionStrategy -down[hidden]- TailInsertionStrategy

RankingInsertionIterator -down[hidden]- StatelessInsertionIterator

@enduml

40 changes: 25 additions & 15 deletions docs/source/_static/data_model.puml
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,69 @@ skinparam ranksep 100
hide empty methods
hide empty attributes

entity Vehicle {
abstract class Algorithm <<algorithms>>

entity Vehicle <<models>> {
identifier: str
capacity: float
timeout: float
}

entity Route {
entity Route <<models>> {
uuid: UUID
}

entity Trip {
entity Trip <<models>> {
identifier: str
on_time_bonus: float
capacity: float
timeout: float
}

entity PlannedTrip {
entity PlannedTrip <<models>> {
}

entity Planning {
entity Planning <<models>> {
computation_time: float
}

entity Stop {
entity Result <<models>> {
}


entity Stop <<models>> {
starting_time?: float
}

entity Service {
entity Service <<models>> {
earliest: float
latest: float
duration: float
}

entity Job {
entity Job <<models>> {
}

entity Fleet {
entity Fleet <<models>> {
}

entity Position {
entity Position <<models>> {
coordinates: Tuple[float, ...]
}

entity Surface {
entity Surface <<models>> {
uuid: UUID
}



Job o-"*" Trip
Algorithm --o Planning: optimizes >
Algorithm o-- Fleet
Algorithm o-- Job
Algorithm -- Result: generates >
Result --o Planning
Result o-- Fleet
Result o-- Job
Algorithm o-- Fleet: receives <
Algorithm o-- Job: receives <
Planning o--"*" Route
Trip o- PlannedTrip: planified >
Trip o-right-"origin" Service
Expand All @@ -77,4 +87,4 @@ Vehicle o-left-"origin" Service
Vehicle o-left-"destination" Service


@enduml
@enduml
42 changes: 42 additions & 0 deletions docs/source/_static/loaders.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@startuml
skinparam linetype ortho
skinparam nodesep 100
skinparam ranksep 100

hide empty methods
hide empty attributes

entity Job <<models>>
entity Fleet <<models>>
entity Surface <<models>>

abstract class Loader <<loaders>> {
}

class FileLoader <<loaders>> {
}

abstract class LoaderFormatter <<loaders>> {
}

class CordeauLaporteLoaderFormatter <<loaders>> {
}

class HashCodeLoaderFormatter <<loaders>> {
}


Loader -up-"loads" Job
Loader -up-"loads" Fleet
Loader -up-"loads" Surface

LoaderFormatter "uses"-right-o Loader

Loader <|-down- FileLoader

LoaderFormatter <|-down- CordeauLaporteLoaderFormatter
LoaderFormatter <|-down- HashCodeLoaderFormatter


@enduml

14 changes: 14 additions & 0 deletions docs/source/_static/modules.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@startuml

package "jinete" {
[models]
[loaders]
[algorithms]
[storers]
[dispachers]
[solvers]
[exceptions]
[utils]
}

@enduml
52 changes: 52 additions & 0 deletions docs/source/_static/storers.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@startuml
skinparam linetype ortho
skinparam nodesep 100
skinparam ranksep 100

hide empty methods
hide empty attributes

entity Result <<models>>

entity Storer <<storers>> {
}

abstract class FileStorer <<storers>> {
}
class SetStorer <<storers>> {
}
class PromptStorer <<storers>> {
}
class GraphPlotStorer <<storers>> {
}

abstract class StorerFormatter <<storers>> {
}
class ColumnarStorerFormatter <<storers>> {
}
class HashCodeStorerFormatter <<storers>> {
}


Storer -up-"stores" Result

StorerFormatter "uses"-right-o Storer

note "composed of" as N2
N2 --o SetStorer
N2 - Storer


Storer <|-down- FileStorer
Storer <|-down- PromptStorer
Storer <|-down- SetStorer


Storer <|-down- GraphPlotStorer

StorerFormatter <|-down- ColumnarStorerFormatter
StorerFormatter <|-down- HashCodeStorerFormatter


@enduml

45 changes: 45 additions & 0 deletions examples/cordeau/benchmark_launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import logging
import traceback
from concurrent import (
futures,
)
from pathlib import (
Path,
)
from subprocess import (
STDOUT,
TimeoutExpired,
check_output,
)

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

DATASETS_PATH = Path(__file__).absolute().parents[2] / "res" / "datasets" / "cordeau-laporte"
INSTANCE_TIMEOUT = 7200


def main():
with futures.ProcessPoolExecutor() as executor:
for file_path in DATASETS_PATH.glob("*.txt"):
executor.submit(run_one, file_path)


def run_one(file_path):
try:
command = ["python3", "benchmark_solve.py", str(file_path.absolute())]
print(f'COMMAND: "{" ".join(command)}"')
try:
output = check_output(command, timeout=INSTANCE_TIMEOUT, stderr=STDOUT, cwd=Path(__file__).parent).decode()
except TimeoutExpired as exc:
print(exc)
output = exc.output.decode()
with (file_path.parent / f"{file_path.name}.log").open("w") as file:
file.write(output)
except Exception as exc:
traceback.print_exc()
raise exc


if __name__ == "__main__":
main()
42 changes: 42 additions & 0 deletions examples/cordeau/benchmark_solve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import logging
import sys
import traceback
from functools import (
partial,
)
from pathlib import (
Path,
)

import jinete as jit

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


def main():
logger.info("Starting...")
file_path = Path(sys.argv[1])
solver = jit.Solver(
loader_kwargs={"file_path": file_path},
algorithm=jit.GraspAlgorithm,
algorithm_kwargs={"first_solution_kwargs": {"episodes": 1, "randomized_size": 2}, "episodes": 5},
storer=jit.StorerSet,
storer_kwargs={
"storer_cls_set": {
jit.PromptStorer,
partial(jit.GraphPlotStorer, file_path=file_path.parent / f"{file_path.name}.png"),
partial(jit.FileStorer, file_path=file_path.parent / f"{file_path.name}.output"),
}
},
)
result = solver.solve() # noqa
logger.info("Finished...")


if __name__ == "__main__":
try:
main()
except Exception as exc:
traceback.print_exc()
raise exc
Loading

0 comments on commit 6ed5687

Please sign in to comment.