diff --git a/README.rst b/README.rst index 89fd73c..569c673 100644 --- a/README.rst +++ b/README.rst @@ -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 ------------ diff --git a/src/bind/input/input.cpp b/src/bind/input/input.cpp index 73dcb9c..b61cda7 100644 --- a/src/bind/input/input.cpp +++ b/src/bind/input/input.cpp @@ -44,7 +44,6 @@ void init_input(py::module_ &m) { vroom::Matrix &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) @@ -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) - // .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"), diff --git a/src/vroom/input/input.py b/src/vroom/input/input.py index 375c00d..c36582d 100644 --- a/src/vroom/input/input.py +++ b/src/vroom/input/input.py @@ -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, @@ -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 @@ -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__( @@ -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() 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: @@ -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]], @@ -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, @@ -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( @@ -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_) @@ -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