Package org.gephi.algorithms.shortestpath

Examples of org.gephi.algorithms.shortestpath.AbstractShortestPathAlgorithm


                        gradientPositions = positions = heatMapPanel.getGradientPositions();
                        dontPaintUnreachable = heatMapPanel.isDontPaintUnreachable();
                    }
                    GraphController gc = Lookup.getDefault().lookup(GraphController.class);

                    AbstractShortestPathAlgorithm algorithm;
                    if (gc.getModel().getGraphVisible() instanceof DirectedGraph) {
                        DirectedGraph graph = (DirectedGraph) gc.getModel().getGraphVisible();
                        algorithm = new BellmanFordShortestPathAlgorithm(graph, n);
                        algorithm.compute();
                    } else {
                        Graph graph = gc.getModel().getGraphVisible();
                        algorithm = new DijkstraShortestPathAlgorithm(graph, n);
                        algorithm.compute();
                    }

                    //Color
                    LinearGradient linearGradient = new LinearGradient(colors, positions);

                    //Algorithm


                    double maxDistance = algorithm.getMaxDistance();
                    if (!dontPaintUnreachable) {
                        maxDistance++;   //+1 to have the maxdistance nodes a ratio<1
                    }
                    if (maxDistance > 0) {
                        for (Entry<Node, Double> entry : algorithm.getDistances().entrySet()) {
                            NodeData node = entry.getKey().getNodeData();
                            if (!Double.isInfinite(entry.getValue())) {
                                float ratio = (float) (entry.getValue() / maxDistance);
                                Color c = linearGradient.getValue(ratio);
                                node.setColor(c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f);
                            } else if (!dontPaintUnreachable) {
                                Color c = colors[colors.length - 1];
                                node.setColor(c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f);
                            }
                        }
                    }
                    Color c = colors[0];
                    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();
                }
            }
        };
View Full Code Here


                    color = shortestPathPanel.getColor();
                    float[] colorArray = new float[]{color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f};
                    Node targetNode = n;
                    GraphController gc = Lookup.getDefault().lookup(GraphController.class);

                    AbstractShortestPathAlgorithm algorithm;
                    if (gc.getModel().getGraphVisible() instanceof DirectedGraph) {
                        algorithm = new BellmanFordShortestPathAlgorithm((DirectedGraph) gc.getModel().getGraphVisible(), sourceNode);
                    } else {
                        algorithm = new DijkstraShortestPathAlgorithm(gc.getModel().getGraphVisible(), sourceNode);
                    }
                    algorithm.compute();

                    double distance;
                    if ((distance = algorithm.getDistances().get(targetNode)) != Double.POSITIVE_INFINITY) {
                        targetNode.getNodeData().setColor(colorArray[0], colorArray[1], colorArray[2]);
                        VizController.getInstance().selectNode(targetNode);
                        Edge predecessorEdge = algorithm.getPredecessorIncoming(targetNode);
                        Node predecessor = algorithm.getPredecessor(targetNode);
                        while (predecessorEdge != null && predecessor != sourceNode) {
                            predecessorEdge.getEdgeData().setColor(colorArray[0], colorArray[1], colorArray[2]);
                            VizController.getInstance().selectEdge(predecessorEdge);
                            predecessor.getNodeData().setColor(colorArray[0], colorArray[1], colorArray[2]);
                            VizController.getInstance().selectNode(predecessor);
                            predecessorEdge = algorithm.getPredecessorIncoming(predecessor);
                            predecessor = algorithm.getPredecessor(predecessor);
                        }
                        predecessorEdge.getEdgeData().setColor(colorArray[0], colorArray[1], colorArray[2]);
                        VizController.getInstance().selectEdge(predecessorEdge);
                        sourceNode.getNodeData().setColor(colorArray[0], colorArray[1], colorArray[2]);
                        VizController.getInstance().selectNode(sourceNode);
View Full Code Here

                        gradientPositions = positions = heatMapPanel.getGradientPositions();
                        dontPaintUnreachable = heatMapPanel.isDontPaintUnreachable();
                    }
                    GraphController gc = Lookup.getDefault().lookup(GraphController.class);

                    AbstractShortestPathAlgorithm algorithm;
                    if (gc.getGraphModel().isDirected()) {
                        DirectedGraph graph = gc.getGraphModel().getDirectedGraphVisible();
                        algorithm = new BellmanFordShortestPathAlgorithm(graph, n);
                        algorithm.compute();
                    } else {
                        Graph graph = gc.getGraphModel().getGraphVisible();
                        algorithm = new DijkstraShortestPathAlgorithm(graph, n);
                        algorithm.compute();
                    }

                    //Color
                    LinearGradient linearGradient = new LinearGradient(colors, positions);

                    //Algorithm


                    double maxDistance = algorithm.getMaxDistance();
                    if (!dontPaintUnreachable) {
                        maxDistance++;   //+1 to have the maxdistance nodes a ratio<1
                    }
                    if (maxDistance > 0) {
                        for (Entry<Node, Double> entry : algorithm.getDistances().entrySet()) {
                            Node node = entry.getKey();
                            if (!Double.isInfinite(entry.getValue())) {
                                float ratio = (float) (entry.getValue() / maxDistance);
                                Color c = linearGradient.getValue(ratio);
                                node.setColor(c);
                            } else if (!dontPaintUnreachable) {
                                Color c = colors[colors.length - 1];
                                node.setColor(c);
                            }
                        }
                    }
                    Color c = colors[0];
                    n.setColor(c);
                    heatMapPanel.setStatus(NbBundle.getMessage(HeatMap.class, "HeatMap.status.maxdistance") + new DecimalFormat("#.##").format(algorithm.getMaxDistance()));
                } catch (Exception e) {
                    Logger.getLogger("").log(Level.SEVERE, "", e);
                }
            }
        };
View Full Code Here

                    color = shortestPathPanel.getColor();
                    Node targetNode = n;
                    GraphController gc = Lookup.getDefault().lookup(GraphController.class);
                    GraphModel gm = gc.getGraphModel();

                    AbstractShortestPathAlgorithm algorithm;
                    if (gm.isDirected()) {
                        algorithm = new BellmanFordShortestPathAlgorithm(gm.getDirectedGraphVisible(), sourceNode);
                    } else {
                        algorithm = new DijkstraShortestPathAlgorithm(gm.getGraphVisible(), sourceNode);
                    }
                    algorithm.compute();

                    double distance;
                    if ((distance = algorithm.getDistances().get(targetNode)) != Double.POSITIVE_INFINITY) {
                        targetNode.setColor(color);
                        VizController.getInstance().selectNode(targetNode);
                        Edge predecessorEdge = algorithm.getPredecessorIncoming(targetNode);
                        Node predecessor = algorithm.getPredecessor(targetNode);
                        while (predecessorEdge != null && predecessor != sourceNode) {
                            predecessorEdge.setColor(color);
                            VizController.getInstance().selectEdge(predecessorEdge);
                            predecessor.setColor(color);
                            VizController.getInstance().selectNode(predecessor);
                            predecessorEdge = algorithm.getPredecessorIncoming(predecessor);
                            predecessor = algorithm.getPredecessor(predecessor);
                        }
                        predecessorEdge.setColor(color);
                        VizController.getInstance().selectEdge(predecessorEdge);
                        sourceNode.setColor(color);
                        VizController.getInstance().selectNode(sourceNode);
View Full Code Here

TOP

Related Classes of org.gephi.algorithms.shortestpath.AbstractShortestPathAlgorithm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.