Skip to content

Commit

Permalink
TSP fix route return (rapidsai#1412)
Browse files Browse the repository at this point in the history
The vertex list that was fed as input to TSP was of type `int64` which ended up being corrupted when passed down
to the cpp layer as `vtx_ptr`. I updated the wrapper to cast the vertices to `int32`. In addition, I fixed the handling of nstart in the wrapper which was assuming vertex ids were starting at 1.
Solves: rapidsai#1410

Authors:
  - Hugo Linsenmaier (@hlinsen)

Approvers:
  - Brad Rees (@BradReesWork)

URL: rapidsai#1412
  • Loading branch information
hlinsen committed Feb 17, 2021
1 parent d78f3cb commit cb2d841
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions python/cugraph/traversal/traveling_salesperson.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def traveling_salesperson(pos_list,
restarts=100000,
beam_search=True,
k=4,
nstart=1,
nstart=None,
verbose=False,
):
"""
Expand Down Expand Up @@ -62,7 +62,7 @@ def traveling_salesperson(pos_list,
null_check(pos_list['x'])
null_check(pos_list['y'])

if not pos_list[pos_list['vertex'] == nstart].index:
if nstart is not None and not pos_list[pos_list['vertex'] == nstart].index:
raise ValueError("nstart should be in vertex ids")

route, cost = traveling_salesperson_wrapper.traveling_salesperson(
Expand Down
8 changes: 6 additions & 2 deletions python/cugraph/traversal/traveling_salesperson_wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def traveling_salesperson(pos_list,
restarts=100000,
beam_search=True,
k=4,
nstart=1,
nstart=None,
verbose=False,
renumber=True,
):
Expand All @@ -43,6 +43,7 @@ def traveling_salesperson(pos_list,
cdef uintptr_t x_pos = <uintptr_t>NULL
cdef uintptr_t y_pos = <uintptr_t>NULL

pos_list['vertex'] = pos_list['vertex'].astype(np.int32)
pos_list['x'] = pos_list['x'].astype(np.float32)
pos_list['y'] = pos_list['y'].astype(np.float32)
x_pos = pos_list['x'].__cuda_array_interface__['data'][0]
Expand All @@ -61,7 +62,10 @@ def traveling_salesperson(pos_list,
cdef uintptr_t vtx_ptr = <uintptr_t>NULL
vtx_ptr = pos_list['vertex'].__cuda_array_interface__['data'][0]

renumbered_nstart = pos_list[pos_list['vertex'] == nstart].index[0]
if nstart is None:
renumbered_nstart = 0
else:
renumbered_nstart = pos_list[pos_list['vertex'] == nstart].index[0]

final_cost = c_traveling_salesperson(handle_[0],
<int*> vtx_ptr,
Expand Down

0 comments on commit cb2d841

Please sign in to comment.