Search in sources :

Example 96 with LGraph

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

the class PartitionPostProcessorTest method testPartitionOrder.

/**
 * For each layer, every node in this layer has the same partition and and this partition is greater or equal to the
 * partition of the previous layer.
 */
@TestAfterProcessor(PartitionPostprocessor.class)
public void testPartitionOrder(final Object graph) {
    LGraph lGraph = (LGraph) graph;
    int lastPartition = -1;
    for (Layer layer : lGraph) {
        // Set to invalid partition
        int currentPartition = -1;
        for (LNode node : layer) {
            if (node.getType() == NodeType.NORMAL && node.hasProperty(LayeredOptions.PARTITIONING_PARTITION)) {
                int nodePartition = node.getProperty(LayeredOptions.PARTITIONING_PARTITION);
                if (currentPartition == -1) {
                    currentPartition = nodePartition;
                } else {
                    assertEquals(currentPartition, nodePartition);
                }
            }
        }
        assertTrue(lastPartition <= currentPartition);
        lastPartition = currentPartition;
    }
}
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) TestAfterProcessor(org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)

Example 97 with LGraph

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

the class LayerSweepCrossingMinimizerTest method moreRandomThanHierarchicalPaths_ShouldNotCrossHierarchy.

/**
 * <pre>
 *_____   _______
 *| *-+---p *\  |
 *|   |   | *-* |
 *|   |   |  x  |
 *|   |   | * | |
 *| *-+---+-*-*-+-*
 *|   |   |     |‚
 *|___|   |_____|
 * </pre>
 *
 * p is unconnected port.
 */
@Test
public void moreRandomThanHierarchicalPaths_ShouldNotCrossHierarchy() {
    LNode leftOuterNode = addNodeToLayer(makeLayer());
    LPort[] leftOuterPorts = addPortsOnSide(2, leftOuterNode, PortSide.EAST);
    makeNestedTwoNodeGraphWithEasternPorts(leftOuterNode, leftOuterPorts);
    LNode middleOuterNode = addNodeToLayer(makeLayer());
    LNode rightNode = addNodeToLayer(makeLayer());
    LPort[] rightOuterPorts = addPortsOnSide(1, middleOuterNode, PortSide.EAST);
    LPort[] middleNodeLeftOuterPorts = addPortsOnSide(2, middleOuterNode, PortSide.WEST);
    addEdgeBetweenPorts(leftOuterPorts[0], middleNodeLeftOuterPorts[1]);
    addEdgeBetweenPorts(leftOuterPorts[1], middleNodeLeftOuterPorts[0]);
    eastWestEdgeFromTo(rightOuterPorts[0], rightNode);
    LGraph nestedGraph = nestedGraph(middleOuterNode);
    LNode[] leftDummies = addExternalPortDummiesToLayer(makeLayer(nestedGraph), middleNodeLeftOuterPorts);
    LNode[] leftInnerNodes = addNodesToLayer(4, makeLayer(nestedGraph));
    LNode[] rightInnerNodes = addNodesToLayer(2, makeLayer(nestedGraph));
    LNode[] rightDummies = addExternalPortDummiesToLayer(makeLayer(nestedGraph), rightOuterPorts);
    eastWestEdgeFromTo(leftDummies[0], leftInnerNodes[3]);
    eastWestEdgeFromTo(leftInnerNodes[0], rightInnerNodes[0]);
    eastWestEdgeFromTo(leftInnerNodes[1], rightInnerNodes[0]);
    eastWestEdgeFromTo(leftInnerNodes[1], rightInnerNodes[1]);
    eastWestEdgeFromTo(leftInnerNodes[2], rightInnerNodes[0]);
    eastWestEdgeFromTo(leftInnerNodes[3], rightInnerNodes[1]);
    eastWestEdgeFromTo(rightInnerNodes[1], rightDummies[0]);
    setOnAllGraphs(LayeredOptions.CROSSING_MINIMIZATION_HIERARCHICAL_SWEEPINESS, 0.0, nestedGraph);
    setUpAndMinimizeCrossings();
    List<GraphInfoHolder> graphData = crossMin.getGraphData();
    if (crossMinType == CrossMinType.BARYCENTER) {
        assertTrue(graphData.get(nestedGraph.id).dontSweepInto());
    }
}
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) GraphInfoHolder(org.eclipse.elk.alg.layered.p3order.GraphInfoHolder) Test(org.junit.Test)

Example 98 with LGraph

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

the class LayerSweepCrossingMinimizerTest method makeNestedTwoNodeGraphWithWesternPorts.

