Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Moss committed Feb 12, 2024
1 parent eecaaa3 commit 945e8a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions aequilibrae/paths/route_choice.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions tests/aequilibrae/paths/test_route_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down

0 comments on commit 945e8a9

Please sign in to comment.