1
クエリを書く方法はグラフ上で実行され、各エッジを1度だけ通過するパスがない場合は「false」を出力し、ポイント。エッジに1回だけアクセスしたグラフにサイクルが存在するかどうかを確認するクエリ
私は、次の sample graphを使用していたクエリを書く方法はグラフ上で実行され、各エッジを1度だけ通過するパスがない場合は「false」を出力し、ポイント。エッジに1回だけアクセスしたグラフにサイクルが存在するかどうかを確認するクエリ
私は、次の sample graphを使用していた:
g = TinkerGraph.open().traversal()
g.addV().property(id, 'blue').as('b').
addV().property(id, 'orange').as('o').
addV().property(id, 'red').as('r').
addV().property(id, 'white').as('w').
addE('bridge').from('w').to('b').
addE('bridge').from('w').to('o').
addE('bridge').from('w').to('r').
addE('bridge').from('w').to('r').
addE('bridge').from('o').to('b').
addE('bridge').from('o').to('b').
addE('bridge').from('o').to('r').
addE('bridge').from('o').to('r').iterate()
次のクエリは、最初の可能なパスを返します:あなたが必要とするすべてがブール値である場合は、ちょうど.hasNext()
を追加し、
gremlin> g.V().sideEffect(outE("bridge").aggregate("bridges")).barrier().
......1> repeat(bothE().or(__.not(select('e')),
......2> __.not(filter(__.as('x').select(all, 'e').unfold().where(eq('x'))))).as('e').otherV()).
......3> until(select(all, 'e').count(local).as("c").select("bridges").count(local).where(eq("c"))).limit(1).
......4> path().by(id).by(constant(" -> ")).map {String.join("", it.get().objects())}
==>orange -> blue -> white -> orange -> red -> white -> red -> orange -> blue
を:
g.V().sideEffect(outE("bridge").aggregate("bridges")).barrier().
repeat(bothE().or(__.not(select('e')),
__.not(filter(__.as('x').select(all, 'e').unfold().where(eq('x'))))).as('e').otherV()).
until(select(all, 'e').count(local).as("c").select("bridges").count(local).where(eq("c"))).hasNext()
これは、すべての頂点をループし、合計nu両方のcount()。count()%2 == 0は0または2です。私はそれを表現するためにトラバーサルをまだヌードルしています。 –
はい。トラバースは最も難しい部分です。まだそれを取得しようとしています。 –