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