private LGraph makeNestedTwoNodeGraphWithWesternPorts(final LNode rightOuterNode, final LPort[] rightOuterPorts) {
    LGraph rightInnerGraph = nestedGraph(rightOuterNode);
    LNode[] rightInnerDummyNodes = addExternalPortDummiesToLayer(makeLayer(rightInnerGraph), rightOuterPorts);
    LNode[] rightInnerNodes = addNodesToLayer(2, makeLayer(rightInnerGraph));
    eastWestEdgeFromTo(rightInnerDummyNodes[0], rightInnerNodes[0]);
    eastWestEdgeFromTo(rightInnerDummyNodes[1], rightInnerNodes[1]);
    return rightInnerGraph;
}
Also used : LNode(org.eclipse.elk.alg.layered.graph.LNode) LGraph(org.eclipse.elk.alg.layered.graph.LGraph)

Example 99 with LGraph

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

the class LayerSweepHierarchicalTwoSidedGreedySwitchTest method givencrossInFirstLevelCompoundNodeUsingTwoSidedGreedySwitch_LeavesCrossing.

/**
 * <pre>
 * ______
 * |*  *+-*
 * | \/ |
 * | /\ |
 * |*  *+-*
 * |----|
 * </pre>
 */
@Test
public void givencrossInFirstLevelCompoundNodeUsingTwoSidedGreedySwitch_LeavesCrossing() {
    // parent graph
    LNode leftOuterNode = addNodeToLayer(makeLayer(getGraph()));
    LNode[] rightNodes = addNodesToLayer(2, makeLayer(getGraph()));
    LPort[] leftOuterPorts = addPortsOnSide(2, leftOuterNode, PortSide.EAST);
    eastWestEdgeFromTo(leftOuterPorts[0], rightNodes[0]);
    eastWestEdgeFromTo(leftOuterPorts[1], rightNodes[1]);
    // child graph
    LGraph leftInnerGraph = nestedGraph(leftOuterNode);
    LNode[] leftInnerNodesleft = addNodesToLayer(2, makeLayer(leftInnerGraph));
    LNode[] leftInnerNodesRight = addNodesToLayer(2, makeLayer(leftInnerGraph));
    LNode[] leftInnerDummyNodes = addExternalPortDummiesToLayer(makeLayer(leftInnerGraph), leftOuterPorts);
    eastWestEdgeFromTo(leftInnerNodesRight[0], leftInnerDummyNodes[0]);
    eastWestEdgeFromTo(leftInnerNodesRight[1], leftInnerDummyNodes[1]);
    eastWestEdgeFromTo(leftInnerNodesleft[0], leftInnerNodesRight[1]);
    eastWestEdgeFromTo(leftInnerNodesleft[1], leftInnerNodesRight[0]);
    getGraph().setProperty(LayeredOptions.CROSSING_MINIMIZATION_HIERARCHICAL_SWEEPINESS, -1.0);
    List<LNode> expectedSameOrder = copyOfNodesInLayer(1);
    setUpAndMinimizeCrossings();
    assertThat(getGraph().getLayers().get(1).getNodes(), is(expectedSameOrder));
}
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 100 with LGraph

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

the class LayerSweepHierarchicalTwoSidedGreedySwitchTest method givenCompoundGraphWhereOrderIsOnlyCorrectedOnForwardSweep_RemovesCrossing.

/**
 * <pre>
 * ________
 * |___  *|
 * || |\/ |
 * || |/\ |
 * ||_|  *|
 * |------|
 * </pre>
 *
 * Sweep backward first.
 */
@Test
public void givenCompoundGraphWhereOrderIsOnlyCorrectedOnForwardSweep_RemovesCrossing() {
    LNode node = addNodeToLayer(makeLayer(getGraph()));
    LGraph innerGraph = nestedGraph(node);
    LNode leftInnerNode = addNodeToLayer(makeLayer(innerGraph));
    setFixedOrderConstraint(leftInnerNode);
    LNode[] rightInnerNodes = addNodesToLayer(2, makeLayer(innerGraph));
    eastWestEdgeFromTo(leftInnerNode, rightInnerNodes[1]);
    eastWestEdgeFromTo(leftInnerNode, rightInnerNodes[0]);
    Layer rightInnerLayer = innerGraph.getLayers().get(1);
    List<LNode> expectedOrderRightInner = switchOrderOfNodesInLayer(0, 1, rightInnerLayer);
    List<LPort> expectedPortOrderLeft = copyPortsInIndexOrder(leftInnerNode, 0, 1);
    getRandom().setNextBoolean(false);
    setUpAndMinimizeCrossings();
    assertThat(leftInnerNode.getPorts(), is(expectedPortOrderLeft));
    assertThat(rightInnerLayer.getNodes(), is(expectedOrderRightInner));
}
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) Layer(org.eclipse.elk.alg.layered.graph.Layer) 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