Search in sources :

Example 41 with LGraph

use of org.eclipse.elk.alg.layered.graph.LGraph in project elk by eclipse.

the class LayerSweepCrossingMinimizerTest method givenNestedGraphWithWronglySortedDummyNodes_ShouldSortAndResolveCrossing.

/**
 * <pre>
 * ____  ____
 * |*-+  +-*|
 * |  |\/|  |
 * |*-+/\+-*|
 * |--|  |--|
 * </pre>
 *
 * With external origins of port dummies on right node wrong way around.
 */
@Test
public void givenNestedGraphWithWronglySortedDummyNodes_ShouldSortAndResolveCrossing() {
    LNode leftOuterNode = addNodeToLayer(makeLayer(getGraph()));
    LNode rightOuterNode = addNodeToLayer(makeLayer(getGraph()));
    LPort[] leftOuterPorts = addPortsOnSide(2, leftOuterNode, PortSide.EAST);
    LPort[] rightOuterPorts = addPortsOnSide(2, rightOuterNode, PortSide.WEST);
    addEdgeBetweenPorts(leftOuterPorts[0], rightOuterPorts[0]);
    addEdgeBetweenPorts(leftOuterPorts[1], rightOuterPorts[1]);
    makeNestedTwoNodeGraphWithEasternPorts(leftOuterNode, leftOuterPorts);
    LGraph rightInnerGraph = nestedGraph(rightOuterNode);
    LPort[] reversedRightPorts = reverse(rightOuterPorts);
    LNode[] rightInnerDummyNodes = addExternalPortDummiesToLayer(makeLayer(rightInnerGraph), reversedRightPorts);
    LNode[] rightInnerNodes = addNodesToLayer(2, makeLayer(rightInnerGraph));
    eastWestEdgeFromTo(rightInnerDummyNodes[1], rightInnerNodes[0]);
    eastWestEdgeFromTo(rightInnerDummyNodes[0], rightInnerNodes[1]);
    List<LNode> expectedNormalNodeOrderRight = switchOrderOfNodesInLayer(0, 1, rightInnerGraph.getLayers().get(1));
    List<LPort> expectedOrderOfPortsRight = Lists.newArrayList(rightOuterPorts[1], rightOuterPorts[0]);
    setUpAndMinimizeCrossings();
    List<LNode> actualExternalDummyOrderRight = rightInnerGraph.getLayers().get(0).getNodes();
    assertThat(actualExternalDummyOrderRight, is((List<LNode>) Lists.newArrayList(rightInnerDummyNodes)));
    assertThat(rightOuterNode.getPorts(), is(expectedOrderOfPortsRight));
    List<LNode> actualNormalOrderRight = rightInnerGraph.getLayers().get(1).getNodes();
    assertThat(actualNormalOrderRight, is(expectedNormalNodeOrderRight));
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) List(java.util.List) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Test(org.junit.Test)

Example 42 with LGraph

use of org.eclipse.elk.alg.layered.graph.LGraph in project elk by eclipse.

the class ForsterConstraintResolverTest method testSuccessorConstraints.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests
/**
 * Test whether the order of nodes respects each node's {@link InternalProperties#IN_LAYER_SUCCESSOR_CONSTRAINTS}.
 */
@TestAfterProcessor(LayerSweepCrossingMinimizer.class)
public void testSuccessorConstraints(final Object graph) {
    for (Layer layer : (LGraph) graph) {
        // We iterate over the layer's nodes and remember the one's we've already seen. If a successor constraint
        // includes a node we've already seen, we fail
        Set<LNode> encounteredNodes = new HashSet<>();
        for (LNode node : layer) {
            if (node.hasProperty(InternalProperties.IN_LAYER_SUCCESSOR_CONSTRAINTS)) {
                boolean violation = node.getProperty(InternalProperties.IN_LAYER_SUCCESSOR_CONSTRAINTS).stream().anyMatch(n -> encounteredNodes.contains(n));
                assertFalse(violation);
            }
            encounteredNodes.add(node);
        }
    }
}
Also used : LNode(org.eclipse.elk.alg.layered.graph.LNode) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Layer(org.eclipse.elk.alg.layered.graph.Layer) HashSet(java.util.HashSet) TestAfterProcessor(org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)

Example 43 with LGraph

use of org.eclipse.elk.alg.layered.graph.LGraph in project elk by eclipse.

the class ForsterConstraintResolverTest method testNonOverlappingLayoutUnits.

/**
 * Nodes may be part of layout units, which must be adhered to even after in-layer constraints are resolved.
 */
@TestAfterProcessor(LayerSweepCrossingMinimizer.class)
public void testNonOverlappingLayoutUnits(final Object graph) {
    for (Layer layer : (LGraph) graph) {
        // We iterate over the layer's nodes and keep track of two things: the layout units we've encountered so
        // far, and the current layout unit. Layout units are identified through a representing node.
        Set<LNode> encounteredLayoutUnits = new HashSet<>();
        LNode currentLayoutUnit = null;
        for (LNode node : layer) {
            LNode newLayoutUnit = node.getProperty(InternalProperties.IN_LAYER_LAYOUT_UNIT);
            if (newLayoutUnit != null && newLayoutUnit != currentLayoutUnit) {
                // We have a node which does not belong to the current layout unit. That's okay if the new layout
                // unit has not been encountered before (if it has, nodes of different layout units overlap)
                assertFalse(encounteredLayoutUnits.contains(newLayoutUnit));
                if (currentLayoutUnit != null) {
                    encounteredLayoutUnits.add(currentLayoutUnit);
                }
                currentLayoutUnit = newLayoutUnit;
            }
        }
    }
}
Also used : LNode(org.eclipse.elk.alg.layered.graph.LNode) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Layer(org.eclipse.elk.alg.layered.graph.Layer) HashSet(java.util.HashSet) TestAfterProcessor(org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)

