use of org.eclipse.elk.alg.layered.p5edges.orthogonal.HyperEdgeSegmentDependency in project elk by eclipse.
the class JsonDebugUtil method createDebugGraph.
/**
* Writes a debug graph for the given list of hypernodes.
*
* @param layeredGraph
* the layered graph
* @param hypernodes
* a list of hypernodes
* @return hypernode graph in JSON format.
*/
public static String createDebugGraph(final LGraph layeredGraph, final List<HyperEdgeSegment> hypernodes) {
StringWriter writer = new StringWriter();
beginGraph(writer, layeredGraph);
beginChildNodeList(writer, 1);
String indent1 = Strings.repeat(INDENT, 2);
// SUPPRESS CHECKSTYLE MagicNumber
String indent2 = Strings.repeat(INDENT, 3);
int edgeId = 0;
Iterator<HyperEdgeSegment> hypernodeIterator = hypernodes.iterator();
StringBuffer edges = new StringBuffer();
while (hypernodeIterator.hasNext()) {
HyperEdgeSegment hypernode = hypernodeIterator.next();
writer.write("\n" + indent1 + "{\n" + indent2 + "\"id\": \"n" + System.identityHashCode(hypernode) + "\",\n" + indent2 + "\"labels\": [ { \"text\": \"" + hypernode.toString() + "\" } ],\n" + indent2 + "\"width\": 50,\n" + indent2 + "\"height\": 25\n" + indent1 + "}");
if (hypernodeIterator.hasNext()) {
writer.write(",");
}
Iterator<HyperEdgeSegmentDependency> dependencyIterator = hypernode.getOutgoingSegmentDependencies().iterator();
while (dependencyIterator.hasNext()) {
HyperEdgeSegmentDependency dependency = dependencyIterator.next();
edges.append("\n" + indent1 + "{\n" + indent2 + "\"id\": \"e" + edgeId++ + "\",\n" + indent2 + "\"source\": \"n" + System.identityHashCode(hypernode) + "\",\n" + indent2 + "\"target\": \"n" + System.identityHashCode(dependency.getTarget()) + "\"\n" + indent1 + "},");
}
}
endChildNodeList(writer, 1);
if (edges.length() > 0) {
edges.deleteCharAt(edges.length() - 1);
}
writer.write(INDENT + "\"edges\": [" + edges + "\n" + INDENT + "]");
endGraph(writer);
return writer.toString();
}
use of org.eclipse.elk.alg.layered.p5edges.orthogonal.HyperEdgeSegmentDependency in project elk by eclipse.
the class DotDebugUtil method createDebugGraph.
/**
* Writes a debug graph for the given list of hypernodes.
*
* @param layeredGraph the layered graph
* @param hypernodes a list of hypernodes
* @return hypernodes graph in DOT format.
*/
public static String createDebugGraph(final LGraph layeredGraph, final List<HyperEdgeSegment> hypernodes) {
StringWriter writer = new StringWriter();
writer.write("digraph {\n");
// Write hypernode information
for (HyperEdgeSegment hypernode : hypernodes) {
writer.write(" " + hypernode.hashCode() + "[label=\"" + hypernode.toString() + "\"]\n");
}
// Write dependency information
for (HyperEdgeSegment hypernode : hypernodes) {
for (HyperEdgeSegmentDependency dependency : hypernode.getOutgoingSegmentDependencies()) {
writer.write(" " + hypernode.hashCode() + "->" + dependency.getTarget().hashCode() + "[label=\"" + dependency.getType().name() + " (" + dependency.getWeight() + ")\"]\n");
}
}
writer.write("}\n");
return writer.toString();
}
use of org.eclipse.elk.alg.layered.p5edges.orthogonal.HyperEdgeSegmentDependency in project elk by eclipse.
the class RoutingSlotAssigner method assignRawRoutingSlotsToSegments.
/**
* This will assign routing slots to the segments as if the four port sides were completely dependent. However,
* they are not. If the northern port side has 6 routing slots, that doesn't mean the eastern side will need 6 as
* well.
*/
private void assignRawRoutingSlotsToSegments() {
Queue<HyperEdgeSegment> sinks = new LinkedList<>();
// these, we also reset the in- and out weights to the number of incoming and outgoing dependencies
for (HyperEdgeSegment segment : hyperEdgeSegments) {
segment.setInWeight(segment.getIncomingSegmentDependencies().size());
segment.setOutWeight(segment.getOutgoingSegmentDependencies().size());
if (segment.getOutWeight() == 0) {
segment.setRoutingSlot(0);
sinks.add(segment);
}
}
// Assign raw routing slots!
while (!sinks.isEmpty()) {
HyperEdgeSegment segment = sinks.poll();
int nextRoutingSlot = segment.getRoutingSlot() + 1;
for (HyperEdgeSegmentDependency inDependency : segment.getIncomingSegmentDependencies()) {
HyperEdgeSegment sourceSegment = inDependency.getSource();
sourceSegment.setRoutingSlot(Math.max(sourceSegment.getRoutingSlot(), nextRoutingSlot));
sourceSegment.setOutWeight(sourceSegment.getOutWeight() - 1);
if (sourceSegment.getOutWeight() == 0) {
sinks.add(sourceSegment);
}
}
}
}
Aggregations