Search in sources :

Example 31 with LGraph

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

the class BasicLayerAssignmentTest method testNoLayerlessNodes.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests
@TestAfterProcessor(CoffmanGrahamLayerer.class)
@TestAfterProcessor(InteractiveLayerer.class)
@TestAfterProcessor(LongestPathLayerer.class)
@TestAfterProcessor(MinWidthLayerer.class)
@TestAfterProcessor(NetworkSimplexLayerer.class)
@TestAfterProcessor(StretchWidthLayerer.class)
public void testNoLayerlessNodes(final Object graph) {
    LGraph lGraph = (LGraph) graph;
    assertTrue(lGraph.getLayerlessNodes().isEmpty());
}
Also used : LGraph(org.eclipse.elk.alg.layered.graph.LGraph) TestAfterProcessor(org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)

Example 32 with LGraph

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

the class AbstractBarycenterPortDistributorTest method distributePortsOnSide_partlyCrossHierarchicalEdges_CrossHierarchyStaysOuterChanges.

/**
 * <pre>
 * ____
 * | *+--  *
 * |  |  \/
 * |  |\ /\
 * | *+-x  *
 * |__|  \
 *        -*
 * </pre>
 */
// TODO this is a problem which currently cannot be solved by our algorithm :-(
@Ignore
public void distributePortsOnSide_partlyCrossHierarchicalEdges_CrossHierarchyStaysOuterChanges() {
    LNode leftOuterNode = addNodeToLayer(makeLayer());
    LNode[] rightNodes = addNodesToLayer(3, makeLayer());
    LPort[] leftOuterPorts = addPortsOnSide(3, leftOuterNode, PortSide.EAST);
    LGraph leftInnerGraph = nestedGraph(leftOuterNode);
    LNode[] leftInnerNodes = addNodesToLayer(2, makeLayer(leftInnerGraph));
    LNode[] leftInnerDummyNodes = new LNode[2];
    Layer dummyLayer = makeLayer();
    leftInnerDummyNodes[0] = addExternalPortDummyNodeToLayer(dummyLayer, leftOuterPorts[0]);
    leftInnerDummyNodes[1] = addExternalPortDummyNodeToLayer(dummyLayer, leftOuterPorts[2]);
    eastWestEdgeFromTo(leftInnerNodes[0], leftInnerDummyNodes[0]);
    eastWestEdgeFromTo(leftInnerNodes[1], leftInnerDummyNodes[1]);
    eastWestEdgeFromTo(leftOuterPorts[0], rightNodes[1]);
    eastWestEdgeFromTo(leftOuterPorts[1], rightNodes[2]);
    eastWestEdgeFromTo(leftOuterPorts[2], rightNodes[0]);
    // leftOuterNode.setProperty(InternalProperties.HAS_HIERARCHICAL_AND_NORMAL_PORTS, true);
    setPortOrderFixed(leftOuterNode);
    setUpIds();
    List<LPort> expectedOrder = Lists.newArrayList(switchOrderInArray(1, 2, leftOuterPorts));
    distributePortsInCompleteGraph(8);
    assertThat(leftOuterNode.getPorts(), is(expectedOrder));
}
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) Ignore(org.junit.Ignore)

Example 33 with LGraph

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

the class LayerSweepCrossingMinimizerTest method inLayerCrossHierarchyCrossingsInLeftMostLayer.

/**
 * <pre>
 *       *
 *      ||
 *   ----*
 *   |  ____
 *   /-|-*|
 * / | |  |
 *|  --|-*| *
 *|    |__|
 * \
 *  \
 *   \
 *     --*
 *      ||
 *       *
 * </pre>
 */
