// Пример использования функции test.distance match (a:Place)-[e:EROAD]->(b:Place) return test.distance( a.latitude, a.longitude, b.latitude, b.longitude), e.distance // Procedure - запуск MATCH (t:Test) WITH COLLECT(t) as nodeList CALL test.allSingleNodes(nodeList) YIELD singleNode RETURN singleNode; // BFS CALL gds.graph.project('myGraph', 'Place', 'EROAD', { relationshipProperties: 'distance' } ); MATCH (a:Place {id: 'Amsterdam'}) WITH id(a) AS startNode CALL gds.bfs.stream('myGraph', {sourceNode: startNode}) YIELD path UNWIND [ n in nodes(path) | n.id ] AS ids RETURN ids ORDER BY ids; // Алгоритм Дейкстры allShortestPaths MATCH (source:Place {id: 'Amsterdam'}) CALL gds.allShortestPaths.dijkstra.stream('myGraph', { sourceNode: id(source), relationshipWeightProperty: 'distance' }) YIELD index, sourceNode, targetNode, totalCost, nodeIds, costs RETURN index, gds.util.asNode(sourceNode).id AS sourceNodeName, gds.util.asNode(targetNode).id AS targetNodeName, totalCost, [ nodeId IN nodeIds | gds.util.asNode(nodeId).id] AS nodeNames, costs ORDER BY index; // Алгоритм Дейкстры MATCH (source:Place {id: 'Amsterdam'}), (target:Place {id: 'London'}) CALL apoc.algo.dijkstra(source, target, 'EROAD', 'distance') YIELD path, weight RETURN [p in nodes(path) | p.id] as names, weight; // Yen’s shortest paths MATCH (source:Place {id: 'Amsterdam'}), (target:Place {id: 'London'}) CALL gds.shortestPath.yens.stream('myGraph', { sourceNode: id(source), targetNode: id(target), k: 3, relationshipWeightProperty: 'distance' }) YIELD index, sourceNode, targetNode, totalCost, nodeIds, costs RETURN index, gds.util.asNode(sourceNode).id AS sourceNodeName, gds.util.asNode(targetNode).id AS targetNodeName, totalCost, [nodeId IN nodeIds | gds.util.asNode(nodeId).id] AS nodeNames, costs ORDER BY index; // PageRank CALL gds.pageRank.stream('myGraph') YIELD nodeId, score RETURN gds.util.asNode(nodeId).id AS name, score ORDER BY score DESC, name ASC; // Connected Components // Тестовый датасет UNWIND range(1,10) as id CREATE (:Test {id: id}); with [i in range(1,20) | toInteger(rand()*10+1)] as rnd unwind [i in range(0,9)| [rnd[i], rnd[10+i]]] as pairs match (a:Test {id: pairs[0]}), (b:Test {id: pairs[1]}) where a.id <> b.id merge (a)-[:LINK]->(b) merge (b)-[:LINK]->(a); // Connected Components Проверка CALL gds.graph.project( 'Test', 'Test', 'LINK', {} ); CALL gds.alpha.scc.stream('Test') YIELD nodeId, componentId RETURN gds.util.asNode(nodeId).id AS Name, componentId AS Component ORDER BY Component DESC;