Skip to content

Commit

Permalink
Fix issue gephi#472
Browse files Browse the repository at this point in the history
  • Loading branch information
mbastian committed Nov 13, 2011
1 parent 381401b commit 112353d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Algorithms/manifest.mf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Manifest-Version: 1.0
AutoUpdate-Essential-Module: true
OpenIDE-Module: org.gephi.algorithms
OpenIDE-Module-Localizing-Bundle: org/gephi/algorithms/Bundle.properties
OpenIDE-Module-Specification-Version: 0.8
OpenIDE-Module-Specification-Version: 0.8.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -75,44 +75,43 @@ public DijkstraShortestPathAlgorithm(Graph graph, Node sourceNode) {
public void compute() {

graph.readLock();
Set<Node> nodes = new HashSet<Node>();
Set<Node> unsettledNodes = new HashSet<Node>();
Set<Node> settledNodes = new HashSet<Node>();

//Initialize
int nodeCount = 0;
for (Node node : graph.getNodes()) {
distances.put(node, Double.POSITIVE_INFINITY);
nodes.add(node);
nodeCount++;
}
distances.put(sourceNode, 0d);
unsettledNodes.add(sourceNode);

while (!nodes.isEmpty()) {
while (!unsettledNodes.isEmpty()) {

// find node with smallest distance value
Double minDistance = Double.POSITIVE_INFINITY;
Node minDistanceNode = null;
for (Node k : nodes) {
for (Node k : unsettledNodes) {
Double dist = distances.get(k);
if (dist.compareTo(minDistance) < 0) {
if (minDistanceNode == null) {
minDistanceNode = k;
} else if (dist.compareTo(minDistance) < 0) {
minDistance = dist;
minDistanceNode = k;
}
}
Node currentNode = minDistanceNode;
nodes.remove(currentNode);

for (Edge edge : graph.getEdges(currentNode)) {
Node neighbor = graph.getOpposite(currentNode, edge);
double dist = edgeWeight(edge) + distances.get(currentNode);
if (distances.get(neighbor).equals(Double.POSITIVE_INFINITY)) {
distances.put(neighbor, dist);
maxDistance = Math.max(maxDistance, dist);
predecessors.put(neighbor, edge);
} else {
if (dist < distances.get(neighbor)) {
unsettledNodes.remove(minDistanceNode);
settledNodes.add(minDistanceNode);

for (Edge edge : graph.getEdges(minDistanceNode)) {
Node neighbor = graph.getOpposite(minDistanceNode, edge);
if (!settledNodes.contains(neighbor)) {
double dist = getShortestDistance(minDistanceNode) + edgeWeight(edge);
if (getShortestDistance(neighbor) > dist) {

distances.put(neighbor, dist);
maxDistance = Math.max(maxDistance, dist);
predecessors.put(neighbor, edge);
unsettledNodes.add(neighbor);
maxDistance = Math.max(maxDistance, dist);
}
}
}
Expand All @@ -121,6 +120,15 @@ public void compute() {
graph.readUnlock();
}

private double getShortestDistance(Node destination) {
Double d = distances.get(destination);
if (d == null) {
return Double.POSITIVE_INFINITY;
} else {
return d;
}
}

@Override
protected double edgeWeight(Edge edge) {
if (timeInterval != null) {
Expand Down
2 changes: 1 addition & 1 deletion ToolsPlugin/manifest.mf
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ AutoUpdate-Essential-Module: true
OpenIDE-Module: org.gephi.tools.plugin
OpenIDE-Module-Layer: org/gephi/tools/plugin/layer.xml
OpenIDE-Module-Localizing-Bundle: org/gephi/tools/plugin/Bundle.properties
OpenIDE-Module-Specification-Version: 0.8.0.1
OpenIDE-Module-Specification-Version: 0.8.0.2

4 changes: 3 additions & 1 deletion ToolsPlugin/src/org/gephi/tools/plugin/HeatMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Development and Distribution License("CDDL") (collectively, the
import java.awt.Color;
import java.text.DecimalFormat;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
Expand Down Expand Up @@ -153,7 +155,7 @@ public void clickNodes(Node[] nodes) {
n.getNodeData().setColor(c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f);
heatMapPanel.setStatus(NbBundle.getMessage(HeatMap.class, "HeatMap.status.maxdistance") + new DecimalFormat("#.##").format(algorithm.getMaxDistance()));
} catch (Exception e) {
e.printStackTrace();
Logger.getLogger("").log(Level.SEVERE, "", e);
}
}
};
Expand Down

0 comments on commit 112353d

Please sign in to comment.