Search in sources :

Example 26 with LPort

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

the class NorthSouthEdgeNeighbouringNodeCrossingsCounterTest method givenPolylineRoutingWhenMoreThanOneEdgeIntoNSNode_countsTheseToo.

/**
 * <pre>
 *
 * *----
 *    /+--*
 *   --+--*
 *   | |
 *  _|_|_
 *  |   |
 *  |___|
 *  .
 * </pre>
 */
@Test
public void givenPolylineRoutingWhenMoreThanOneEdgeIntoNSNode_countsTheseToo() {
    LNode leftNode = addNodeToLayer(makeLayer(getGraph()));
    LNode[] middleNodes = addNodesToLayer(3, makeLayer(getGraph()));
    LNode[] rightNodes = addNodesToLayer(2, makeLayer(getGraph()));
    setFixedOrderConstraint(middleNodes[2]);
    // ports are added in clockwise fashion!
    addNorthSouthEdge(PortSide.NORTH, middleNodes[2], middleNodes[1], rightNodes[0], false);
    addNorthSouthEdge(PortSide.NORTH, middleNodes[2], middleNodes[0], leftNode, true);
    // second edge on middle node
    LPort middleNodePort = middleNodes[1].getPorts().get(0);
    eastWestEdgeFromTo(middleNodePort, rightNodes[1]);
    getGraph().setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.POLYLINE);
    countCrossingsInLayerBetweenNodes(1, 0, 1);
    assertThat(counter.getUpperLowerCrossings(), is(2));
    assertThat(counter.getLowerUpperCrossings(), is(1));
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) Test(org.junit.Test)

Example 27 with LPort

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

the class NorthSouthEdgeNeighbouringNodeCrossingsCounterTest method edgesInBothDirections.

/**
 * <pre>
 * *---.--*
 *     |
 * *-.-+--*
 *   | |
 *  _|_|_
 *  |   |
 *  |___|
 * </pre>
 */
@Test
public void edgesInBothDirections() {
    LNode[] leftLayer = addNodesToLayer(2, makeLayer());
    LNode[] middleLayer = addNodesToLayer(3, makeLayer());
    LNode[] rightLayer = addNodesToLayer(2, makeLayer());
    setFixedOrderConstraint(middleLayer[2]);
    addNorthSouthEdge(PortSide.NORTH, middleLayer[2], middleLayer[1], leftLayer[1], true);
    LPort normalNodePort = addPortOnSide(rightLayer[1], PortSide.WEST);
    LPort dummyNodePort = addPortOnSide(middleLayer[1], PortSide.EAST);
    addEdgeBetweenPorts(dummyNodePort, normalNodePort);
    LPort originPort = middleLayer[2].getPorts().get(0);
    dummyNodePort.setProperty(InternalProperties.ORIGIN, originPort);
    addNorthSouthEdge(PortSide.NORTH, middleLayer[2], middleLayer[0], leftLayer[0], true);
    normalNodePort = addPortOnSide(rightLayer[0], PortSide.WEST);
    dummyNodePort = addPortOnSide(middleLayer[0], PortSide.EAST);
    addEdgeBetweenPorts(dummyNodePort, normalNodePort);
    originPort = middleLayer[2].getPorts().get(1);
    dummyNodePort.setProperty(InternalProperties.ORIGIN, originPort);
    countCrossingsInLayerBetweenNodes(1, 0, 1);
    assertThat(counter.getUpperLowerCrossings(), is(1));
    // Note that the two other crossings which result from this switch are
    // counted by a
    // different crossings counter.
    assertThat(counter.getLowerUpperCrossings(), is(1));
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) Test(org.junit.Test)

Example 28 with LPort

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

the class NorthSouthEdgeNeighbouringNodeCrossingsCounterTest method givenMultipleEdgesInOneNSNodeCountsCrossings.

/**
 * <pre>
 *     .--*
 *     |
 * *-.-+--*
 *   | |
 *  _|_|_
 *  |   |
 *  |___|
 * </pre>
 */
@Test
public void givenMultipleEdgesInOneNSNodeCountsCrossings() {
    LNode leftNode = addNodeToLayer(makeLayer());
    LNode[] middleLayer = addNodesToLayer(3, makeLayer());
    LNode[] rightLayer = addNodesToLayer(2, makeLayer());
    setFixedOrderConstraint(middleLayer[2]);
    addNorthSouthEdge(PortSide.NORTH, middleLayer[2], middleLayer[1], leftNode, true);
    LPort normalNodePort = addPortOnSide(rightLayer[1], PortSide.WEST);
    LPort dummyNodePort = addPortOnSide(middleLayer[1], PortSide.EAST);
    addEdgeBetweenPorts(dummyNodePort, normalNodePort);
    LPort originPort = middleLayer[2].getPorts().get(0);
    dummyNodePort.setProperty(InternalProperties.ORIGIN, originPort);
    addNorthSouthEdge(PortSide.NORTH, middleLayer[2], middleLayer[0], rightLayer[0], false);
    countCrossingsInLayerBetweenNodes(1, 0, 1);
    assertThat(counter.getUpperLowerCrossings(), is(1));
    assertThat(counter.getLowerUpperCrossings(), is(0));
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) Test(org.junit.Test)

Example 29 with LPort

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

the class BetweenLayerEdgeTwoNodeCrossingsCounterTest method multipleEdgesIntoSamePort_causesNoCrossings.

@Test
public void multipleEdgesIntoSamePort_causesNoCrossings() {
    Layer leftLayer = makeLayer(graph);
    Layer rightLayer = makeLayer(graph);
    LNode topLeft = addNodeToLayer(leftLayer);
    LNode bottomLeft = addNodeToLayer(leftLayer);
    LNode bottomRight = addNodeToLayer(rightLayer);
    LPort bottomRightPort = addPortOnSide(bottomRight, PortSide.WEST);
    eastWestEdgeFromTo(topLeft, bottomRightPort);
    eastWestEdgeFromTo(topLeft, bottomRightPort);
    eastWestEdgeFromTo(bottomLeft, bottomRightPort);
    setUpIds();
    nodeOrder = getGraph().toNodeArray();
    layerToCountIn = getGraph().getLayers().get(0);
    crossingCounter = new BetweenLayerEdgeTwoNodeCrossingsCounter(nodeOrder, 0);
    setUpperNode(0);
    setLowerNode(1);
    assertEasternSideUpperLowerCrossingsIs(0);
    assertEasternSideUpperLowerCrossingsIs(0);
}
Also used : BetweenLayerEdgeTwoNodeCrossingsCounter(org.eclipse.elk.alg.layered.intermediate.greedyswitch.BetweenLayerEdgeTwoNodeCrossingsCounter) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) Layer(org.eclipse.elk.alg.layered.graph.Layer) Test(org.junit.Test)

Example 30 with LPort

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

the class GreedySwitchProcessorTest method selfLoops.

@Test
public void selfLoops() {
    Layer leftLayer = makeLayer(getGraph());
    Layer rightLayer = makeLayer(getGraph());
    LNode topLeft = addNodeToLayer(leftLayer);
    LNode bottomLeft = addNodeToLayer(leftLayer);
    LNode topRight = addNodeToLayer(rightLayer);
    LNode bottomRight = addNodeToLayer(rightLayer);
    LPort topLeftPort = addPortOnSide(topLeft, PortSide.EAST);
    LPort bottomLeftPort = addPortOnSide(bottomLeft, PortSide.EAST);
    setUpIds();
    LGraph selfLoopCrossGraph = getGraph();
    for (Layer layer : selfLoopCrossGraph) {
        for (LNode node : layer) {
            selfLoopOn(node, PortSide.EAST);
            selfLoopOn(node, PortSide.EAST);
            selfLoopOn(node, PortSide.EAST);
            selfLoopOn(node, PortSide.WEST);
            selfLoopOn(node, PortSide.WEST);
            selfLoopOn(node, PortSide.WEST);
        }
    }
    LPort topRightPort = addPortOnSide(topRight, PortSide.WEST);
    LPort bottomRightPort = addPortOnSide(bottomRight, PortSide.WEST);
    addEdgeBetweenPorts(topLeftPort, bottomRightPort);
    addEdgeBetweenPorts(bottomLeftPort, topRightPort);
    List<LNode> expectedOrderLayerOne;
    List<LNode> expectedOrderLayerTwo;
    if (greedyType == CrossMinType.ONE_SIDED_GREEDY_SWITCH) {
        expectedOrderLayerOne = copyOfNodesInLayer(0);
        expectedOrderLayerTwo = copyOfSwitchOrderOfNodesInLayer(0, 1, 1);
    } else {
        expectedOrderLayerOne = copyOfSwitchOrderOfNodesInLayer(0, 1, 0);
        expectedOrderLayerTwo = copyOfNodesInLayer(1);
    }
    startGreedySwitcherWithCurrentType();
    assertThat("Layer one", copyOfNodesInLayer(0), is(expectedOrderLayerOne));
    assertThat("Layer two", copyOfNodesInLayer(1), is(expectedOrderLayerTwo));
}
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

LPort (org.eclipse.elk.alg.layered.graph.LPort)270 LNode (org.eclipse.elk.alg.layered.graph.LNode)187 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)78 Test (org.junit.Test)66 Layer (org.eclipse.elk.alg.layered.graph.Layer)62 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)46 KVector (org.eclipse.elk.core.math.KVector)36 PortSide (org.eclipse.elk.core.options.PortSide)29 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)23 KVectorChain (org.eclipse.elk.core.math.KVectorChain)18 GraphInfoHolder (org.eclipse.elk.alg.layered.p3order.GraphInfoHolder)15 List (java.util.List)12 ArrayList (java.util.ArrayList)8 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)8 PortConstraints (org.eclipse.elk.core.options.PortConstraints)7 Set (java.util.Set)6 ElkLabel (org.eclipse.elk.graph.ElkLabel)6 EnumSet (java.util.EnumSet)5 SelfHyperLoop (org.eclipse.elk.alg.layered.intermediate.loops.SelfHyperLoop)5 Lists (com.google.common.collect.Lists)4