Search in sources :

Example 26 with LEdge

use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.

the class StretchWidthLayerer method getRank.

/**
 * Computes the rank of a node. The rank is defined as max(d⁺(v),max(d⁺(u):(u,v)∈ E)), where
 * d⁺(v) is the number of outgoing edges of a node v.
 *
 * @param node
 *            to compute the rank for
 * @return rank of the node
 */
private Integer getRank(final LNode node) {
    int max = Iterables.size(node.getOutgoingEdges());
    int temp;
    LNode pre;
    // compute max of predecessors out-degree and out-degree of the current node
    for (LEdge preEdge : node.getIncomingEdges()) {
        pre = preEdge.getSource().getNode();
        temp = Iterables.size(pre.getOutgoingEdges());
        max = Math.max(max, temp);
    }
    return max;
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LNode(org.eclipse.elk.alg.layered.graph.LNode)

Example 27 with LEdge

use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.

the class StretchWidthLayerer method updateOutGoing.

/**
 * Updates the information of the nodes, telling which has successors that are not placed. Is used when one layer is
 * finished, to eliminate edges in the same layer.
 *
 * @param currentLayer
 *            which is about to be finished
 */
private void updateOutGoing(final Layer currentLayer) {
    for (LNode node : currentLayer.getNodes()) {
        for (LEdge edge : node.getIncomingEdges()) {
            int pos = edge.getSource().getNode().id;
            remainingOutGoing[pos] = remainingOutGoing[pos] - 1;
        }
    }
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LNode(org.eclipse.elk.alg.layered.graph.LNode)

Example 28 with LEdge

use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.

the class NetworkSimplexPlacer method identifyPaths.

// ------------------------------------------------------------------------------------------------
// Path identification
// ------------------------------------------------------------------------------------------------
private List<Path> identifyPaths() {
    final List<Path> paths = Lists.newArrayList();
    lGraph.getLayers().stream().flatMap(l -> l.getNodes().stream()).filter(n -> nodeState[n.id] == JUNCTION).forEach(junction -> {
        for (LEdge e : junction.getConnectedEdges()) {
            if (!isHandledEdge(e)) {
                continue;
            }
            Path path = follow(e, junction, new Path());
            if (path.size() > 1) {
                paths.add(path);
            }
        }
    });
    return paths;
}
Also used : Arrays(java.util.Arrays) ElkMargin(org.eclipse.elk.core.math.ElkMargin) Iterables(com.google.common.collect.Iterables) GraphProperties(org.eclipse.elk.alg.layered.options.GraphProperties) Layer(org.eclipse.elk.alg.layered.graph.Layer) ListIterator(java.util.ListIterator) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) NorthSouthPortPreprocessor(org.eclipse.elk.alg.layered.intermediate.NorthSouthPortPreprocessor) PortSide(org.eclipse.elk.core.options.PortSide) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) NGraph(org.eclipse.elk.alg.common.networksimplex.NGraph) Stack(java.util.Stack) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) ArrayList(java.util.ArrayList) Spacings(org.eclipse.elk.alg.layered.options.Spacings) IntermediateProcessorStrategy(org.eclipse.elk.alg.layered.intermediate.IntermediateProcessorStrategy) Lists(com.google.common.collect.Lists) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) Map(java.util.Map) NodeFlexibility.getNodeFlexibility(org.eclipse.elk.alg.layered.options.NodeFlexibility.getNodeFlexibility) StreamSupport(java.util.stream.StreamSupport) NetworkSimplex(org.eclipse.elk.alg.common.networksimplex.NetworkSimplex) NodeType(org.eclipse.elk.alg.layered.graph.LNode.NodeType) LayoutProcessorConfiguration(org.eclipse.elk.core.alg.LayoutProcessorConfiguration) NNode(org.eclipse.elk.alg.common.networksimplex.NNode) DoubleMath(com.google.common.math.DoubleMath) NodeFlexibility(org.eclipse.elk.alg.layered.options.NodeFlexibility) Iterator(java.util.Iterator) PortConstraints(org.eclipse.elk.core.options.PortConstraints) Predicate(java.util.function.Predicate) NEdge(org.eclipse.elk.alg.common.networksimplex.NEdge) Set(java.util.Set) ILayoutPhase(org.eclipse.elk.core.alg.ILayoutPhase) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) LGraphElement(org.eclipse.elk.alg.layered.graph.LGraphElement) List(java.util.List) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) NodeLabelPlacement(org.eclipse.elk.core.options.NodeLabelPlacement) LayeredPhases(org.eclipse.elk.alg.layered.LayeredPhases) LabelAndNodeSizeProcessor(org.eclipse.elk.alg.layered.intermediate.LabelAndNodeSizeProcessor) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) Queue(java.util.Queue) LEdge(org.eclipse.elk.alg.layered.graph.LEdge)

Example 29 with LEdge

use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.

the class NetworkSimplexPlacer method prepare.

// ------------------------------------------------------------------------------------------------
// Preparation
// ------------------------------------------------------------------------------------------------
private void prepare() {
    this.nGraph = new NGraph();
    // "integerify" port anchor and port positions
    // note that margin.top and margin.bottom are not required to be integral
    // since they do not influence the offset calculation for the edges
    // ... while we're at it, we assign ids to the nodes and edges
    int nodeIdx = 0;
    int edgeIdx = 0;
    for (Layer l : lGraph) {
        for (LNode lNode : l) {
            lNode.id = nodeIdx++;
            for (LEdge e : lNode.getOutgoingEdges()) {
                e.id = edgeIdx++;
            }
            // if a node is flexible, an edge attaches to the port itself within
            // the auxiliary graph, thus the anchor must be integer
            // otherwise the port position can be altered such that it accounts for the anchor's position as well
            boolean anchorMustBeInteger = isFlexibleNode(lNode);
            for (LPort p : lNode.getPorts()) {
                if (anchorMustBeInteger) {
                    // anchor
                    double y = p.getAnchor().y;
                    if (y != Math.floor(y)) {
                        double offset = y - Math.round(y);
                        p.getAnchor().y -= offset;
                    }
                }
                // port + anchor
                double y = p.getPosition().y + p.getAnchor().y;
                if (y != Math.floor(y)) {
                    double offset = y - Math.round(y);
                    p.getPosition().y -= offset;
                }
            }
        }
    }
    this.nodeCount = nodeIdx;
    this.edgeCount = edgeIdx;
    this.nodeReps = new NodeRep[nodeIdx];
    this.edgeReps = new EdgeRep[edgeIdx];
    this.flexibleWhereSpacePermitsEdges.clear();
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge) NGraph(org.eclipse.elk.alg.common.networksimplex.NGraph) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 30 with LEdge

use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.

the class NetworkSimplexPlacer method preferStraightEdges.

/**
 * Potentially alters the weights of paths in a similar fashion to long edges. Also collects 'two paths'
 * for later post processing.
 */
