Search in sources :

Example 11 with EdgeRef

use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.

the class FRLayoutTest method testFRLayout.

@Test
public void testFRLayout() {
    Graph g = m_graphContainer.getGraph();
    List<Vertex> vertices = new ArrayList<>(g.getDisplayVertices());
    TopoFRLayout<VertexRef, EdgeRef> layout = runFRLayout(g, g.getLayout(), vertices);
    Vertex v1 = vertices.get(0);
    Vertex v2 = vertices.get(1);
    Vertex v3 = vertices.get(2);
    double distance = calcDistance(layout, v1, v2);
    double distance2 = calcDistance(layout, v2, v3);
    double distance3 = calcDistance(layout, v1, v3);
    LOG.info("distance: " + distance);
    LOG.info("distance2: " + distance2);
    LOG.info("distance3: " + distance3);
    // Run again then refactor
    TopoFRLayout<VertexRef, EdgeRef> layout2 = runFRLayout(g, g.getLayout(), vertices);
    distance = calcDistance(layout2, v1, v2);
    distance2 = calcDistance(layout2, v2, v3);
    distance3 = calcDistance(layout2, v1, v3);
    LOG.info("distance: " + distance);
    LOG.info("distance2: " + distance2);
    LOG.info("distance3: " + distance3);
    TopoFRLayout<VertexRef, EdgeRef> layout3 = runFRLayout(g, g.getLayout(), vertices);
    distance = calcDistance(layout3, v1, v2);
    distance2 = calcDistance(layout3, v2, v3);
    distance3 = calcDistance(layout3, v1, v3);
    LOG.info("distance: " + distance);
    LOG.info("distance2: " + distance2);
    LOG.info("distance3: " + distance3);
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Graph(org.opennms.features.topology.api.Graph) ArrayList(java.util.ArrayList) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Test(org.junit.Test)

Example 12 with EdgeRef

use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.

the class DefaultSelectionContext method setSelectedEdgeRefs.

@Override
public boolean setSelectedEdgeRefs(Collection<? extends EdgeRef> edgeRefs) {
    Set<EdgeRef> oldSet = new HashSet<>();
    oldSet.addAll(getSelectedEdgeRefs());
    doDeselectAll();
    for (EdgeRef edgeRef : edgeRefs) {
        setEdgeRefSelected(edgeRef, true);
    }
    if (oldSet.equals(getSelectedEdgeRefs())) {
        return false;
    } else {
        return true;
    }
}
Also used : EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) HashSet(java.util.HashSet)

Example 13 with EdgeRef

use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.

the class TopoFRLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(final Graph graph) {
    final Layout graphLayout = graph.getLayout();
    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
    Collection<Vertex> vertices = graph.getDisplayVertices();
    for (Vertex v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<Edge> edges = graph.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    TopoFRLayout<VertexRef, EdgeRef> layout = new TopoFRLayout<VertexRef, EdgeRef>(jungGraph);
    // Initialize the vertex positions to the last known positions from the layout
    Dimension size = selectLayoutSize(graph);
    layout.setInitializer(initializer(graphLayout, (int) size.getWidth() / 2, (int) size.getHeight() / 2));
    // Resize the graph to accommodate the number of vertices
    layout.setSize(size);
    while (!layout.done()) {
        layout.step();
    }
    // Store the new positions in the layout
    for (Vertex v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v) - (size.getWidth() / 2), (int) layout.getY(v) - (size.getHeight() / 2)));
    }
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) Dimension(java.awt.Dimension) Point(org.opennms.features.topology.api.Point) SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Layout(org.opennms.features.topology.api.Layout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Example 14 with EdgeRef

use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.

the class RealUltimateLayoutAlgorithm method doSpringLayout.

private static void doSpringLayout(final Layout graphLayout, SparseGraph<VertexRef, EdgeRef> jungGraph, Dimension size, int repulsion) {
    SpringLayout<VertexRef, EdgeRef> layout = new SpringLayout<VertexRef, EdgeRef>(jungGraph);
    layout.setForceMultiplier(SPRING_FORCE_MULTIPLIER);
    layout.setRepulsionRange(repulsion);
    layout.setInitializer(initializer(graphLayout));
    layout.setSize(size);
    int count = 0;
    while (!layout.done() && count < 700) {
        layout.step();
        count++;
    }
    for (VertexRef v : jungGraph.getVertices()) {
        graphLayout.setLocation(v, new Point(layout.getX(v), layout.getY(v)));
    }
}
Also used : SpringLayout(edu.uci.ics.jung.algorithms.layout.SpringLayout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Point(org.opennms.features.topology.api.Point)

Example 15 with EdgeRef

use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.

the class SpringLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(final Graph graph) {
    final Layout graphLayout = graph.getLayout();
    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
    Collection<? extends Vertex> vertices = graph.getDisplayVertices();
    for (VertexRef v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<? extends Edge> edges = graph.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    SpringLayout<VertexRef, EdgeRef> layout = new SpringLayout<VertexRef, EdgeRef>(jungGraph);
    layout.setForceMultiplier(SPRING_FORCE_MULTIPLIER);
    layout.setRepulsionRange(SPRING_LAYOUT_REPULSION);
    layout.setInitializer(initializer(graphLayout));
    layout.setSize(selectLayoutSize(graph));
    int count = 0;
    while (!layout.done() && count < 700) {
        layout.step();
        count++;
    }
    for (VertexRef v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v), layout.getY(v)));
    }
}
Also used : SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Layout(org.opennms.features.topology.api.Layout) SpringLayout(edu.uci.ics.jung.algorithms.layout.SpringLayout) SpringLayout(edu.uci.ics.jung.algorithms.layout.SpringLayout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge) Point(org.opennms.features.topology.api.Point)

Aggregations

EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)30 VertexRef (org.opennms.features.topology.api.topo.VertexRef)18 Vertex (org.opennms.features.topology.api.topo.Vertex)14 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 Edge (org.opennms.features.topology.api.topo.Edge)11 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)10 Status (org.opennms.features.topology.api.topo.Status)10 Point (org.opennms.features.topology.api.Point)9 Dimension (java.awt.Dimension)6 Layout (org.opennms.features.topology.api.Layout)6 FRLayout (edu.uci.ics.jung.algorithms.layout.FRLayout)3 SpringLayout (edu.uci.ics.jung.algorithms.layout.SpringLayout)3 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)3 HashMap (java.util.HashMap)2 Graph (org.opennms.features.topology.api.Graph)2 Predicate (com.google.common.base.Predicate)1 Lists (com.google.common.collect.Lists)1 ISOMLayout (edu.uci.ics.jung.algorithms.layout.ISOMLayout)1 UnweightedShortestPath (edu.uci.ics.jung.algorithms.shortestpath.UnweightedShortestPath)1