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;

以上。