use of org.eclipse.elk.alg.layered.graph.LGraph in project elk by eclipse.
the class PartitionPostProcessorTest method testPartitionOrder.
/**
* For each layer, every node in this layer has the same partition and and this partition is greater or equal to the
* partition of the previous layer.
*/
@TestAfterProcessor(PartitionPostprocessor.class)
public void testPartitionOrder(final Object graph) {
LGraph lGraph = (LGraph) graph;
int lastPartition = -1;
for (Layer layer : lGraph) {
// Set to invalid partition
int currentPartition = -1;
for (LNode node : layer) {
if (node.getType() == NodeType.NORMAL && node.hasProperty(LayeredOptions.PARTITIONING_PARTITION)) {
int nodePartition = node.getProperty(LayeredOptions.PARTITIONING_PARTITION);
if (currentPartition == -1) {
currentPartition = nodePartition;
} else {
assertEquals(currentPartition, nodePartition);
}
}
}
assertTrue(lastPartition <= currentPartition);
lastPartition = currentPartition;
}
}
use of org.eclipse.elk.alg.layered.graph.LGraph in project elk by eclipse.
the class LayerSweepCrossingMinimizerTest method moreRandomThanHierarchicalPaths_ShouldNotCrossHierarchy.
/**
* <pre>
*_____ _______
*| *-+---p *\ |
*| | | *-* |
*| | | x |
*| | | * | |
*| *-+---+-*-*-+-*
*| | | |‚
*|___| |_____|
* </pre>
*
* p is unconnected port.
*/
@Test
public void moreRandomThanHierarchicalPaths_ShouldNotCrossHierarchy() {
LNode leftOuterNode = addNodeToLayer(makeLayer());
LPort[] leftOuterPorts = addPortsOnSide(2, leftOuterNode, PortSide.EAST);
makeNestedTwoNodeGraphWithEasternPorts(leftOuterNode, leftOuterPorts);
LNode middleOuterNode = addNodeToLayer(makeLayer());
LNode rightNode = addNodeToLayer(makeLayer());
LPort[] rightOuterPorts = addPortsOnSide(1, middleOuterNode, PortSide.EAST);
LPort[] middleNodeLeftOuterPorts = addPortsOnSide(2, middleOuterNode, PortSide.WEST);
addEdgeBetweenPorts(leftOuterPorts[0], middleNodeLeftOuterPorts[1]);
addEdgeBetweenPorts(leftOuterPorts[1], middleNodeLeftOuterPorts[0]);
eastWestEdgeFromTo(rightOuterPorts[0], rightNode);
LGraph nestedGraph = nestedGraph(middleOuterNode);
LNode[] leftDummies = addExternalPortDummiesToLayer(makeLayer(nestedGraph), middleNodeLeftOuterPorts);
LNode[] leftInnerNodes = addNodesToLayer(4, makeLayer(nestedGraph));
LNode[] rightInnerNodes = addNodesToLayer(2, makeLayer(nestedGraph));
LNode[] rightDummies = addExternalPortDummiesToLayer(makeLayer(nestedGraph), rightOuterPorts);
eastWestEdgeFromTo(leftDummies[0], leftInnerNodes[3]);
eastWestEdgeFromTo(leftInnerNodes[0], rightInnerNodes[0]);
eastWestEdgeFromTo(leftInnerNodes[1], rightInnerNodes[0]);
eastWestEdgeFromTo(leftInnerNodes[1], rightInnerNodes[1]);
eastWestEdgeFromTo(leftInnerNodes[2], rightInnerNodes[0]);
eastWestEdgeFromTo(leftInnerNodes[3], rightInnerNodes[1]);
eastWestEdgeFromTo(rightInnerNodes[1], rightDummies[0]);
setOnAllGraphs(LayeredOptions.CROSSING_MINIMIZATION_HIERARCHICAL_SWEEPINESS, 0.0, nestedGraph);
setUpAndMinimizeCrossings();
List<GraphInfoHolder> graphData = crossMin.getGraphData();
if (crossMinType == CrossMinType.BARYCENTER) {
assertTrue(graphData.get(nestedGraph.id).dontSweepInto());
}
}
use of org.eclipse.elk.alg.layered.graph.LGraph in project elk by eclipse.
the class LayerSweepCrossingMinimizerTest method makeNestedTwoNodeGraphWithWesternPorts.
private LGraph makeNestedTwoNodeGraphWithWesternPorts(final LNode rightOuterNode, final LPort[] rightOuterPorts) {
LGraph rightInnerGraph = nestedGraph(rightOuterNode);
LNode[] rightInnerDummyNodes = addExternalPortDummiesToLayer(makeLayer(rightInnerGraph), rightOuterPorts);
LNode[] rightInnerNodes = addNodesToLayer(2, makeLayer(rightInnerGraph));
eastWestEdgeFromTo(rightInnerDummyNodes[0], rightInnerNodes[0]);
eastWestEdgeFromTo(rightInnerDummyNodes[1], rightInnerNodes[1]);
return rightInnerGraph;
}
use of org.eclipse.elk.alg.layered.graph.LGraph in project elk by eclipse.
the class LayerSweepHierarchicalTwoSidedGreedySwitchTest method givencrossInFirstLevelCompoundNodeUsingTwoSidedGreedySwitch_LeavesCrossing.
/**
* <pre>
* ______
* |* *+-*
* | \/ |
* | /\ |
* |* *+-*
* |----|
* </pre>
*/
@Test
public void givencrossInFirstLevelCompoundNodeUsingTwoSidedGreedySwitch_LeavesCrossing() {
// parent graph
LNode leftOuterNode = addNodeToLayer(makeLayer(getGraph()));
LNode[] rightNodes = addNodesToLayer(2, makeLayer(getGraph()));
LPort[] leftOuterPorts = addPortsOnSide(2, leftOuterNode, PortSide.EAST);
eastWestEdgeFromTo(leftOuterPorts[0], rightNodes[0]);
eastWestEdgeFromTo(leftOuterPorts[1], rightNodes[1]);
// child graph
LGraph leftInnerGraph = nestedGraph(leftOuterNode);
LNode[] leftInnerNodesleft = addNodesToLayer(2, makeLayer(leftInnerGraph));
LNode[] leftInnerNodesRight = addNodesToLayer(2, makeLayer(leftInnerGraph));
LNode[] leftInnerDummyNodes = addExternalPortDummiesToLayer(makeLayer(leftInnerGraph), leftOuterPorts);
eastWestEdgeFromTo(leftInnerNodesRight[0], leftInnerDummyNodes[0]);
eastWestEdgeFromTo(leftInnerNodesRight[1], leftInnerDummyNodes[1]);
eastWestEdgeFromTo(leftInnerNodesleft[0], leftInnerNodesRight[1]);
eastWestEdgeFromTo(leftInnerNodesleft[1], leftInnerNodesRight[0]);
getGraph().setProperty(LayeredOptions.CROSSING_MINIMIZATION_HIERARCHICAL_SWEEPINESS, -1.0);
List<LNode> expectedSameOrder = copyOfNodesInLayer(1);
setUpAndMinimizeCrossings();
assertThat(getGraph().getLayers().get(1).getNodes(), is(expectedSameOrder));
}
use of org.eclipse.elk.alg.layered.graph.LGraph in project elk by eclipse.
the class LayerSweepHierarchicalTwoSidedGreedySwitchTest method givenCompoundGraphWhereOrderIsOnlyCorrectedOnForwardSweep_RemovesCrossing.
/**
* <pre>
* ________
* |___ *|
* || |\/ |
* || |/\ |
* ||_| *|
* |------|
* </pre>
*
* Sweep backward first.
*/
@Test
public void givenCompoundGraphWhereOrderIsOnlyCorrectedOnForwardSweep_RemovesCrossing() {
LNode node = addNodeToLayer(makeLayer(getGraph()));
LGraph innerGraph = nestedGraph(node);
LNode leftInnerNode = addNodeToLayer(makeLayer(innerGraph));
setFixedOrderConstraint(leftInnerNode);
LNode[] rightInnerNodes = addNodesToLayer(2, makeLayer(innerGraph));
eastWestEdgeFromTo(leftInnerNode, rightInnerNodes[1]);
eastWestEdgeFromTo(leftInnerNode, rightInnerNodes[0]);
Layer rightInnerLayer = innerGraph.getLayers().get(1);
List<LNode> expectedOrderRightInner = switchOrderOfNodesInLayer(0, 1, rightInnerLayer);
List<LPort> expectedPortOrderLeft = copyPortsInIndexOrder(leftInnerNode, 0, 1);
getRandom().setNextBoolean(false);
setUpAndMinimizeCrossings();
assertThat(leftInnerNode.getPorts(), is(expectedPortOrderLeft));
assertThat(rightInnerLayer.getNodes(), is(expectedOrderRightInner));
}
Aggregations