1

私の仕事はTinkerGraphであり、Javaでそれをやりたいと思っています。

グレムリンは私にはあまり役に立ちません

g.V().has(id1).
  repeat(both().simplePath()).
    until(has(id2)).as("path").
  map(unfold().coalesce(values("weight"),
                        constant(0)).
      sum()).as("cost").
  select("cost","path").next().get("path");

これにより、エッジの重みプロパティを考慮せずに最短経路が得られます。

編集:私の例:

挿入されたエッジ:

ソース・ターゲット

b1,b2

b1,b2

b1,b2

b1,b2

b1,b3

b3,b2

private void add(Vertex source,Vertex target){
    if(!checkEdgeExist(graph,source,target))
        source.addEdge(target).property(WEIGHT,1.0);
    else {
        Edge e = getEdgeBetweenTwoVertices(graph,source,target);
       source.edges(Direction.OUT).forEachRemaining(edge -> {
            if(edge.inVertex().equals(target))
                edge.property(WEIGHT,(double)e.property(WEIGHT).value()+1);
        });

    private  static  boolean checkEdgeExist(TinkerGraph graph,Vertex source,Vertex target){
    return graph.traversal().V(source).outE().filter(p -> p.get().inVertex().equals(target)).hasNext();
}

言い換えれば、エッジの重みはエッジの頻度に応じて更新されます。たとえば、b1、b2 が 4 回出現した場合、エッジの重みは 4 になります。ここで、ダイクストラに重みではなく最短パスを返すようにします。エッジに関しては最短です。パス (b1、b2) = b1->b3->b2

4

2 に答える 2