Commit 75736ee6 by Michael Schmid

decomposition tree creation now works as well

parent c5bc69e2
......@@ -317,7 +317,7 @@ public class SystemSetup<T extends Task> {
try {
jobDag.addDagEdge(pairs.getKey(), pairs.getValue());
} catch (final Exception e) {
// TODO: handle exception
// nothing to do here
}
}
}
......
......@@ -147,7 +147,7 @@ public class DagUtils {
try {
modifiedJobDag.addDagEdge(p, sink);
} catch (final Exception exception) {
// TODO: handle exception
}
}
continue nextEdge;
......@@ -296,10 +296,11 @@ public class DagUtils {
final Job forkNode, final Job sink, final List<Job> joinNodes) {
for (final Job j : joinNodes) {
final Set<Job> ancestorsOfJ = jobDag.getAncestors(jobDag, j);
final Set<Job> ancesotorsOfFork = jobDag.getAncestors(jobDag, forkNode);
ancesotorsOfFork.add(forkNode);
final Set<Job> ancestorsOfFork = jobDag.getAncestors(jobDag, forkNode);
ancestorsOfFork.add(forkNode);
final Set<Job> inbetweenJobs = new HashSet<>(ancestorsOfJ);
inbetweenJobs.removeAll(ancesotorsOfFork);
inbetweenJobs.removeAll(ancestorsOfFork);
inbetweenJobs.add(j);
if (inbetweenJobs.isEmpty()) {
continue;
}
......
package mvd.jester.model;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import java.util.Stack;
import java.util.concurrent.ThreadLocalRandom;
import org.jgrapht.Graphs;
import org.jgrapht.experimental.dag.DirectedAcyclicGraph;
import org.jgrapht.graph.DefaultEdge;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import mvd.jester.utils.DagUtils;
import mvd.jester.utils.BinaryDecompositionTree.Node;
import mvd.jester.utils.BinaryDecompositionTree.NodeType;
import mvd.jester.model.SystemSetup.DagTaskBuilder;
import mvd.jester.utils.BinaryDecompositionTree;
......@@ -38,7 +35,7 @@ public class TestDagUtils {
@Test
@DisplayName("Check if NFJ DAGs are created correctly.")
void checkNfjDagCreation() {
for (int i = 0; i < 10000; ++i) {
for (int i = 0; i < 100; ++i) {
DagTaskBuilder b = new DagTaskBuilder();
DagTask t = b.generateTask();
......@@ -49,55 +46,11 @@ public class TestDagUtils {
}
private long countLeafs(BinaryDecompositionTree<Job> tree) {
Node<Job> node = tree.getRootNode();
// Base Case
if (node == null) {
return 0;
}
// Create an empty stack and push root to it
Stack<Node<Job>> nodeStack = new Stack<>();
nodeStack.push(node);
long count = 0;
while (nodeStack.empty() == false) {
// Pop the top item from stack and print it
Node<Job> mynode = nodeStack.peek();
if (mynode.getNodeType() == NodeType.LEAF) {
count++;
}
nodeStack.pop();
// Push right and left children of the popped node to stack
if (mynode.getLeftNode() != null) {
nodeStack.push(mynode.getLeftNode());
}
if (mynode.getRightNode() != null) {
nodeStack.push(mynode.getRightNode());
}
}
return count;
}
private void drawGraph(DirectedAcyclicGraph<Job, DefaultEdge> nfjJobDag) {
for (Job j : nfjJobDag) {
List<Job> predecessors = Graphs.predecessorListOf(nfjJobDag, j);
List<Job> successors = Graphs.successorListOf(nfjJobDag, j);
int test = 4;
}
}
@Test
@DisplayName("Check if Decomposition Tree is created correctly for NFJ Dag.")
void checkDecompositionTreeCreation() {
for (int i = 0; i < 10000; ++i) {
// {
// int i = 610;
// System.out.println(i);
// long numberOfProcessors = ThreadLocalRandom.current().nextLong(4, 16);
long numberOfProcessors = 4;
for (int i = 0; i < 100; ++i) {
long numberOfProcessors = ThreadLocalRandom.current().nextLong(4, 16);
DagTaskBuilder b = new DagTaskBuilder().setNumberOfProcessors(numberOfProcessors);
DagTask t = b.generateTask();
DirectedAcyclicGraph<Job, DefaultEdge> jobDag = t.getJobDag();
......@@ -107,22 +60,13 @@ public class TestDagUtils {
DirectedAcyclicGraph<Job, DefaultEdge> jobDagFromTree =
DagUtils.createNFJfromDecompositionTree(tree);
// drawGraph(nfjJobDag);
// drawGraph(nfjJobDag);
boolean ja = DagUtils.checkNFJProperty(nfjJobDag);
System.out.println("Bei i = " + i + ": nfj = " + ja);
assertTrue(jobDag.vertexSet().size() == nfjJobDag.vertexSet().size());
assertTrue(jobDag.vertexSet().size() == jobDagFromTree.vertexSet().size());
assertTrue(jobDagFromTree.edgeSet().size() == nfjJobDag.edgeSet().size());
for (DefaultEdge e : nfjJobDag.edgeSet()) {
Job target = nfjJobDag.getEdgeTarget(e);
Job source = nfjJobDag.getEdgeSource(e);
if (!jobDagFromTree.containsEdge(source, target)) {
drawGraph(jobDag);
}
assertTrue(jobDagFromTree.containsEdge(source, target));
}
......
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 sign in to comment