赞
踩
一.介绍:
单源最短路径算法:
给定带权有向图G=(V,E),其中每条边的权都是非负数。给定一个起始顶点,成为源。计算从源到所有其他定点的最短路径长度。路径长度是各边权重之和,该问题称为单源最短路径问题。
基本思想:Dijkstra算法(迪杰斯特拉算法)是解单源最短路径问题的贪心算法
二.neo4j算法
MERGE (a:Loc {name:'A'})
MERGE (b:Loc {name:'B'})
MERGE (c:Loc {name:'C'})
MERGE (d:Loc {name:'D'})
MERGE (e:Loc {name:'E'})
MERGE (f:Loc {name:'F'})
MERGE (a)-[:ROAD {cost:50}]->(b)
MERGE (a)-[:ROAD {cost:50}]->(c)
MERGE (a)-[:ROAD {cost:100}]->(d)
MERGE (b)-[:ROAD {cost:40}]->(d)
MERGE (c)-[:ROAD {cost:40}]->(d)
MERGE (c)-[:ROAD {cost:80}]->(e)
MERGE (d)-[:ROAD {cost:30}]->(e)
MERGE (d)-[:ROAD {cost:80}]->(f)
MERGE (e)-[:ROAD {cost:40}]->(f)
match(n:Loc{name:'A'})
call algo.shortestPath.deltaStepping.stream(n,'cost',3.0)
yield nodeId,distance
return algo.getNodeById(nodeId).name AS NAME,distance
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。