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