Search in sources :

Example 11 with CrossingsCounter

use of org.eclipse.elk.alg.layered.p3order.counting.CrossingsCounter in project elk by eclipse.

the class CrossingsCounterTest method countCrossingsBetweenLayers_crossFormedMultipleEdgesBetweenSameNodes.

/**
 * Constructs a cross formed graph with two edges between the corners
 *
 * <pre>
 * *    *
 *  \\//
 *  //\\
 * *    *
 * .
 * </pre>
 */
@Test
public void countCrossingsBetweenLayers_crossFormedMultipleEdgesBetweenSameNodes() {
    Layer leftLayer = makeLayer(graph);
    Layer rightLayer = makeLayer(graph);
    LNode topLeft = addNodeToLayer(leftLayer);
    LNode bottomLeft = addNodeToLayer(leftLayer);
    LNode topRight = addNodeToLayer(rightLayer);
    LNode bottomRight = addNodeToLayer(rightLayer);
    LPort topLeftTopPort = addPortOnSide(topLeft, PortSide.EAST);
    LPort topLeftBottomPort = addPortOnSide(topLeft, PortSide.EAST);
    LPort bottomRightBottomPort = addPortOnSide(bottomRight, PortSide.WEST);
    LPort bottomRightTopPort = addPortOnSide(bottomRight, PortSide.WEST);
    addEdgeBetweenPorts(topLeftTopPort, bottomRightTopPort);
    addEdgeBetweenPorts(topLeftBottomPort, bottomRightBottomPort);
    LPort bottomLeftTopPort = addPortOnSide(bottomLeft, PortSide.EAST);
    LPort bottomLeftBottomPort = addPortOnSide(bottomLeft, PortSide.EAST);
    LPort topRightBottomPort = addPortOnSide(topRight, PortSide.WEST);
    LPort topRightTopPort = addPortOnSide(topRight, PortSide.WEST);
    addEdgeBetweenPorts(bottomLeftTopPort, topRightTopPort);
    addEdgeBetweenPorts(bottomLeftBottomPort, topRightBottomPort);
    GraphInfoHolder gd = new GraphInfoHolder(graph, CrossMinType.BARYCENTER, null);
    gd.portDistributor().distributePortsWhileSweeping(order(), 1, true);
    counter = new CrossingsCounter(new int[getNumPorts(order())]);
    assertThat(counter.countCrossingsBetweenLayers(order()[0], order()[1]), is(4));
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) CrossingsCounter(org.eclipse.elk.alg.layered.p3order.counting.CrossingsCounter) GraphInfoHolder(org.eclipse.elk.alg.layered.p3order.GraphInfoHolder) Layer(org.eclipse.elk.alg.layered.graph.Layer) Test(org.junit.Test)

Example 12 with CrossingsCounter

use of org.eclipse.elk.alg.layered.p3order.counting.CrossingsCounter in project elk by eclipse.

the class CrossingsCounterTest method countingTwoDifferentGraphs_DoesNotInterfereWithEachOther.

/**
 * <pre>
 * *---         *---
 * ___ \       ___  \
 * | |\/* and: | |--*
 * | |/\*      | |--*
 * |_|         |_|
 * </pre>
 */
@Test
public void countingTwoDifferentGraphs_DoesNotInterfereWithEachOther() throws Exception {
    LNode[] leftNodes = addNodesToLayer(3, makeLayer());
    LNode[] rightNodes = addNodesToLayer(3, makeLayer());
    LNode leftNode = leftNodes[1];
    LPort[] leftPorts = addPortsOnSide(2, leftNode, PortSide.EAST);
    eastWestEdgeFromTo(leftNodes[2], rightNodes[1]);
    eastWestEdgeFromTo(leftPorts[0], rightNodes[1]);
    eastWestEdgeFromTo(leftPorts[1], rightNodes[0]);
    eastWestEdgeFromTo(leftNodes[0], rightNodes[0]);
    counter = new CrossingsCounter(new int[getNumPorts(order())]);
    counter.initForCountingBetween(leftNodes, rightNodes);
    assertThat(counter.countCrossingsBetweenPortsInBothOrders(leftNode.getPorts().get(0), leftNode.getPorts().get(1)).getFirst(), is(1));
    counter.switchPorts(leftPorts[0], leftPorts[1]);
    leftNode.getPorts().set(0, leftPorts[1]);
    leftNode.getPorts().set(1, leftPorts[0]);
    assertThat(counter.countCrossingsBetweenPortsInBothOrders(leftNode.getPorts().get(0), leftNode.getPorts().get(1)).getFirst(), is(0));
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) CrossingsCounter(org.eclipse.elk.alg.layered.p3order.counting.CrossingsCounter) Test(org.junit.Test)