@Test
public void inLayerCrossHierarchyCrossingsInLeftMostLayer() {
    LNode[] nodes = addNodesToLayer(5, makeLayer());
    addPortsOnSide(2, nodes[0], PortSide.WEST);
    addNodeToLayer(makeLayer());
    LPort[] topNodePorts = addPortsOnSide(2, nodes[0], PortSide.WEST);
    LPort[] secondNodePorts = addPortsOnSide(3, nodes[1], PortSide.WEST);
    addEdgeBetweenPorts(topNodePorts[0], secondNodePorts[2]);
    addEdgeBetweenPorts(topNodePorts[1], secondNodePorts[1]);
    LPort[] outerPorts = addPortsOnSide(2, nodes[2], PortSide.WEST);
    LGraph inner = makeNestedTwoNodeGraphWithWesternPorts(nodes[2], outerPorts);
    LPort[] fifthNodePorts = addPortsOnSide(3, nodes[3], PortSide.WEST);
    LPort[] sixthNodePorts = addPortsOnSide(2, nodes[4], PortSide.WEST);
    addEdgeBetweenPorts(fifthNodePorts[0], sixthNodePorts[1]);
    addEdgeBetweenPorts(fifthNodePorts[1], sixthNodePorts[0]);
    addEdgeBetweenPorts(outerPorts[0], fifthNodePorts[2]);
    List<LPort> actualPortOrder = nodes[2].getPorts();
    List<LPort> expectedPortOrder = getListCopyInIndexOrder(actualPortOrder, 1, 0);
    List<LNode> actualNodeOrder = graph.getLayers().get(0).getNodes();
    List<LNode> expectedNodeOrder = Lists.newArrayList(actualNodeOrder);
    List<LNode> actualInnerNodeOrder = inner.getLayers().get(1).getNodes();
    List<LNode> expectedInnerNodeOrder = getListCopyInIndexOrder(actualInnerNodeOrder, 1, 0);
    graph.setProperty(LayeredOptions.CROSSING_MINIMIZATION_HIERARCHICAL_SWEEPINESS, 1.0);
    setUpAndMinimizeCrossings();
    assertThat(actualNodeOrder, is(expectedNodeOrder));
    assertThat(actualPortOrder, is(expectedPortOrder));
    assertThat(actualInnerNodeOrder, is(expectedInnerNodeOrder));
}
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 34 with LGraph

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

the class LayerSweepCrossingMinimizerTest method recursiveLayout_givenCrossInFirstLevelCompoundNode_sortsPortsAccordingly.

/**
 * <pre>
 * _______
 * |*  *-|--*
 * | \/  |
 * | /\  |
 * |*  *-|--*
 * |*--* |
 * |*--* |
 * |*--* |
 * |*--* |
 * |*--* |
 * |*--* |
 * |-----|
 * </pre>
 */
@Test
public void recursiveLayout_givenCrossInFirstLevelCompoundNode_sortsPortsAccordingly() {
    // 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(9, makeLayer(leftInnerGraph));
    LNode[] leftInnerNodesRight = addNodesToLayer(9, 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]);
    for (int i = 2; i < leftInnerNodesLeft.length; i++) {
        eastWestEdgeFromTo(leftInnerNodesLeft[i], leftInnerNodesRight[i]);
    }
    List<LNode> expectedOrderRight = copyOfSwitchOrderOfNodesInLayer(0, 1, 1);
    List<LPort> expectedPortOrderLeft = copyPortsInIndexOrder(leftOuterNode, 1, 0);
    setUpAndMinimizeCrossings();
    if (crossMinType == CrossMinType.BARYCENTER) {
        assertThat(leftOuterNode.getPorts(), is(expectedPortOrderLeft));
        assertThat(getGraph().getLayers().get(1).getNodes(), is(expectedOrderRight));
    }
}
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 35 with LGraph

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

the class LayerSweepCrossingMinimizerTest method givenSimpleHierarchicalCross_ShouldResultInNoCrossing.

/**
 * <pre>
 * ____  ____
 * |*-+  +-*|
 * |  |\/|  |
 * |*-+/\+-*|
 * |--|  |--|
 * </pre>
 */
@Test
public void givenSimpleHierarchicalCross_ShouldResultInNoCrossing() {
    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 = makeNestedTwoNodeGraphWithWesternPorts(rightOuterNode, rightOuterPorts);
    List<LNode> expectedExternalDummyOrderRight = switchOrderOfNodesInLayer(0, 1, rightInnerGraph.getLayers().get(0));
    List<LNode> expectedNormalNodeOrderRight = switchOrderOfNodesInLayer(0, 1, rightInnerGraph.getLayers().get(1));
    List<LPort> expectedOrderOfPortsRight = Lists.newArrayList(rightOuterPorts[1], rightOuterPorts[0]);
    setOnAllGraphs(LayeredOptions.CROSSING_MINIMIZATION_HIERARCHICAL_SWEEPINESS, 0.1, graph);
    setUpAndMinimizeCrossings();
    List<LNode> actualExternalDummyOrderRight = rightInnerGraph.getLayers().get(0).getNodes();
    assertThat(actualExternalDummyOrderRight, is(expectedExternalDummyOrderRight));
    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) 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