neo4jでsandbox その4
概要
neo4jでsandboxやってみた。
最短経路、やってみた。
参考にしたページ
写真
nodeとrelasionを投入。
CREATE (p1:Point {name:"p1"}),
(p2:Point {name:"p2"}),
(p3:Point {name:"p3"}),
(p4:Point {name:"p4"}),
(p5:Point {name:"p5"}),
(p1)-[:Route {weight:7}]->(p2),
(p1)-[:Route {weight:5}]->(p3),
(p1)-[:Route {weight:8}]->(p4),
(p1)-[:Route {weight:9}]->(p5),
(p2)-[:Route {weight:3}]->(p3),
(p2)-[:Route {weight:2}]->(p4),
(p2)-[:Route {weight:1}]->(p5),
(p3)-[:Route {weight:4}]->(p4),
(p3)-[:Route {weight:7}]->(p5),
(p4)-[:Route {weight:9}]->(p5);
p1からp5の最短経路を求める。
MATCH g = (:Point {name:"p1"})-[:Route*]-(:Point {name:"p5"})
RETURN g, REDUCE(weight = 0, r in RELATIONSHIPS(g) | weight + r.weight) AS score
ORDER BY score ASC
LIMIT 1;
CREATE (p1:Point {name:"p1"}),
(p2:Point {name:"p2"}),
(p3:Point {name:"p3"}),
(p4:Point {name:"p4"}),
(p5:Point {name:"p5"}),
(p1)-[:Route {weight:7}]->(p2),
(p1)-[:Route {weight:5}]->(p3),
(p1)-[:Route {weight:8}]->(p4),
(p1)-[:Route {weight:9}]->(p5),
(p2)-[:Route {weight:3}]->(p3),
(p2)-[:Route {weight:2}]->(p4),
(p2)-[:Route {weight:1}]->(p5),
(p3)-[:Route {weight:4}]->(p4),
(p3)-[:Route {weight:7}]->(p5),
(p4)-[:Route {weight:9}]->(p5);
MATCH g = (:Point {name:"p1"})-[:Route*]-(:Point {name:"p5"})
RETURN g, REDUCE(weight = 0, r in RELATIONSHIPS(g) | weight + r.weight) AS score
ORDER BY score ASC
LIMIT 1;
以上。
Author And Source
この問題について(neo4jでsandbox その4), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/ed8de9085143403fb163著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .