use of org.eclipse.elk.alg.layered.graph.LGraph in project elk by eclipse.
the class LayerSweepCrossingMinimizerTest method givenNestedGraphWithWronglySortedDummyNodes_ShouldSortAndResolveCrossing.
/**
* <pre>
* ____ ____
* |*-+ +-*|
* | |\/| |
* |*-+/\+-*|
* |--| |--|
* </pre>
*
* With external origins of port dummies on right node wrong way around.
*/
@Test
public void givenNestedGraphWithWronglySortedDummyNodes_ShouldSortAndResolveCrossing() {
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 = nestedGraph(rightOuterNode);
LPort[] reversedRightPorts = reverse(rightOuterPorts);
LNode[] rightInnerDummyNodes = addExternalPortDummiesToLayer(makeLayer(rightInnerGraph), reversedRightPorts);
LNode[] rightInnerNodes = addNodesToLayer(2, makeLayer(rightInnerGraph));
eastWestEdgeFromTo(rightInnerDummyNodes[1], rightInnerNodes[0]);
eastWestEdgeFromTo(rightInnerDummyNodes[0], rightInnerNodes[1]);
List<LNode> expectedNormalNodeOrderRight = switchOrderOfNodesInLayer(0, 1, rightInnerGraph.getLayers().get(1));
List<LPort> expectedOrderOfPortsRight = Lists.newArrayList(rightOuterPorts[1], rightOuterPorts[0]);
setUpAndMinimizeCrossings();
List<LNode> actualExternalDummyOrderRight = rightInnerGraph.getLayers().get(0).getNodes();
assertThat(actualExternalDummyOrderRight, is((List<LNode>) Lists.newArrayList(rightInnerDummyNodes)));
assertThat(rightOuterNode.getPorts(), is(expectedOrderOfPortsRight));
List<LNode> actualNormalOrderRight = rightInnerGraph.getLayers().get(1).getNodes();
assertThat(actualNormalOrderRight, is(expectedNormalNodeOrderRight));
}
use of org.eclipse.elk.alg.layered.graph.LGraph in project elk by eclipse.
the class ForsterConstraintResolverTest method testSuccessorConstraints.
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests
/**
* Test whether the order of nodes respects each node's {@link InternalProperties#IN_LAYER_SUCCESSOR_CONSTRAINTS}.
*/
@TestAfterProcessor(LayerSweepCrossingMinimizer.class)
public void testSuccessorConstraints(final Object graph) {
for (Layer layer : (LGraph) graph) {
// We iterate over the layer's nodes and remember the one's we've already seen. If a successor constraint
// includes a node we've already seen, we fail
Set<LNode> encounteredNodes = new HashSet<>();
for (LNode node : layer) {
if (node.hasProperty(InternalProperties.IN_LAYER_SUCCESSOR_CONSTRAINTS)) {
boolean violation = node.getProperty(InternalProperties.IN_LAYER_SUCCESSOR_CONSTRAINTS).stream().anyMatch(n -> encounteredNodes.contains(n));
assertFalse(violation);
}
encounteredNodes.add(node);
}
}
}
use of org.eclipse.elk.alg.layered.graph.LGraph in project elk by eclipse.
the class ForsterConstraintResolverTest method testNonOverlappingLayoutUnits.
/**
* Nodes may be part of layout units, which must be adhered to even after in-layer constraints are resolved.
*/
@TestAfterProcessor(LayerSweepCrossingMinimizer.class)
public void testNonOverlappingLayoutUnits(final Object graph) {
for (Layer layer : (LGraph) graph) {
// We iterate over the layer's nodes and keep track of two things: the layout units we've encountered so
// far, and the current layout unit. Layout units are identified through a representing node.
Set<LNode> encounteredLayoutUnits = new HashSet<>();
LNode currentLayoutUnit = null;
for (LNode node : layer) {
LNode newLayoutUnit = node.getProperty(InternalProperties.IN_LAYER_LAYOUT_UNIT);
if (newLayoutUnit != null && newLayoutUnit != currentLayoutUnit) {
// We have a node which does not belong to the current layout unit. That's okay if the new layout
// unit has not been encountered before (if it has, nodes of different layout units overlap)
assertFalse(encounteredLayoutUnits.contains(newLayoutUnit));
if (currentLayoutUnit != null) {
encounteredLayoutUnits.add(currentLayoutUnit);
}
currentLayoutUnit = newLayoutUnit;
}
}
}
}
use of org.eclipse.elk.alg.layered.graph.LGraph in project elk by eclipse.
the class GreedyPortDistributorTest method givenDoubleCrossBetweenCompoundAndNonCompoundNodes_SwitchesPorts.
/**
* <pre>
* ____
* |*-+ *
* | |\\/
* |*-+/\\
* |--| *
* </pre>
*/
@Test
public void givenDoubleCrossBetweenCompoundAndNonCompoundNodes_SwitchesPorts() {
LNode leftOuterNode = addNodeToLayer(makeLayer(getGraph()));
LNode[] rightNodes = addNodesToLayer(2, makeLayer(getGraph()));
LPort[] leftOuterPorts = addPortsOnSide(2, leftOuterNode, PortSide.EAST);
eastWestEdgeFromTo(leftOuterPorts[0], rightNodes[1]);
eastWestEdgeFromTo(leftOuterPorts[0], rightNodes[1]);
eastWestEdgeFromTo(leftOuterPorts[1], rightNodes[0]);
LGraph leftInnerGraph = nestedGraph(leftOuterNode);
LNode[] leftInnerNodes = addNodesToLayer(2, makeLayer(leftInnerGraph));
LNode[] leftInnerDummyNodes = addExternalPortDummiesToLayer(makeLayer(leftInnerGraph), leftOuterPorts);
eastWestEdgeFromTo(leftInnerNodes[0], leftInnerDummyNodes[0]);
eastWestEdgeFromTo(leftInnerNodes[1], leftInnerDummyNodes[1]);
setUpIds();
List<LPort> expectedPortOrderLeftNode = portsOrderedAs(leftOuterNode, 1, 0);
setUpDistributor();
portDist.distributePortsWhileSweeping(graph.toNodeArray(), 0, false);
assertThat(leftOuterNode.getPorts(), is(expectedPortOrderLeftNode));
}
use of org.eclipse.elk.alg.layered.graph.LGraph in project elk by eclipse.
the class GreedyPortDistributorTest method givenSingleCrossBetweenCompoundAndNonCompoundNodes_DoesNotSwitchPorts.
/**
* <pre>
* ____
* |*-+ *
* | |\/
* |*-+/\
* |--| *
* </pre>
*/
@Test
public void givenSingleCrossBetweenCompoundAndNonCompoundNodes_DoesNotSwitchPorts() {
LNode leftOuterNode = addNodeToLayer(makeLayer(getGraph()));
LNode[] rightNodes = addNodesToLayer(2, makeLayer(getGraph()));
LPort[] leftOuterPorts = addPortsOnSide(2, leftOuterNode, PortSide.EAST);
eastWestEdgeFromTo(leftOuterPorts[0], rightNodes[1]);
eastWestEdgeFromTo(leftOuterPorts[1], rightNodes[0]);
LGraph leftInnerGraph = nestedGraph(leftOuterNode);
LNode[] leftInnerNodes = addNodesToLayer(2, makeLayer(leftInnerGraph));
LNode[] leftInnerDummyNodes = addExternalPortDummiesToLayer(makeLayer(leftInnerGraph), leftOuterPorts);
eastWestEdgeFromTo(leftInnerNodes[0], leftInnerDummyNodes[0]);
eastWestEdgeFromTo(leftInnerNodes[1], leftInnerDummyNodes[1]);
// Order stays the same.
List<LPort> expectedPortOrderLeftNode = portsOrderedAs(leftOuterNode, 0, 1);
setUpDistributor();
portDist.distributePortsWhileSweeping(graph.toNodeArray(), 0, false);
assertThat(leftOuterNode.getPorts(), is(expectedPortOrderLeftNode));
}
Aggregations