Commit cdd49cbd authored by Sebastian Vollbrecht's avatar Sebastian Vollbrecht

Some minor fixes.

parent 78672061
...@@ -218,7 +218,9 @@ public final class GraphGenerator { ...@@ -218,7 +218,9 @@ public final class GraphGenerator {
edgeIncluder.setASAPTimesMap(asapTimes); edgeIncluder.setASAPTimesMap(asapTimes);
backedgeIncluder.setASAPTimesMap(asapTimes); backedgeIncluder.setASAPTimesMap(asapTimes);
property.generateProperty(layers, Collections.unmodifiableSet(nodes), nodeTable, edgeCreator); property.generateProperty(layers, Collections.unmodifiableSet(nodes), Collections.unmodifiableMap(nodeTable),
edgeCreator
);
if (verbose) { if (verbose) {
out.println("\tLayer structure post property generation: " + layers.toString()); out.println("\tLayer structure post property generation: " + layers.toString());
...@@ -328,7 +330,7 @@ public final class GraphGenerator { ...@@ -328,7 +330,7 @@ public final class GraphGenerator {
* <p> * <p>
* Use <code>new PrintStream(new FileOutputStream(new File(filename))</code> to immediately write to a file.<br> * Use <code>new PrintStream(new FileOutputStream(new File(filename))</code> to immediately write to a file.<br>
* <b>Warning</b>: The resulting file might be excessively large due to the * <b>Warning</b>: The resulting file might be excessively large due to the
* amount of edges possible in large graphs (O(2* V^2)). * amount of edges possible in large graphs (O(2*V<sup>2</sup>)).
* *
* @param out the print stream * @param out the print stream
*/ */
......
...@@ -180,7 +180,6 @@ public class EdgeCreator extends Observable<Edge<ResourceNode>> implements EdgeC ...@@ -180,7 +180,6 @@ public class EdgeCreator extends Observable<Edge<ResourceNode>> implements EdgeC
outgoingBackedges.get(src).add(edge); outgoingBackedges.get(src).add(edge);
incomingBackedges.get(dst).add(edge); incomingBackedges.get(dst).add(edge);
// TODO: is this check necessary?
if (src != GraphGenerator.SOURCE && dst != GraphGenerator.SINK) { if (src != GraphGenerator.SOURCE && dst != GraphGenerator.SINK) {
notifyObservers(edge); notifyObservers(edge);
} }
......
...@@ -21,7 +21,6 @@ import graphgen.generator.exceptions.IllegalSwapException; ...@@ -21,7 +21,6 @@ import graphgen.generator.exceptions.IllegalSwapException;
import graphgen.generator.exceptions.NodeDoesNotExistException; import graphgen.generator.exceptions.NodeDoesNotExistException;
import graphgen.generator.exceptions.StrictModeException; import graphgen.generator.exceptions.StrictModeException;
import graphgen.observer.Observer; import graphgen.observer.Observer;
import graphgen.util.JavaUtils;
import modsched.Edge; import modsched.Edge;
import modsched.Node; import modsched.Node;
...@@ -36,7 +35,6 @@ import java.util.List; ...@@ -36,7 +35,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Queue; import java.util.Queue;
import java.util.Set; import java.util.Set;
import java.util.TreeMap;
/** /**
* The layer structure is an essential component of the graph generator. It contains a list of layers, which are * The layer structure is an essential component of the graph generator. It contains a list of layers, which are
...@@ -66,9 +64,22 @@ public final class LayerStructure implements Serializable, Iterable<Integer>, Ob ...@@ -66,9 +64,22 @@ public final class LayerStructure implements Serializable, Iterable<Integer>, Ob
* Constructs a new layer structure based on the provided list of layers and the ID depths map. * Constructs a new layer structure based on the provided list of layers and the ID depths map.
* *
* @param depthsByID the depths of the IDs contained in the given list of layers * @param depthsByID the depths of the IDs contained in the given list of layers
* @throws IllegalArgumentException if any depth is negative
*/ */
public LayerStructure(Map<Integer, Integer> depthsByID) { public LayerStructure(Map<Integer, Integer> depthsByID) {
this.layers = new ArrayList<>(new TreeMap<>(JavaUtils.invertMap(depthsByID)).values()); this.layers = new ArrayList<>();
depthsByID.forEach((id, depth) -> {
if (depth < 0) {
throw new IllegalArgumentException("Depth of ID " + id + " cannot be negative.");
} else {
while (layers.size() <= depth) {
layers.add(new HashSet<>());
}
}
layers.get(depth).add(id);
});
this.height = layers.size(); this.height = layers.size();
this.depthsByID = new HashMap<>(depthsByID); this.depthsByID = new HashMap<>(depthsByID);
this.checker = new SwapChecker(); this.checker = new SwapChecker();
...@@ -106,11 +117,13 @@ public final class LayerStructure implements Serializable, Iterable<Integer>, Ob ...@@ -106,11 +117,13 @@ public final class LayerStructure implements Serializable, Iterable<Integer>, Ob
throw new IllegalSwapException(firstID, secondID); throw new IllegalSwapException(firstID, secondID);
} }
int firstLevel = depthsByID.get(firstID); int firstDepth = depthsByID.get(firstID);
int secondLevel = depthsByID.get(secondID); int secondDepth = depthsByID.get(secondID);
moveNode(secondID, firstLevel); if (firstDepth != secondDepth) {
moveNode(firstID, secondLevel); moveNode(secondID, firstDepth);
moveNode(firstID, secondDepth);
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment