Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding geometry flag #104

Merged
merged 5 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Usage with a routing engine

>>> sol = problem_instance.solve(exploration_level=5, nb_threads=4)
>>> print(sol.summary.duration)
2698
2704

Installation
------------
Expand Down
7 changes: 7 additions & 0 deletions src/bind/solution/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
ptr[idx].setup = step.setup;
ptr[idx].service = step.service;
ptr[idx].waiting_time = step.waiting_time;
ptr[idx].distance = step.distance;
ptr[idx].arrival = step.arrival;
ptr[idx].duration = step.duration;

Expand All @@ -104,6 +105,12 @@
std::cout, py::module_::import("sys").attr("stdout"));
vroom::io::write_to_json(solution, false, "");
})
.def("_geometry_solution_json",
[](vroom::Solution solution) {

Check warning on line 109 in src/bind/solution/solution.cpp

View check run for this annotation

Codecov / codecov/patch

src/bind/solution/solution.cpp#L109

Added line #L109 was not covered by tests
py::scoped_ostream_redirect stream(
std::cout, py::module_::import("sys").attr("stdout"));
vroom::io::write_to_json(solution, true, "");
})

Check warning on line 113 in src/bind/solution/solution.cpp

View check run for this annotation

Codecov / codecov/patch

src/bind/solution/solution.cpp#L111-L113

Added lines #L111 - L113 were not covered by tests
.def_readwrite("code", &vroom::Solution::code)
.def_readwrite("error", &vroom::Solution::error)
.def_readonly("summary", &vroom::Solution::summary)
Expand Down
12 changes: 10 additions & 2 deletions src/vroom/input/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

"""

_geometry: bool = False

def __init__(
self,
amount_size: Optional[int] = None,
Expand Down Expand Up @@ -104,13 +106,16 @@
"""
if geometry is None:
geometry = servers is not None
if geometry:
self._set_geometry(True)

Check warning on line 110 in src/vroom/input/input.py

View check run for this annotation

Codecov / codecov/patch

src/vroom/input/input.py#L110

Added line #L110 was not covered by tests
instance = Input(servers=servers, router=router)
with open(filepath) as handle:
instance._from_json(handle.read(), geometry)
return instance

def set_geometry(self):
return self._set_geometry()
self._geometry = True
return self._set_geometry(True)

Check warning on line 118 in src/vroom/input/input.py

View check run for this annotation

Codecov / codecov/patch

src/vroom/input/input.py#L117-L118

Added lines #L117 - L118 were not covered by tests

def set_amount_size(self, *amount_sizes: int) -> None:
"""Add amount sizes."""
Expand Down Expand Up @@ -307,9 +312,12 @@
exploration_level: int,
nb_threads: int,
) -> Solution:
return Solution(
solution = Solution(
self._solve(
exploration_level=exploration_level,
nb_threads=nb_threads,
)

)
solution._geometry = self._geometry
return solution
14 changes: 12 additions & 2 deletions src/vroom/solution/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
Frame outlining all routes for all vehicles.
"""

_geometry: bool = False

@property
def routes(self) -> pandas.DataFrame:
"""
Expand Down Expand Up @@ -81,17 +83,25 @@
del frame[column]
else:
frame.loc[frame[column] == NA_SUBSTITUTE, column] = pandas.NA
if self._geometry:
frame["distance"] = array["distance"]

Check warning on line 87 in src/vroom/solution/solution.py

View check run for this annotation

Codecov / codecov/patch

src/vroom/solution/solution.py#L87

Added line #L87 was not covered by tests
return frame

def to_dict(self) -> Dict[str, Any]:
"""Convert solution into VROOM compatible dictionary."""
stream = io.StringIO()
with redirect_stdout(stream):
self._solution_json()
if self._geometry:
self._geometry_solution_json()

Check warning on line 95 in src/vroom/solution/solution.py

View check run for this annotation

Codecov / codecov/patch

src/vroom/solution/solution.py#L95

Added line #L95 was not covered by tests
else:
self._solution_json()
return json.loads(stream.getvalue())

def to_json(self, filepath: Union[str, Path]) -> None:
"""Store solution into VROOM compatible JSON file."""
with open(filepath, "w") as handler:
with redirect_stdout(handler):
self._solution_json()
if self._geometry:
self._geometry_solution_json()

Check warning on line 105 in src/vroom/solution/solution.py

View check run for this annotation

Codecov / codecov/patch

src/vroom/solution/solution.py#L104-L105

Added lines #L104 - L105 were not covered by tests
else:
self._solution_json()

Check warning on line 107 in src/vroom/solution/solution.py

View check run for this annotation

Codecov / codecov/patch

src/vroom/solution/solution.py#L107

Added line #L107 was not covered by tests
Loading