Example 13 with CrossingsCounter

use of org.eclipse.elk.alg.layered.p3order.counting.CrossingsCounter in project elk by eclipse.

the class CrossingsCounterTest method countCrossingsBetweenLayers_intoSamePort.

/**
 * <pre>
 * *   *<- Into same port
 *  \//
 *  //\
 * *   *
 * </pre>
 */
@Test
public void countCrossingsBetweenLayers_intoSamePort() {
    Layer leftLayer = makeLayer(graph);
    Layer rightLayer = makeLayer(graph);
    LNode topLeft = addNodeToLayer(leftLayer);
    LNode bottomLeft = addNodeToLayer(leftLayer);
    LNode topRight = addNodeToLayer(rightLayer);
    LNode bottomRight = addNodeToLayer(rightLayer);
    eastWestEdgeFromTo(topLeft, bottomRight);
    LPort bottomLeftFirstPort = addPortOnSide(bottomLeft, PortSide.EAST);
    LPort bottomLeftSecondPort = addPortOnSide(bottomLeft, PortSide.EAST);
    LPort topRightFirstPort = addPortOnSide(topRight, PortSide.WEST);
    addEdgeBetweenPorts(bottomLeftFirstPort, topRightFirstPort);
    addEdgeBetweenPorts(bottomLeftSecondPort, topRightFirstPort);
    setUpIds();
    counter = new CrossingsCounter(new int[getNumPorts(order())]);
    assertThat(counter.countCrossingsBetweenLayers(order()[0], order()[1]), is(2));
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) CrossingsCounter(org.eclipse.elk.alg.layered.p3order.counting.CrossingsCounter) Layer(org.eclipse.elk.alg.layered.graph.Layer) Test(org.junit.Test)

Example 14 with CrossingsCounter

use of org.eclipse.elk.alg.layered.p3order.counting.CrossingsCounter in project elk by eclipse.

the class GreedyPortDistributor method initAfterTraversal.

@Override
public void initAfterTraversal() {
    portPos = new int[nPorts];
    crossingsCounter = new CrossingsCounter(portPos);
}
Also used : CrossingsCounter(org.eclipse.elk.alg.layered.p3order.counting.CrossingsCounter) BetweenLayerEdgeTwoNodeCrossingsCounter(org.eclipse.elk.alg.layered.intermediate.greedyswitch.BetweenLayerEdgeTwoNodeCrossingsCounter)

Example 15 with CrossingsCounter

use of org.eclipse.elk.alg.layered.p3order.counting.CrossingsCounter in project elk by eclipse.

the class CrossingsCounterTest method countCrossingsBetweenLayers_fixedPortOrder.

@Test
public void countCrossingsBetweenLayers_fixedPortOrder() {
    getFixedPortOrderGraph();
    counter = new CrossingsCounter(new int[getNumPorts(order())]);
    assertThat(counter.countCrossingsBetweenLayers(order()[0], order()[1]), is(1));
}
Also used : CrossingsCounter(org.eclipse.elk.alg.layered.p3order.counting.CrossingsCounter) Test(org.junit.Test)

Aggregations

CrossingsCounter (org.eclipse.elk.alg.layered.p3order.counting.CrossingsCounter)18 Test (org.junit.Test)13 LNode (org.eclipse.elk.alg.layered.graph.LNode)10 LPort (org.eclipse.elk.alg.layered.graph.LPort)4 Layer (org.eclipse.elk.alg.layered.graph.Layer)4 GraphInfoHolder (org.eclipse.elk.alg.layered.p3order.GraphInfoHolder)3 Date (java.util.Date)1 BetweenLayerEdgeTwoNodeCrossingsCounter (org.eclipse.elk.alg.layered.intermediate.greedyswitch.BetweenLayerEdgeTwoNodeCrossingsCounter)1 Ignore (org.junit.Ignore)1