Skip to content
Snippets Groups Projects
Commit 77107cbf authored by Stefano Zacchiroli's avatar Stefano Zacchiroli
Browse files

random walk: include starting node into returned path

parent 40daed1e
No related branches found
No related tags found
No related merge requests found
......@@ -288,9 +288,9 @@ public class Traversal {
* that no suitable path have been found
*/
public <T> ArrayList<Long> randomWalk(long srcNodeId, T dst, int retries) {
long curNodeId = srcNodeId;
ArrayList<Long> path = new ArrayList<Long>();
this.nbEdgesAccessed = 0;
long curNodeId = srcNodeId;
boolean found;
if (retries < 0) {
......@@ -298,6 +298,7 @@ public class Traversal {
}
while (true) {
path.add(curNodeId);
long nbNeighbors = graph.degree(curNodeId, useTransposed);
if (nbNeighbors == 0) {
found = false;
......@@ -307,9 +308,8 @@ public class Traversal {
Iterator<Long> successors = neighbors.iterator();
curNodeId = randomPick(successors, nbNeighbors);
path.add(curNodeId);
if (isDstNode(curNodeId, dst)) {
path.add(curNodeId);
found = true;
break;
}
......
......@@ -110,11 +110,10 @@ def test_random_walk(graph_client):
the dataset, and only check the final node of the path (i.e., the origin)
"""
actual = list(graph_client.random_walk(
'swh:1:cnt:0000000000000000000000000000000000000001', 'ori',
direction='backward',
))
src = 'swh:1:cnt:0000000000000000000000000000000000000001'
actual = list(graph_client.random_walk(src, 'ori', direction='backward'))
expected_root = 'swh:1:ori:0000000000000000000000000000000000000021'
assert actual[0] == src
assert actual[-1] == expected_root
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment