Skip to content

Commit

Permalink
removing amount from input
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathf committed Dec 1, 2024
1 parent 2970f62 commit deb1042
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 40 deletions.
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)
2714
4041
Installation
------------
Expand Down
2 changes: 0 additions & 2 deletions src/bind/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ void init_input(py::module_ &m) {
vroom::Matrix<vroom::UserCost> &m) {
self.set_costs_matrix(profile, std::move(m));
})
.def("zero_amount", &vroom::Input::zero_amount)
.def("has_skills", &vroom::Input::has_skills)
.def("has_jobs", &vroom::Input::has_jobs)
.def("has_shipments", &vroom::Input::has_shipments)
Expand All @@ -53,7 +52,6 @@ void init_input(py::module_ &m) {
&vroom::Input::has_homogeneous_locations)
.def("has_homogeneous_profiles", &vroom::Input::has_homogeneous_profiles)
.def("has_homogeneous_costs", &vroom::Input::has_homogeneous_costs)

Check warning on line 54 in src/bind/input/input.cpp

View check run for this annotation

Codecov / codecov/patch

src/bind/input/input.cpp#L54

Added line #L54 was not covered by tests
// .def("vehicle_ok_with_job", &vroom::Input::vehicle_ok_with_job)
.def("_solve", &vroom::Input::solve, "Solve problem.",
py::arg("nb_searches"),
py::arg("depth"),
Expand Down
50 changes: 13 additions & 37 deletions src/vroom/input/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Input(_vroom.Input):

def __init__(
self,
amount_size: Optional[int] = None,
servers: Optional[Dict[str, Union[str, _vroom.Server]]] = None,
router: _vroom.ROUTER = _vroom.ROUTER.OSRM,
apply_TSPFix: bool = False,
Expand All @@ -45,9 +44,6 @@ def __init__(
"""Class initializer.
Args:
amount_size:
The size of the job to be transported. Used to verify all jobs
have the same size limit.
servers:
Assuming no custom duration matrix is provided (from
`set_durations_matrix`), use this dict to configure the
Expand All @@ -66,7 +62,6 @@ def __init__(
for key, server in servers.items():
if isinstance(server, str):
servers[key] = _vroom.Server(*server.split(":"))
self._amount_size = amount_size
self._servers = servers
self._router = router
_vroom.Input.__init__(
Expand All @@ -75,16 +70,12 @@ def __init__(
router=router,
apply_TSPFix=apply_TSPFix,
)
if amount_size is not None:
self._set_amount_size(amount_size)
if geometry:
self.set_geometry()

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

View check run for this annotation

Codecov / codecov/patch

src/vroom/input/input.py#L74

Added line #L74 was not covered by tests

def __repr__(self) -> str:
"""String representation."""
args = []
if self._amount_size is not None:
args.append(f"amount_size={self._amount_size}")
if self._servers:
args.append(f"servers={self._servers}")
if self._router != _vroom.ROUTER.OSRM:
Expand Down Expand Up @@ -135,18 +126,6 @@ def set_geometry(self):
self._geometry = True
return self._set_geometry(True)

def set_amount_size(self, *amount_sizes: int) -> None:
"""Add amount sizes."""
sizes = set(amount_sizes)
if self._amount_size is not None:
sizes.add(self._amount_size)
if len(sizes) > 1:
raise _vroom.VroomInputException(f"Inconsistent capacity lengths: {sizes}")
if self._amount_size is None:
size = sizes.pop()
self._amount_size = size
self._set_amount_size(size)

def add_job(
self,
job: Union[Job, Shipment, Sequence[Job], Sequence[Shipment]],
Expand All @@ -172,14 +151,9 @@ def add_job(
jobs = [job] if isinstance(job, (Job, Shipment)) else job
for job_ in jobs:
if isinstance(job_, Job):
if job_._pickup:
self.set_amount_size(len(job_._pickup))
if job_._delivery:
self.set_amount_size(len(job_._delivery))
self._add_job(job_)

elif isinstance(job_, Shipment):
self.set_amount_size(len(job_.amount))
self._add_shipment(
_vroom.Job(
id=job_.pickup.id,
Expand Down Expand Up @@ -236,7 +210,6 @@ def add_shipment(
The job priority level, where 0 is the most
important and 100 is the least important.
"""
self.set_amount_size(len(amount))
if skills is None:
skills = set()
self._add_shipment(
Expand Down Expand Up @@ -281,7 +254,6 @@ def add_vehicle(
vehicles = [vehicle] if isinstance(vehicle, _vroom.Vehicle) else vehicle
if not vehicles:
return
self.set_amount_size(*[len(vehicle_.capacity) for vehicle_ in vehicles])
for vehicle_ in vehicles:
self._add_vehicle(vehicle_)

Expand Down Expand Up @@ -348,32 +320,36 @@ def set_costs_matrix(

def solve(
self,
nb_searches,
depth,
exploration_level: int,
nb_threads: int = 4,
timeout: Optional[timedelta] = None,
h_params = (),
h_param = (),
) -> Solution:
"""Solve routing problem.
Args:
nb_searches:
depth:
exploration_level:
The exploration level to use. Number between 1 and 5.
nb_threads:
The number of available threads.
timeout:
Stop the solving process after a given amount of time.
h_params:
"""
assert isinstance(timeout, (None, timedelta)), (
assert timeout is None or isinstance(timeout, timedelta), (
f"unknown timeout type: {timeout}")
assert exploration_level <= 5
nb_searches = 4 * (exploration_level + 1)
if exploration_level >= 4:
nb_searches += 4
if exploration_level == 5:
nb_searches += 4
solution = Solution(
self._solve(
nb_searches=nb_searches,
depth=depth,
depth=int(exploration_level),
nb_threads=int(nb_threads),
timeout=timeout,
h_params=list(h_params),
h_param=list(h_param),
)
)
solution._geometry = self._geometry
Expand Down

0 comments on commit deb1042

Please sign in to comment.