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));
}
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));
}
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));
}
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);
}
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));
}
Aggregations