Example 44 with LGraph

use of org.eclipse.elk.alg.layered.graph.LGraph in project elk by eclipse.

the class GreedyPortDistributorTest method givenDoubleCrossBetweenCompoundAndNonCompoundNodes_SwitchesPorts.

/**
 * <pre>
 * ____
 * |*-+   *
 * |  |\\/
 * |*-+/\\
 * |--|   *
 * </pre>
 */
@Test
public void givenDoubleCrossBetweenCompoundAndNonCompoundNodes_SwitchesPorts() {
    LNode leftOuterNode = addNodeToLayer(makeLayer(getGraph()));
    LNode[] rightNodes = addNodesToLayer(2, makeLayer(getGraph()));
    LPort[] leftOuterPorts = addPortsOnSide(2, leftOuterNode, PortSide.EAST);
    eastWestEdgeFromTo(leftOuterPorts[0], rightNodes[1]);
    eastWestEdgeFromTo(leftOuterPorts[0], rightNodes[1]);
    eastWestEdgeFromTo(leftOuterPorts[1], rightNodes[0]);
    LGraph leftInnerGraph = nestedGraph(leftOuterNode);
    LNode[] leftInnerNodes = addNodesToLayer(2, makeLayer(leftInnerGraph));
    LNode[] leftInnerDummyNodes = addExternalPortDummiesToLayer(makeLayer(leftInnerGraph), leftOuterPorts);
    eastWestEdgeFromTo(leftInnerNodes[0], leftInnerDummyNodes[0]);
    eastWestEdgeFromTo(leftInnerNodes[1], leftInnerDummyNodes[1]);
    setUpIds();
    List<LPort> expectedPortOrderLeftNode = portsOrderedAs(leftOuterNode, 1, 0);
    setUpDistributor();
    portDist.distributePortsWhileSweeping(graph.toNodeArray(), 0, false);
    assertThat(leftOuterNode.getPorts(), is(expectedPortOrderLeftNode));
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Test(org.junit.Test)

Example 45 with LGraph

use of org.eclipse.elk.alg.layered.graph.LGraph in project elk by eclipse.

the class GreedyPortDistributorTest method givenSingleCrossBetweenCompoundAndNonCompoundNodes_DoesNotSwitchPorts.

/**
 * <pre>
 * ____
 * |*-+  *
 * |  |\/
 * |*-+/\
 * |--|  *
 * </pre>
 */
@Test
public void givenSingleCrossBetweenCompoundAndNonCompoundNodes_DoesNotSwitchPorts() {
    LNode leftOuterNode = addNodeToLayer(makeLayer(getGraph()));
    LNode[] rightNodes = addNodesToLayer(2, makeLayer(getGraph()));
    LPort[] leftOuterPorts = addPortsOnSide(2, leftOuterNode, PortSide.EAST);
    eastWestEdgeFromTo(leftOuterPorts[0], rightNodes[1]);
    eastWestEdgeFromTo(leftOuterPorts[1], rightNodes[0]);
    LGraph leftInnerGraph = nestedGraph(leftOuterNode);
    LNode[] leftInnerNodes = addNodesToLayer(2, makeLayer(leftInnerGraph));
    LNode[] leftInnerDummyNodes = addExternalPortDummiesToLayer(makeLayer(leftInnerGraph), leftOuterPorts);
    eastWestEdgeFromTo(leftInnerNodes[0], leftInnerDummyNodes[0]);
    eastWestEdgeFromTo(leftInnerNodes[1], leftInnerDummyNodes[1]);
    // Order stays the same.
    List<LPort> expectedPortOrderLeftNode = portsOrderedAs(leftOuterNode, 0, 1);
    setUpDistributor();
    portDist.distributePortsWhileSweeping(graph.toNodeArray(), 0, false);
    assertThat(leftOuterNode.getPorts(), is(expectedPortOrderLeftNode));
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Test(org.junit.Test)

Aggregations

LGraph (org.eclipse.elk.alg.layered.graph.LGraph)115 LNode (org.eclipse.elk.alg.layered.graph.LNode)90 LPort (org.eclipse.elk.alg.layered.graph.LPort)49 Layer (org.eclipse.elk.alg.layered.graph.Layer)38 Test (org.junit.Test)36 TestAfterProcessor (org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)19 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)17 KVector (org.eclipse.elk.core.math.KVector)15 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)14 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)13 List (java.util.List)11 ILayoutProcessor (org.eclipse.elk.core.alg.ILayoutProcessor)11 IElkProgressMonitor (org.eclipse.elk.core.util.IElkProgressMonitor)10 NodeType (org.eclipse.elk.alg.layered.graph.LNode.NodeType)9 Lists (com.google.common.collect.Lists)7 Set (java.util.Set)7 GraphProperties (org.eclipse.elk.alg.layered.options.GraphProperties)7 GraphInfoHolder (org.eclipse.elk.alg.layered.p3order.GraphInfoHolder)7 PortSide (org.eclipse.elk.core.options.PortSide)7 ElkNode (org.eclipse.elk.graph.ElkNode)7