Skip to content

Commit

Permalink
Added a Crossing Minimizer that does nothing. (#795)
Browse files Browse the repository at this point in the history
Note that this does only work as intended if greedySwitch.type is set to
off.
This also includes a small debugging addition to the SortByInputModel
processor.

Signed-off-by: Soeren Domroes <sdo@informatik.uni-kiel.de>
  • Loading branch information
soerendomroes committed Mar 18, 2022
1 parent 6a0fdeb commit 1ddffd3
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
Expand Up @@ -51,6 +51,8 @@ public class SortByInputModelProcessor implements ILayoutProcessor<LGraph> {

@Override
public void process(final LGraph graph, final IElkProgressMonitor progressMonitor) {
progressMonitor.begin("Sort By Input Model "
+ graph.getProperty(LayeredOptions.CONSIDER_MODEL_ORDER_STRATEGY), 1);
int layerIndex = 0;
for (Layer layer : graph) {
final int previousLayerIndex = layerIndex == 0 ? 0 : layerIndex - 1;
Expand All @@ -67,23 +69,26 @@ public void process(final LGraph graph, final IElkProgressMonitor progressMonito
Collections.sort(node.getPorts(),
new ModelOrderPortComparator(previousLayer,
longEdgeTargetNodePreprocessing(node)));
progressMonitor.log("Node " + node + " ports: " + node.getPorts());
}
}
// Sort nodes.
Collections.sort(layer.getNodes(),
new ModelOrderNodeComparator(previousLayer,
graph.getProperty(LayeredOptions.CONSIDER_MODEL_ORDER_STRATEGY),
graph.getProperty(LayeredOptions.CONSIDER_MODEL_ORDER_LONG_EDGE_STRATEGY)));
progressMonitor.log("Layer " + layerIndex + ": " + layer);
layerIndex++;
}
progressMonitor.done();
}

/**
* Calculate long edge target of port and saves it and adds a map of all long edge targets to the node.
* @param node the node
* @return A map of all long edge targets of a node
*/
public static Map<LNode, Integer> longEdgeTargetNodePreprocessing(LNode node) {
public static Map<LNode, Integer> longEdgeTargetNodePreprocessing(final LNode node) {
Map<LNode, Integer> targetNodeModelOrder = new HashMap<>();
if (node.hasProperty(InternalProperties.TARGET_NODE_MODEL_ORDER)) {
return node.getProperty(InternalProperties.TARGET_NODE_MODEL_ORDER);
Expand Down
Expand Up @@ -14,6 +14,7 @@
import org.eclipse.elk.alg.layered.p3order.InteractiveCrossingMinimizer;
import org.eclipse.elk.alg.layered.p3order.LayerSweepCrossingMinimizer;
import org.eclipse.elk.alg.layered.p3order.LayerSweepCrossingMinimizer.CrossMinType;
import org.eclipse.elk.alg.layered.p3order.NoCrossingMinimizer;
import org.eclipse.elk.core.alg.ILayoutPhase;
import org.eclipse.elk.core.alg.ILayoutPhaseFactory;
import org.eclipse.elk.graph.properties.AdvancedPropertyValue;
Expand All @@ -40,7 +41,12 @@ public enum CrossingMinimizationStrategy implements ILayoutPhaseFactory<LayeredP
* a node, that movement is reflected in the ordering of nodes.
*/
@AdvancedPropertyValue
INTERACTIVE;
INTERACTIVE,

/**
* Allows to do no crossing minimization. This requires to also set {@link GreedySwitchType} to off.
*/
NONE;


@Override
Expand All @@ -52,6 +58,9 @@ public ILayoutPhase<LayeredPhases, LGraph> create() {
case INTERACTIVE:
return new InteractiveCrossingMinimizer();

case NONE:
return new NoCrossingMinimizer();

default:
throw new IllegalArgumentException(
"No implementation is available for the crossing minimizer " + this.toString());
Expand Down
@@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) 2022 Kiel University and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.elk.alg.layered.p3order;

import org.eclipse.elk.alg.layered.LayeredPhases;
import org.eclipse.elk.alg.layered.graph.LGraph;
import org.eclipse.elk.alg.layered.intermediate.IntermediateProcessorStrategy;
import org.eclipse.elk.alg.layered.options.GreedySwitchType;
import org.eclipse.elk.core.alg.ILayoutPhase;
import org.eclipse.elk.core.alg.LayoutProcessorConfiguration;
import org.eclipse.elk.core.util.IElkProgressMonitor;

/**
* This class does nothing instead of minimizing crossing. Everything remains as it was before.
* <dl>
* <dt>Precondition:</dt>
* <dd>The graph has a proper layering, i.e. all long edges have been splitted; all nodes have at least fixed port
* sides. This is, however, not checked but preceding processors or phases might depend on this.</dd>
* <dt>Postcondition:</dt>
* <dd>The order of nodes and ports remains as it was before this phase.</dd>
* <dt>Dependencies:</dt>
* <dd>It is advised to set {@link GreedySwitchType} to OFF. Otherwise, nodes and ports might be reordered
* if crossings are created.</dd>
* </dl>
*
*/
public class NoCrossingMinimizer implements ILayoutPhase<LayeredPhases, LGraph> {

@Override
public void process(final LGraph graph, final IElkProgressMonitor progressMonitor) {
progressMonitor.begin("No crossing minimization", 1);
progressMonitor.done();

}

@Override
public LayoutProcessorConfiguration<LayeredPhases, LGraph> getLayoutProcessorConfiguration(final LGraph graph) {
LayoutProcessorConfiguration<LayeredPhases, LGraph> configuration =
LayoutProcessorConfiguration.createFrom(INTERMEDIATE_PROCESSING_CONFIGURATION);
configuration.addBefore(LayeredPhases.P3_NODE_ORDERING, IntermediateProcessorStrategy.PORT_LIST_SORTER);

return configuration;
}



/** intermediate processing configuration. */
private static final LayoutProcessorConfiguration<LayeredPhases, LGraph> INTERMEDIATE_PROCESSING_CONFIGURATION =
LayoutProcessorConfiguration.<LayeredPhases, LGraph>create()
.addBefore(LayeredPhases.P3_NODE_ORDERING, IntermediateProcessorStrategy.LONG_EDGE_SPLITTER)
.addBefore(LayeredPhases.P4_NODE_PLACEMENT,
IntermediateProcessorStrategy.IN_LAYER_CONSTRAINT_PROCESSOR)
.after(LayeredPhases.P5_EDGE_ROUTING)
.add(IntermediateProcessorStrategy.LONG_EDGE_JOINER);

}

0 comments on commit 1ddffd3

Please sign in to comment.