Commit bc29a6dc by Michael Schmid

creating nfj dags now works

parent f0a948aa
package mvd.jester;
import java.util.Arrays;
import java.util.Set;
import java.util.List;
import mvd.jester.model.DagTask;
import mvd.jester.model.SystemSetup;
import mvd.jester.tests.AbstractTest;
import mvd.jester.tests.FonsecaNelis;
import mvd.jester.tests.MelaniButtazzo;
import mvd.jester.tests.SchmidMottok;
......@@ -17,13 +18,15 @@ public class App {
public static void main(String[] args) {
for (int p = 8; p <= 8; p *= 2) {
SystemSetup.DagTaskBuilder builder =
new SystemSetup.DagTaskBuilder().setNumberOfProcessors(p);
new SystemSetup.DagTaskBuilder(p).setNumberOfProcessors(p);
TestEnvironment te = new TestEnvironment();
Set<ResultCollector<AbstractTest<DagTask>>> tests = te.registerTests(Arrays
.asList(new SchmidMottok(p), /* new MelaniButtazzo(p), */ new FonsecaNelis(p)));
List<AbstractTest<DagTask>> tests =
te.registerTests(Arrays.asList(/*
* new SchmidMottok(p), new MelaniButtazzo(p) ,
*/ new FonsecaNelis(p)));
te.runExperiments(builder, tests, p, 500);
te.runExperiments(builder, tests, p, 100);
}
}
}
......@@ -20,6 +20,12 @@ public class ResultCollector<T extends TypeInterface>
this.schedulingInfos = new HashSet<>();
}
public ResultCollector(ResultCollector<T> resultCollector) {
this.abstractValue = resultCollector.abstractValue;
this.priorityManager = resultCollector.priorityManager;
this.schedulingInfos = new HashSet<>();
}
/**
* @return the priorityManager
*/
......
package mvd.jester;
import java.io.IOException;
import java.time.LocalTime;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ObjectArrays;
import com.google.common.collect.Table;
import com.google.common.collect.TreeBasedTable;
import com.google.common.math.DoubleMath;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import java.util.Map.Entry;
import mvd.jester.info.SchedulingInfo.Feasiblity;
import mvd.jester.model.Task;
import mvd.jester.simulator.AbstractSimulator;
import mvd.jester.tests.AbstractTest;
import mvd.jester.utils.Logger;
......@@ -22,34 +13,68 @@ import mvd.jester.utils.Logger;
*/
public class ResultLogger {
private final long numberOfProcessors;
private final Logger logger;
private boolean headerLogged = false;
public ResultLogger(long numberOfProcessors) {
this.numberOfProcessors = numberOfProcessors;
public ResultLogger(final long numberOfProcessors) {
this.logger = new Logger("./results/feasibility_" + numberOfProcessors + ".txt");
}
public <T extends Task> void logAll(Set<ResultCollector<AbstractTest<T>>> testResults,
Set<ResultCollector<AbstractSimulator>> simResults) {
logTests(testResults);
logSimulations(simResults);
}
public <T extends Task> void logTests(Set<ResultCollector<AbstractTest<T>>> results) {
if (!results.isEmpty()) {
logFeasibility(results, "test");
public <T extends Task> void logLine(final double utilization,
final Map<AbstractTest<T>, Long> results) {
final Appendable out = new StringBuilder();
try {
if (!headerLogged) {
headerLogged = true;
out.append("Utilization");
for (final Entry<AbstractTest<T>, Long> rc : results.entrySet()) {
out.append("\t" + rc.getKey().getName());
}
out.append("\n");
}
out.append("" + utilization);
for (final Entry<AbstractTest<T>, Long> rc : results.entrySet()) {
final long numberOfFeasibleTasks = rc.getValue();
out.append("\t" + numberOfFeasibleTasks);
}
} catch (final Exception e) {
throw new RuntimeException("Failed to log line!");
}
logger.log(out);
}
public void logSimulations(Set<ResultCollector<AbstractSimulator>> results) {
if (!results.isEmpty()) {
logFeasibility(results, "sim");
logTaskRatio(results, "sim");
public void newLine() {
final Appendable out = new StringBuilder();
try {
out.append("\n");
} catch (final Exception e) {
throw new RuntimeException("Failed to log line!");
}
logger.log(out);
}
// public <T extends Task> void logAll(Set<ResultCollector<AbstractTest<T>>> testResults,
// Set<ResultCollector<AbstractSimulator>> simResults) {
// logTests(testResults);
// logSimulations(simResults);
// }
// public <T extends Task> void logTests(Set<ResultCollector<AbstractTest<T>>> results) {
// if (!results.isEmpty()) {
// logFeasibility(results, "test");
// }
// }
// public void logSimulations(Set<ResultCollector<AbstractSimulator>> results) {
// if (!results.isEmpty()) {
// logFeasibility(results, "sim");
// logTaskRatio(results, "sim");
// }
// }
public <T extends TypeInterface> void logFeasibilityLevel(Set<ResultCollector<T>> results,
String type) {
public <T extends TypeInterface> void logFeasibilityLevel(final Set<ResultCollector<T>> results,
final String type) {
// LocalTime date = LocalTime.now();
// Logger log = new Logger("./results/feasibility_level_" + type + "_" + numberOfProcessors
// + "_" + date.getHour() + ":" + date.getMinute() + ".txt");
......@@ -82,31 +107,31 @@ public class ResultLogger {
public <T extends TypeInterface> void logFeasibility(Set<ResultCollector<T>> results,
String type) {
LocalTime date = LocalTime.now();
Logger log = new Logger("./results/feasibility_" + type + "_" + numberOfProcessors + "_"
+ date.getHour() + ":" + date.getMinute() + ".txt");
// public <T extends TypeInterface> void logFeasibility(Set<ResultCollector<T>> results,
// String type) {
// LocalTime date = LocalTime.now();
// Logger log = new Logger("./results/feasibility_" + type + "_" + numberOfProcessors + "_"
// + date.getHour() + ":" + date.getMinute() + ".txt");
Table<Double, ResultCollector<T>, Long> resultTable = TreeBasedTable.create();
Set<ResultCollector<T>> resultCollectors = new TreeSet<>();
// Table<Double, ResultCollector<T>, Long> resultTable = TreeBasedTable.create();
// Set<ResultCollector<T>> resultCollectors = new TreeSet<>();
for (double util = 0.25; util <= numberOfProcessors; util += 0.25) {
for (ResultCollector<T> rc : results) {
resultCollectors.add(rc);
final double local_util = util;
long feasibleTasksets = rc.getResults().stream()
.filter(r -> DoubleMath.fuzzyEquals(r.getUtilization(), local_util, 0.125))
.filter(r -> r.checkTasksetFeasible()).count();
resultTable.put(util, rc, feasibleTasksets);
}
}
// for (double util = 0.25; util <= numberOfProcessors; util += 0.25) {
// for (ResultCollector<T> rc : results) {
// resultCollectors.add(rc);
// final double local_util = util;
// long feasibleTasksets = rc.getResults().stream()
// .filter(r -> DoubleMath.fuzzyEquals(r.getUtilization(), local_util, 0.125))
// .filter(r -> r.checkTasksetFeasible()).count();
// resultTable.put(util, rc, feasibleTasksets);
// }
// }
logData(log, resultTable, resultCollectors, "Utilization");
}
// logData(log, resultTable, resultCollectors, "Utilization");
// }
public <T extends TypeInterface> void logFeasibilityRatio(Set<ResultCollector<T>> results,
String type) {
public <T extends TypeInterface> void logFeasibilityRatio(final Set<ResultCollector<T>> results,
final String type) {
// LocalTime date = LocalTime.now();
// Logger log = new Logger("./results/feasibility_ratio_" + type + "_" + numberOfProcessors
// + "_" + date.getHour() + ":" + date.getMinute() + ".txt");
......@@ -135,8 +160,8 @@ public class ResultLogger {
// logData(log, resultTable, resultCollectors, "Utilization");
}
public <T extends TypeInterface> void logTaskRatio(Set<ResultCollector<T>> results,
String type) {
public <T extends TypeInterface> void logTaskRatio(final Set<ResultCollector<T>> results,
final String type) {
// LocalTime date = LocalTime.now();
// Logger log = new Logger("./results/task_ratio_" + type + "_" + numberOfProcessors + "_"
// + date.getHour() + ":" + date.getMinute() + ".txt");
......@@ -158,25 +183,29 @@ public class ResultLogger {
// logData(log, resultTable, resultCollectors, "TaskRatio");
}
private <T extends TypeInterface> void logData(Logger log,
Table<Double, ResultCollector<T>, ? extends Number> resultTable,
Set<ResultCollector<T>> resultCollectors, String xDataName) {
final Appendable out = new StringBuilder();
try {
String[] resultCollectorNames = resultCollectors.stream()
.map(ResultCollector<T>::getName).toArray(String[]::new);
String[] header = ObjectArrays.concat(xDataName, resultCollectorNames);
final CSVPrinter printer = CSVFormat.DEFAULT.withHeader(header).print(out);
printer.printRecords(resultTable.rowMap().entrySet().stream()
.map(entry -> ImmutableList.builder().add((double) entry.getKey())
.addAll(entry.getValue().values()).build())
.collect(Collectors.toList()));
} catch (final IOException e) {
e.printStackTrace();
}
log.log(out);
log.finalize();
public void finalize() {
logger.finalize();
}
// private <T extends TypeInterface> void logData(Logger log,
// Table<Double, ResultCollector<T>, ? extends Number> resultTable,
// Set<ResultCollector<T>> resultCollectors, String xDataName) {
// final Appendable out = new StringBuilder();
// try {
// String[] resultCollectorNames = resultCollectors.stream()
// .map(ResultCollector<T>::getName).toArray(String[]::new);
// String[] header = ObjectArrays.concat(xDataName, resultCollectorNames);
// final CSVPrinter printer = CSVFormat.DEFAULT.withHeader(header).print(out);
// printer.printRecords(resultTable.rowMap().entrySet().stream()
// .map(entry -> ImmutableList.builder().add((double) entry.getKey())
// .addAll(entry.getValue().values()).build())
// .collect(Collectors.toList()));
// } catch (final IOException e) {
// e.printStackTrace();
// }
// log.log(out);
// log.finalize();
// }
}
package mvd.jester;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import mvd.jester.info.SchedulingInfo;
import mvd.jester.info.SchedulingInfo.Feasiblity;
import mvd.jester.model.DagTask;
import mvd.jester.model.SortedTaskSet;
import mvd.jester.model.SynchronousTask;
......@@ -22,26 +27,24 @@ public class TestEnvironment {
public TestEnvironment() {
}
public <T extends Task> Set<ResultCollector<AbstractTest<T>>> registerTests(
List<AbstractTest<T>> tests) {
Set<ResultCollector<AbstractTest<T>>> testSet = new HashSet<>();
for (AbstractTest<T> t : tests) {
testSet.add(new ResultCollector<AbstractTest<T>>(t.getPriorityManager(), t));
}
return testSet;
public <T extends Task> List<AbstractTest<T>> registerTests(final List<AbstractTest<T>> tests) {
// Set<ResultCollector<AbstractTest<T>>> testSet = new HashSet<>();
// for (AbstractTest<T> t : tests) {
// testSet.add(new ResultCollector<AbstractTest<T>>(t.getPriorityManager(), t));
// }
return new ArrayList<>(tests);
}
public void runExperiments(SynchronousTaskBuilder builder,
Set<ResultCollector<AbstractTest<SynchronousTask>>> abstractTestInstances,
long numberOfProcessors, long numberOfTaskSets) {
public void runExperiments(final SynchronousTaskBuilder builder,
final Set<ResultCollector<AbstractTest<SynchronousTask>>> abstractTestInstances,
final long numberOfProcessors, final long numberOfTaskSets) {
long checkedTasksets = 0;
System.out.print(Math.round((double) checkedTasksets / numberOfTaskSets * 100) + "% of "
+ numberOfTaskSets + " tasksets tested!\r");
while (checkedTasksets < numberOfTaskSets) {
Set<SynchronousTask> tasks = builder.generateTaskSet();
final Set<SynchronousTask> tasks = builder.generateTaskSet();
double utilization = tasks.stream().mapToDouble(SynchronousTask::getUtilization).sum();
......@@ -53,14 +56,15 @@ public class TestEnvironment {
+ "% of " + numberOfTaskSets + " tasksets tested!\r");
}
for (ResultCollector<AbstractTest<SynchronousTask>> testInstance : abstractTestInstances) {
PriorityManager priorityManager = testInstance.getPriorityManager();
AbstractTest<SynchronousTask> abstractTest = testInstance.getAbstractValue();
for (final ResultCollector<AbstractTest<SynchronousTask>> testInstance : abstractTestInstances) {
final PriorityManager priorityManager = testInstance.getPriorityManager();
final AbstractTest<SynchronousTask> abstractTest =
testInstance.getAbstractValue();
SortedTaskSet<SynchronousTask> sortedTaskSet =
final SortedTaskSet<SynchronousTask> sortedTaskSet =
new SortedTaskSet<>(priorityManager);
sortedTaskSet.addAll(tasks);
SchedulingInfo schedulingInfo =
final SchedulingInfo schedulingInfo =
abstractTest.runSchedulabilityCheck(sortedTaskSet);
testInstance.addResult(schedulingInfo);
}
......@@ -71,47 +75,55 @@ public class TestEnvironment {
}
}
System.out.println("");
ResultLogger resultLogger = new ResultLogger(numberOfProcessors);
final ResultLogger resultLogger = new ResultLogger(numberOfProcessors);
resultLogger.logTests(abstractTestInstances);
// resultLogger.logTests(abstractTestInstances);
}
public void runExperiments(DagTaskBuilder builder,
Set<ResultCollector<AbstractTest<DagTask>>> abstractTestInstances,
long numberOfProcessors, long numberOfTaskSetsPerUtil) {
public void runExperiments(final DagTaskBuilder builder,
final List<AbstractTest<DagTask>> abstractTestInstances, final long numberOfProcessors,
final long numberOfTaskSetsPerUtil) {
long checkedTasksets = 0;
long numberOfTaskSets = numberOfProcessors * 4 * numberOfTaskSetsPerUtil;
final long numberOfTaskSets = ((numberOfProcessors * 4) - 3) * numberOfTaskSetsPerUtil;
// create LoggerFile here
final ResultLogger resultLogger = new ResultLogger(numberOfProcessors);
final Map<AbstractTest<DagTask>, Long> resultMap = new LinkedHashMap<>();
abstractTestInstances.forEach(t -> resultMap.put(t, (long) 0));
for (double util = 1; util <= numberOfProcessors; util += 0.25) {
// new Result set here
for (int i = 0; i < numberOfTaskSetsPerUtil; ++i) {
Set<DagTask> taskSet = builder.generateTaskSet(util);
resultMap.replaceAll((k, v) -> (long) 0);
nextTry: for (int i = 0; i < numberOfTaskSetsPerUtil; ++i) {
final Set<DagTask> taskSet = builder.generateTaskSet(util);
System.out.print(Math.round((double) checkedTasksets / numberOfTaskSets * 100)
+ "% of " + numberOfTaskSets + " tasksets tested!\r");
for (ResultCollector<AbstractTest<DagTask>> testResultCollector : abstractTestInstances) {
AbstractTest<DagTask> testInstance = testResultCollector.getAbstractValue();
PriorityManager priorityManager = testResultCollector.getPriorityManager();
for (final AbstractTest<DagTask> testInstance : abstractTestInstances) {
final PriorityManager priorityManager = testInstance.getPriorityManager();
SortedTaskSet<DagTask> sortedTaskSet = new SortedTaskSet<>(priorityManager);
final SortedTaskSet<DagTask> sortedTaskSet =
new SortedTaskSet<>(priorityManager);
sortedTaskSet.addAll(taskSet);
SchedulingInfo schedulingInfo =
testInstance.runSchedulabilityCheck(sortedTaskSet);
testResultCollector.addResult(schedulingInfo);
final SchedulingInfo schedulingInfo;
try {
schedulingInfo = testInstance.runSchedulabilityCheck(sortedTaskSet);
} catch (Exception e) {
i--;
continue nextTry;
// TODO: remove this exception
}
if (schedulingInfo.getFeasibility() == Feasiblity.SUCCEEDED) {
resultMap.computeIfPresent(testInstance, (k, v) -> v + 1);
}
}
checkedTasksets++;
}
// write Result line to LoggerFile
resultLogger.logLine(util, resultMap);
resultLogger.newLine();
}
System.out.println("");
ResultLogger resultLogger = new ResultLogger(numberOfProcessors);
resultLogger.logTests(abstractTestInstances);
resultLogger.finalize();
}
}
......
......@@ -4,6 +4,7 @@ public class Job {
private final long wcet;
private long relativeCompletionTime;
private boolean visited = false;
public Job(long wcet) {
this.wcet = wcet;
......@@ -14,6 +15,14 @@ public class Job {
return wcet;
}
public boolean getVisited() {
return visited;
}
public void setVisited(boolean visited) {
this.visited = visited;
}
/**
* @return the relativeCompletionTime
*/
......
......@@ -5,6 +5,7 @@ import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import com.google.common.collect.ArrayListMultimap;
......@@ -206,17 +207,23 @@ public class SystemSetup<T extends Task> {
private long numberOfProcessors = 4;
private long minimumWcet = 1;
private long maximumWcet = 100;
private long maxNumberOfBranches = 5;
private long depth = 2;
private long maxNumberOfBranches = 3; // TODO: change back to 5
private long depth = 1; // change back to 2
private long p_par = 80;
private long p_add = 20;
private final Random random;
public DagTaskBuilder(long seed) {
random = new Random(seed);
}
public double getBeta() {
return 0.035 * numberOfProcessors;
}
private long randomProbability() {
return ThreadLocalRandom.current().nextLong(1, 100);
// return random.nextInt(99) + 1;
return ThreadLocalRandom.current().nextLong(0, 100);
}
public Set<DagTask> generateTaskSet(final double totalUtilization) {
......@@ -251,7 +258,7 @@ public class SystemSetup<T extends Task> {
final Job j = fork(jobDag, Optional.empty(), this.depth);
fork(jobDag, Optional.of(j), this.depth);
randomEdges(jobDag);
// randomEdges(jobDag); // TODO: uncomment
final long workload = DagUtils.calculateWorkload(jobDag);
final long criticalPath = DagUtils.calculateCriticalPath(jobDag);
......@@ -320,15 +327,19 @@ public class SystemSetup<T extends Task> {
}
private long randomTaskPeriod(final long criticalPathLength, final long workload) {
// long upper = (long) (workload / getBeta());
// return random.nextInt((int) (upper - criticalPathLength)) + criticalPathLength;
return ThreadLocalRandom.current().nextLong(criticalPathLength,
(long) (workload / getBeta()));
}
private long randomNumberOfBranches() {
// return random.nextInt((int) maxNumberOfBranches - 2) + 2;
return ThreadLocalRandom.current().nextLong(2, maxNumberOfBranches);
}
private long randomWcet() {
// return random.nextInt((int) (maximumWcet - minimumWcet)) + minimumWcet;
return ThreadLocalRandom.current().nextLong(minimumWcet, maximumWcet);
}
......
......@@ -13,6 +13,7 @@ import java.util.Set;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.math.LongMath;
import org.jgrapht.Graphs;
import org.jgrapht.experimental.dag.DirectedAcyclicGraph;
import org.jgrapht.graph.DefaultEdge;
import mvd.jester.info.SchedulingInfo;
......@@ -68,11 +69,80 @@ public class FonsecaNelis extends AbstractTest<DagTask> {
final DirectedAcyclicGraph<Job, DefaultEdge> nfjJobDag =
DagUtils.createNFJGraph(jobDag);
final BinaryDecompositionTree<Job> tree = DagUtils.createDecompositionTree(nfjJobDag);
// TODO: remove this
if (!DagUtils.checkNFJProperty(nfjJobDag) || !checkTree(nfjJobDag, tree)) {
throw new RuntimeException("Nicht NFJ in Test!");
}
sortedSegments.put(t, constructCarryOutDistribution(nfjJobDag, tree));
}
}
// TODO: Remove this function
private boolean checkTree(DirectedAcyclicGraph<Job, DefaultEdge> nfjJobDag,
BinaryDecompositionTree<Job> tree) {
DirectedAcyclicGraph<Job, DefaultEdge> jobDagFromTree =
DagUtils.createNFJfromDecompositionTree(tree);
if (nfjJobDag.vertexSet().size() != jobDagFromTree.vertexSet().size()) {
return false;
}
if (jobDagFromTree.edgeSet().size() != nfjJobDag.edgeSet().size()) {
return false;
}
for (DefaultEdge e : nfjJobDag.edgeSet()) {
Job target = nfjJobDag.getEdgeTarget(e);
Job source = nfjJobDag.getEdgeSource(e);
if (!jobDagFromTree.containsEdge(source, target)) {
return false;
}
}
for (Job j : nfjJobDag) {
for (Job n : nfjJobDag) {
if (n == j) {
continue;
}
if (nfjJobDag.containsEdge(n, j) && !jobDagFromTree.containsEdge(n, j)) {
return false;
}
}
if (nfjJobDag.inDegreeOf(j) != jobDagFromTree.inDegreeOf(j))
return false;
if (nfjJobDag.outDegreeOf(j) != jobDagFromTree.outDegreeOf(j))
return false;
for (Job p : Graphs.predecessorListOf(nfjJobDag, j)) {
if (!Graphs.predecessorListOf(jobDagFromTree, j).contains(p)) {
return false;
}
}
for (Job s : Graphs.successorListOf(nfjJobDag, j)) {
if (!Graphs.successorListOf(jobDagFromTree, j).contains(s)) {
return false;
}
}
for (Job a : nfjJobDag.getAncestors(nfjJobDag, j)) {
if (!jobDagFromTree.getAncestors(jobDagFromTree, j).contains(a)) {
return false;
}
}
for (Job d : nfjJobDag.getDescendants(nfjJobDag, j)) {
if (!jobDagFromTree.getDescendants(jobDagFromTree, j).contains(d)) {
return false;
}
}
}
return true;
}
private Set<Segment> constructCarryOutDistribution(
final DirectedAcyclicGraph<Job, DefaultEdge> nfjDag,
final BinaryDecompositionTree<Job> tree) {
......
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;
......@@ -8,6 +10,8 @@ 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;
......@@ -35,22 +39,70 @@ public class TestDagUtils {
@Test
@DisplayName("Check if NFJ DAGs are created correctly.")
void checkNfjDagCreation() {
for (int i = 0; i < 100; ++i) {
DagTaskBuilder b = new DagTaskBuilder();
for (int i = 0; i < 10000; ++i) {
// {
// int i = 1992;
System.out.println(i);
DagTaskBuilder b = new DagTaskBuilder(i);
DagTask t = b.generateTask();
DirectedAcyclicGraph<Job, DefaultEdge> nfjDag = DagUtils.createNFJGraph(t.getJobDag());
assertTrue(DagUtils.checkNFJProperty(nfjDag));
}
}
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 < 100; ++i) {
for (int i = 0; i < 10000; ++i) {
// {
// int i = 847;
// System.out.println(i);
long numberOfProcessors = ThreadLocalRandom.current().nextLong(4, 16);
DagTaskBuilder b = new DagTaskBuilder().setNumberOfProcessors(numberOfProcessors);
// long numberOfProcessors = 4;
DagTaskBuilder b = new DagTaskBuilder(i).setNumberOfProcessors(numberOfProcessors);
DagTask t = b.generateTask();
DirectedAcyclicGraph<Job, DefaultEdge> jobDag = t.getJobDag();
DirectedAcyclicGraph<Job, DefaultEdge> nfjJobDag = DagUtils.createNFJGraph(jobDag);
......@@ -59,6 +111,11 @@ 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());
......@@ -67,6 +124,9 @@ public class TestDagUtils {
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));
}
......@@ -87,7 +147,7 @@ public class TestDagUtils {
assertTrue(Graphs.predecessorListOf(jobDagFromTree, j).contains(p));
}
for (Job s : Graphs.successorListOf(jobDagFromTree, j)) {
for (Job s : Graphs.successorListOf(nfjJobDag, j)) {
assertTrue(Graphs.successorListOf(jobDagFromTree, j).contains(s));
}
......@@ -101,6 +161,7 @@ public class TestDagUtils {
}
}
}
......
......@@ -74,7 +74,7 @@ public class TestSystemSetup {
@DisplayName("Check if DagTaskBuilder works correctly")
void testDagTaskBuilder() {
for (int i = 0; i < 100; ++i) {
DagTaskBuilder builder = new DagTaskBuilder();
DagTaskBuilder builder = new DagTaskBuilder(i);
DagTask task = builder.generateTask();
DirectedAcyclicGraph<Job, DefaultEdge> jobDag = task.getJobDag();
......@@ -103,7 +103,7 @@ public class TestSystemSetup {
void testUtil() {
for (int i = 0; i < 5; ++i) {
for (double d = 0.25; d < 4; d += 0.25) {
DagTaskBuilder builder = new DagTaskBuilder();
DagTaskBuilder builder = new DagTaskBuilder(i);
Set<DagTask> taskSet = builder.generateTaskSet(d);
double taskSetUtil = 0;
for (DagTask t : taskSet) {
......
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