diff --git a/aequilibrae/paths/route_choice.pyx b/aequilibrae/paths/route_choice.pyx index 93d635532..e07fb26c2 100644 --- a/aequilibrae/paths/route_choice.pyx +++ b/aequilibrae/paths/route_choice.pyx @@ -147,7 +147,7 @@ cdef class RouteChoiceSet: **route set** (:obj:`list[tuple[int, ...]]): Returns a list of unique variable length tuples of compact link IDs. Represents paths from ``origin`` to ``destination``. """ - return self.batched([(origin, destination)], max_routes=max_routes, max_depth=max_depth, seed=seed, a_star=a_star)[(origin, destination)] + return [tuple(x) for x in self.batched([(origin, destination)], max_routes=max_routes, max_depth=max_depth, seed=seed, a_star=a_star).column("route set").to_pylist()] # Bounds checking doesn't really need to be disabled here but the warning is annoying @cython.boundscheck(False) @@ -184,11 +184,6 @@ cdef class RouteChoiceSet: each OD pair provided (as keys). Represents paths from ``origin`` to ``destination``. None if ``where`` was not None. """ cdef: - long long origin_index, dest_index, i - unsigned int c_max_routes = max_routes - unsigned int c_max_depth = max_depth - unsigned int c_seed = seed - unsigned int c_cores = cores long long o, d if max_routes == 0 and max_depth == 0: @@ -204,6 +199,12 @@ cdef class RouteChoiceSet: raise ValueError(f"Destination {d} is not present within the compact graph") cdef: + long long origin_index, dest_index, i + unsigned int c_max_routes = max_routes + unsigned int c_max_depth = max_depth + unsigned int c_seed = seed + unsigned int c_cores = cores + vector[pair[long long, long long]] c_ods # A* (and Dijkstra's) require memory views, so we must allocate here and take slices. Python can handle this memory diff --git a/tests/aequilibrae/paths/test_route_choice.py b/tests/aequilibrae/paths/test_route_choice.py index 1a7b89508..a43d7a0b2 100644 --- a/tests/aequilibrae/paths/test_route_choice.py +++ b/tests/aequilibrae/paths/test_route_choice.py @@ -69,8 +69,8 @@ def test_route_choice_empty_path(self): rc = RouteChoiceSet(self.graph) a = 1 - self.assertEqual( - rc.batched([(a, a)], max_routes=0, max_depth=3), {(a, a): []}, "Route set from self to self should be empty" + self.assertFalse( + rc.batched([(a, a)], max_routes=0, max_depth=3), "Route set from self to self should be empty" ) def test_route_choice_blocking_centroids(self): @@ -96,11 +96,12 @@ def test_route_choice_batched(self): max_routes = 20 results = rc.batched(nodes, max_routes=max_routes, max_depth=10, cores=1) - self.assertEqual(len(results), len(nodes), "Requested number of route sets not returned") + gb = results.to_pandas().groupby(by="origin id") + self.assertEqual(len(gb), len(nodes), "Requested number of route sets not returned") - for od, route_set in results.items(): - self.assertEqual(len(route_set), len(set(route_set)), f"Duplicate routes returned for {od}") - self.assertEqual(len(route_set), max_routes, f"Requested number of routes not returned for {od}") + for _, row in gb: + self.assertFalse(any(row["route set"].duplicated()), f"Duplicate routes returned for {row['origin id']}") + self.assertEqual(len(row["route set"]), max_routes, f"Requested number of routes not returned for {row['origin id']}") def test_route_choice_exceptions(self): rc = RouteChoiceSet(self.graph)