1

ノード間にいくつかのノードとリンク (関係) があります。

デフォルトでは、ダイクストラ (neo4j 内) は関係のコスト プロパティを考慮して、ノード間の最短パスを見つけます。

ノードのコスト特性も考慮したいので、次のように定義しましたcostEvaluator

CostEvaluator<Double> costEvaluator = new CostEvaluator<Double>() {
            @Override
            public Double getCost(Relationship relationship, Direction direction) {
                Long costR = (Long) relationship.getProperty("cost");
                Long costE = (Long) relationship.getEndNode().getProperty("cost");
                Long cost = costR + costE; 
                return cost.doubleValue();
            }
        };

次のコードで使用しました。

    PathFinder<WeightedPath> finder = GraphAlgoFactory.dijkstra(
            Traversal.expanderForTypes(ROAD, Direction.BOTH), 
            costEvaluator);

    WeightedPath path = finder.findSinglePath(node1, node2);

    System.out.println("Path weight: " + path.weight());
    for (Node n: path.nodes()) {
        System.out.println("Node: " + n.getId() + "-" +  n.getProperty("cost"));
    }
    for (Relationship r: path.relationships()) {
        System.out.println("Relationship: " + r.getId() + "-" + r.getProperty("cost") );
    }

このコードを実行すると、次の結果が得られます。

Path weight: 1395.0
Node: 106-100
Node: 29-30
Node: 85-30
Node: 16-40
Node: 10-100
Node: 152-60
Relationship: 344-334
Relationship: 13-398
Relationship: 406-38
Relationship: 326-146
Relationship: 500-289

なぜパスの重みは 1395 なのですか? 1465 にする必要があります (私の意見では)。

関係のコスト: 334 + 398 + 38 + 146 + 289 = 1205

これらの関係のエンド ノードのコスト: 30 + 30 + 40 + 100 + 60 = 260

1205+260=1465

なぜパスの重みは 1395 なのですか?

誰かがそれを説明できますか?

4

0 に答える 0