Neo4j获取巴士方向路线申请

时间:2015-08-04 15:20:46

标签: neo4j routes direction

在有火车和火车站的图表中,我应该如何包含火车方向 我已按照此topic说明创建了我的模型。

这是我用两列火车的例子:

Create  
    (A:Stop {nameFr:'A'}),
    (B:Stop {nameFr:'B'}),
    (C:Stop {nameFr:'C'}),
    (D:Stop {nameFr:'D'}),
    (E:Stop {nameFr:'E'}),
    (F:Stop {nameFr:'F'}),
    (G:Stop {nameFr:'G'}),
    (H:Stop {nameFr:'H'}),
    (I:Stop {nameFr:'I'}),

    (A)-[:NEXT]->(B),
    (B)-[:NEXT]->(C),
    (C)-[:NEXT]->(D),
    (D)-[:NEXT]->(E),
    (E)-[:NEXT]->(F),
    (F)-[:NEXT]->(E),
    (E)-[:NEXT]->(D),
    (D)-[:NEXT]->(C),
    (C)-[:NEXT]->(B),
    (B)-[:NEXT]->(A),
    (C)-[:NEXT]->(G),
    (G)-[:NEXT]->(H),
    (H)-[:NEXT]->(I),
    (I)-[:NEXT]->(H),
    (H)-[:NEXT]->(G),
    (G)-[:NEXT]->(C),

    (R1:Train {id:'R1', directionA:'I', directionR:'A'}),
    (R1)-[:STOP_AT {order:'1'}]->(A),
    (R1)-[:STOP_AT {order:'2'}]->(B),
    (R1)-[:STOP_AT {order:'3'}]->(C),
    (R1)-[:STOP_AT {order:'4'}]->(G),
    (R1)-[:STOP_AT {order:'5'}]->(H),
    (R1)-[:STOP_AT {order:'6'}]->(I),

    (R2:Train {id:'R2', directionA:'F', directionR:'B'}),
    (R2)-[:STOP_AT {order:'2'}]->(B),
    (R2)-[:STOP_AT {order:'3'}]->(C),
    (R2)-[:STOP_AT {order:'4'}]->(D),
    (R2)-[:STOP_AT {order:'5'}]->(E),
    (R2)-[:STOP_AT {order:'6'}]->(F);

我的Cypher查询获取路线:

MATCH (A:Stop {nameFr:'A'}), (F:Stop {nameFr:'F'})
MATCH p = allShortestPaths((A)-[:STOP_AT*]-(F))
RETURN EXTRACT(x IN NODES(p) | CASE WHEN x:Stop THEN 'Stop ' + x.nameFr
                                    WHEN x:Train THEN 'Train ' + x.id
                                    ELSE '' END) AS itinerary

我的问题是:我怎样才能得到火车的方向?

编辑: 这是我的例子here: 从停止" A"到了停止" F"我想要这个结果: [停止A,训练R1,方向I,停止B,训练R2,方向F,停止F]

0 个答案:

没有答案