Commit 24eebe3e by Michael Schmid

Binary dec tree and nfj creation finished

parent a15a466e
package mvd.jester.utils; package mvd.jester.utils;
public class BinaryDecompositionTree<N> { public class BinaryDecompositionTree<N> {
private Node<N> root; private Node<N> root;
...@@ -12,6 +13,9 @@ public class BinaryDecompositionTree<N> { ...@@ -12,6 +13,9 @@ public class BinaryDecompositionTree<N> {
} }
public boolean contains(N object) { public boolean contains(N object) {
if (root == null) {
return false;
}
return root.contains(object); return root.contains(object);
} }
...@@ -75,8 +79,9 @@ public class BinaryDecompositionTree<N> { ...@@ -75,8 +79,9 @@ public class BinaryDecompositionTree<N> {
/** /**
* @param leftNode the leftNode to set * @param leftNode the leftNode to set
*/ */
public void setLeftNode(Node<T> leftNode) { public Node<T> setLeftNode(Node<T> leftNode) {
this.leftNode = leftNode; this.leftNode = leftNode;
return this.leftNode;
} }
/** /**
...@@ -89,8 +94,9 @@ public class BinaryDecompositionTree<N> { ...@@ -89,8 +94,9 @@ public class BinaryDecompositionTree<N> {
/** /**
* @param rightNode the rightNode to set * @param rightNode the rightNode to set
*/ */
public void setRightNode(Node<T> rightNode) { public Node<T> setRightNode(Node<T> rightNode) {
this.rightNode = rightNode; this.rightNode = rightNode;
return this.rightNode;
} }
/** /**
......
package mvd.jester.model; package mvd.jester.model;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.jgrapht.Graphs;
import org.jgrapht.experimental.dag.DirectedAcyclicGraph; import org.jgrapht.experimental.dag.DirectedAcyclicGraph;
import org.jgrapht.graph.DefaultEdge; import org.jgrapht.graph.DefaultEdge;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
...@@ -12,20 +13,6 @@ import mvd.jester.utils.BinaryDecompositionTree; ...@@ -12,20 +13,6 @@ import mvd.jester.utils.BinaryDecompositionTree;
public class TestDagUtils { public class TestDagUtils {
@Test @Test
@DisplayName("Test if a NFJ Graph is created correctly.")
public void checkNFJCreation() {
for (int i = 0; i < 100; ++i) {
DagTaskBuilder builder = new DagTaskBuilder();
DirectedAcyclicGraph<Job, DefaultEdge> jobDag = builder.generateTask().getJobDag();
DirectedAcyclicGraph<Job, DefaultEdge> modifiedJobDag = DagUtils.createNFJGraph(jobDag);
assertTrue(DagUtils.checkNFJProperty(modifiedJobDag));
}
}
@Test
@DisplayName("Test if dynamic segments are constructed correctly.") @DisplayName("Test if dynamic segments are constructed correctly.")
public void checkPathLength() { public void checkPathLength() {
DirectedAcyclicGraph<Job, DefaultEdge> jobDag = createJobDag(); DirectedAcyclicGraph<Job, DefaultEdge> jobDag = createJobDag();
...@@ -45,15 +32,73 @@ public class TestDagUtils { ...@@ -45,15 +32,73 @@ public class TestDagUtils {
@Test @Test
@DisplayName("Check if NFJ DAGs are created correctly.")
void checkNfjDagCreation() {
for (int i = 0; i < 100; ++i) {
DagTaskBuilder b = new DagTaskBuilder();
DagTask t = b.generateTask();
DirectedAcyclicGraph<Job, DefaultEdge> nfjDag = DagUtils.createNFJGraph(t.getJobDag());
assertTrue(DagUtils.checkNFJProperty(nfjDag));
}
}
@Test
@DisplayName("Check if Decomposition Tree is created correctly for NFJ Dag.") @DisplayName("Check if Decomposition Tree is created correctly for NFJ Dag.")
void checkDecompositionTreeCreation() { void checkDecompositionTreeCreation() {
DirectedAcyclicGraph<Job, DefaultEdge> jobDag = createJobDag(); for (int i = 0; i < 100; ++i) {
DagTaskBuilder b = new DagTaskBuilder();
BinaryDecompositionTree<Job> tree = DagUtils.createDecompositionTree(jobDag); DagTask t = b.generateTask();
DirectedAcyclicGraph<Job, DefaultEdge> jobDagFromTree = DirectedAcyclicGraph<Job, DefaultEdge> jobDag = t.getJobDag();
DagUtils.createNFJfromDecompositionTree(tree); DirectedAcyclicGraph<Job, DefaultEdge> nfjJobDag = DagUtils.createNFJGraph(jobDag);
BinaryDecompositionTree<Job> tree = DagUtils.createDecompositionTree(nfjJobDag);
DirectedAcyclicGraph<Job, DefaultEdge> jobDagFromTree =
DagUtils.createNFJfromDecompositionTree(tree);
assertTrue(jobDag.vertexSet().equals(nfjJobDag.vertexSet()));
assertTrue(jobDag.vertexSet().equals(jobDagFromTree.vertexSet()));
assertTrue(jobDagFromTree.edgeSet().size() == nfjJobDag.edgeSet().size());
for (DefaultEdge e : nfjJobDag.edgeSet()) {
Job target = nfjJobDag.getEdgeTarget(e);
Job source = nfjJobDag.getEdgeSource(e);
assertTrue(jobDagFromTree.containsEdge(source, target));
}
for (Job j : nfjJobDag) {
for (Job n : nfjJobDag) {
if (n == j) {
continue;
}
if (nfjJobDag.containsEdge(n, j)) {
assertTrue(jobDagFromTree.containsEdge(n, j));
}
}
assertTrue(nfjJobDag.inDegreeOf(j) == jobDagFromTree.inDegreeOf(j));
assertTrue(nfjJobDag.outDegreeOf(j) == jobDagFromTree.outDegreeOf(j));
for (Job p : Graphs.predecessorListOf(nfjJobDag, j)) {
assertTrue(Graphs.predecessorListOf(jobDagFromTree, j).contains(p));
}
for (Job s : Graphs.successorListOf(jobDagFromTree, j)) {
assertTrue(Graphs.successorListOf(jobDagFromTree, j).contains(s));
}
for (Job a : nfjJobDag.getAncestors(nfjJobDag, j)) {
assertTrue(jobDagFromTree.getAncestors(jobDagFromTree, j).contains(a));
}
for (Job d : nfjJobDag.getDescendants(nfjJobDag, j)) {
assertTrue(jobDagFromTree.getDescendants(jobDagFromTree, j).contains(d));
}
}
assertTrue(jobDag.equals(jobDagFromTree)); }
} }
......
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