private void preferStraightEdges() {
    // the nodes were counted and indexed during #prepare
    nodeState = new int[nodeCount];
    twoPaths = Lists.newArrayList();
    // record node states
    lGraph.getLayers().stream().flatMap(l -> l.getNodes().stream()).forEach(n -> nodeState[n.id] = getNodeState(n));
    markEdgeCrossings();
    List<Path> identifiedPaths = identifyPaths();
    // the weights of the connecting edges are altered to straighten the path as much as possible
    for (Path path : identifiedPaths) {
        if (path.size() <= 1) {
            continue;
        }
        // remember 'two paths' for processing after network simplex has been executed
        if (path.size() == 2) {
            path.orderTwoPath();
            if (!path.isTwoPathCenterNodeFlexible()) {
                twoPaths.add(path);
            }
            continue;
        }
        // ignore paths that contain long edge dummies, and paths that contain flexible nodes that allow resizing
        if (path.containsLongEdgeDummy() || path.containsFlexibleNode(nf -> nf.isFlexibleSizeWhereSpacePermits())) {
            continue;
        }
        Iterator<LEdge> pathIt = path.iterator();
        LEdge last = null;
        while (pathIt.hasNext()) {
            LEdge cur = pathIt.next();
            EdgeRep curRep = edgeReps[cur.id];
            double weight;
            if (last == null || !pathIt.hasNext()) {
                // first or last segment
                weight = getEdgeWeight(NodeType.NORMAL, NodeType.LONG_EDGE);
            } else {
                weight = getEdgeWeight(NodeType.LONG_EDGE, NodeType.LONG_EDGE);
            }
            // at this point one can decide whether long edges are more important than "paths"
            weight *= LONG_EDGE_VS_PATH_FACTOR;
            double oldLeftWeight = curRep.left.weight;
            curRep.left.weight = Math.max(oldLeftWeight, oldLeftWeight + (weight - oldLeftWeight));
            double oldRightWeight = curRep.right.weight;
            curRep.right.weight = Math.max(oldRightWeight, oldRightWeight + (weight - oldRightWeight));
            last = cur;
        }
    }
}
Also used : Arrays(java.util.Arrays) ElkMargin(org.eclipse.elk.core.math.ElkMargin) Iterables(com.google.common.collect.Iterables) GraphProperties(org.eclipse.elk.alg.layered.options.GraphProperties) Layer(org.eclipse.elk.alg.layered.graph.Layer) ListIterator(java.util.ListIterator) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) NorthSouthPortPreprocessor(org.eclipse.elk.alg.layered.intermediate.NorthSouthPortPreprocessor) PortSide(org.eclipse.elk.core.options.PortSide) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) NGraph(org.eclipse.elk.alg.common.networksimplex.NGraph) Stack(java.util.Stack) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) ArrayList(java.util.ArrayList) Spacings(org.eclipse.elk.alg.layered.options.Spacings) IntermediateProcessorStrategy(org.eclipse.elk.alg.layered.intermediate.IntermediateProcessorStrategy) Lists(com.google.common.collect.Lists) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) Map(java.util.Map) NodeFlexibility.getNodeFlexibility(org.eclipse.elk.alg.layered.options.NodeFlexibility.getNodeFlexibility) StreamSupport(java.util.stream.StreamSupport) NetworkSimplex(org.eclipse.elk.alg.common.networksimplex.NetworkSimplex) NodeType(org.eclipse.elk.alg.layered.graph.LNode.NodeType) LayoutProcessorConfiguration(org.eclipse.elk.core.alg.LayoutProcessorConfiguration) NNode(org.eclipse.elk.alg.common.networksimplex.NNode) DoubleMath(com.google.common.math.DoubleMath) NodeFlexibility(org.eclipse.elk.alg.layered.options.NodeFlexibility) Iterator(java.util.Iterator) PortConstraints(org.eclipse.elk.core.options.PortConstraints) Predicate(java.util.function.Predicate) NEdge(org.eclipse.elk.alg.common.networksimplex.NEdge) Set(java.util.Set) ILayoutPhase(org.eclipse.elk.core.alg.ILayoutPhase) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) LGraphElement(org.eclipse.elk.alg.layered.graph.LGraphElement) List(java.util.List) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) NodeLabelPlacement(org.eclipse.elk.core.options.NodeLabelPlacement) LayeredPhases(org.eclipse.elk.alg.layered.LayeredPhases) LabelAndNodeSizeProcessor(org.eclipse.elk.alg.layered.intermediate.LabelAndNodeSizeProcessor) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) Queue(java.util.Queue) LEdge(org.eclipse.elk.alg.layered.graph.LEdge)

Aggregations

LEdge (org.eclipse.elk.alg.layered.graph.LEdge)148 LNode (org.eclipse.elk.alg.layered.graph.LNode)107 LPort (org.eclipse.elk.alg.layered.graph.LPort)80 Layer (org.eclipse.elk.alg.layered.graph.Layer)41 KVector (org.eclipse.elk.core.math.KVector)34 KVectorChain (org.eclipse.elk.core.math.KVectorChain)20 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)17 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)16 PortSide (org.eclipse.elk.core.options.PortSide)11 ArrayList (java.util.ArrayList)9 List (java.util.List)9 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)8 Set (java.util.Set)7 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)7 Map (java.util.Map)6 IElkProgressMonitor (org.eclipse.elk.core.util.IElkProgressMonitor)6 Lists (com.google.common.collect.Lists)5 Iterator (java.util.Iterator)5 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)5 Pair (org.eclipse.elk.core.util.Pair)5