2017-02-23 8 views
2

2つのノード間の最短経路を計算しますが、一部のノードの属性に格納されている長さの値を考慮しています。neo4j内のすべてのパスに沿ってノード属性を合計

match (origin:type1 {t1id:"start"}), 
    (dest:type2 {t2id:"end"}), 
    path= (origin)<-[:JOINS]-()-[:JOINS*..10]-()<-[:PARKING]-(dest) 
    with extract(n in NODES(path) | n._length) as x 
    return x 

ノードの3つのタイプがあり、パスは次のとおりです。

(type1)-[:JOINS]-(type2)-[:JOINS]-(type1)-[:JOINS]-(type2)-...<-[:PARK]-(type3) 

は、クエリは、上記のパス(下)のリストが表示されますが、私は一緒に値を合計する方法を見つけることができません個々のパスの合計長さを指定します。ヌル値は、長さの値を持たないタイプ2のノードに関連しています。

x 
[8.06, null, 34.25, null, 46.52, null, 37.38, null, 44.2, null] 
[8.06, null, 34.25, null, 32.41, null, 31.3, null, 19, null, 44.2, null] 
[8.06, null, 34.25, null, 14.63, null, 44.2, null] 
[8.06, null, 32.41, null, 46.52, null, 37.38, null, 44.2, null] 
[8.06, null, 32.41, null, 34.25, null, 31.3, null, 19, null, 44.2, null] 
[8.06, null, 32.41, null, 14.63, null, 44.2, null] 
[8.06, null, 31.3, null, 35.86, null, 57.93, null, 55.35, null, 44.2, null] 
[8.06, null, 31.3, null, 19, null, 44.2, null] 

私は(下記)パスで区切られたすべての長さのリストを提供していない、それをほどく使用

y 
8.06 
null 
34.25 
null 
46.52 
null 
37.38 
null 
44.2 
null 
8.06 
null 
34.25 
null 
...etc 

すべてのヘルプやアドバイスをいただければ幸いです。

答えて

1

あなたがreducecaseを必要とpath凝集によって:

match (origin:type1 {t1id:"start"}), 
     (dest:type2 {t2id:"end"}) 
with origin, dest 
match path= (origin)<-[:JOINS]-()-[:JOINS*..10]-()<-[:PARKING]-(dest) 
return path, 
     reduce(acc=0, n in nodes(path) | 
       acc + case when n._length is null then 0 else n._length end 
     ) as pathLength 
+0

ああ優れたありがとう、完璧に動作します! – SAB

関連する問題