1
您好,我目前正在研究Dijkstras算法。我想要計算所選特定邊的數量,以便更改下一個邊的成本等。添加特定邊的次數有問題。我鏈接了我的部分代碼。計算Dijkstra算法的特定邊緣
Edge dirC = new Edge("d" + nodes.get(i * ds.columns + j), nodes.get(i * ds.columns + j), nodes.get((i + 1) * ds.columns + j), downcost1);
edges.add(dirC);
在這一部分的特定邊緣 「DIRC」 被添加。我想添加一個「dicCcount」,然後獲取計數器的值,以便在該部分運行後在if語句中使用它。 Edge類看起來像這樣。
package autonavigate;
public class Edge {
private final String id;
private final Vertex source;
private final Vertex destination;
private final double weight;
public Edge(String id, Vertex source, Vertex destination, double weight) {
this.id = id;
this.source = source;
this.destination = destination;
this.weight = weight;
}
public String getId() {
return id;
}
public Vertex getDestination() {
return destination;
}
public Vertex getSource() {
return source;
}
public double getWeight() {
return weight;
}
@Override
public String toString() {
return source + " " + destination;
}
}
我試圖解決這個問題了幾個小時,但我無法弄清楚如何做到這一點。它不是一個家庭作業,它是我爲遙控車所做的一個程序:)。
任何建議如何做到這一點?