Commit c5bc69e2 by Michael Schmid

nfj creation now works

parent 471ee8c4
......@@ -6,8 +6,6 @@ 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;
/**
......@@ -18,7 +16,7 @@ public class App {
public static void main(String[] args) {
for (int p = 8; p <= 8; p *= 2) {
SystemSetup.DagTaskBuilder builder =
new SystemSetup.DagTaskBuilder(p).setNumberOfProcessors(p);
new SystemSetup.DagTaskBuilder().setNumberOfProcessors(p);
TestEnvironment te = new TestEnvironment();
List<AbstractTest<DagTask>> tests =
......
......@@ -3,7 +3,6 @@ package mvd.jester;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import mvd.jester.info.SchedulingInfo.Feasiblity;
import mvd.jester.model.Task;
import mvd.jester.tests.AbstractTest;
import mvd.jester.utils.Logger;
......
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;
......
......@@ -4,7 +4,6 @@ public class Job {
private final long wcet;
private long relativeCompletionTime;
private boolean visited = false;
public Job(long wcet) {
this.wcet = wcet;
......@@ -15,14 +14,6 @@ public class Job {
return wcet;
}
public boolean getVisited() {
return visited;
}
public void setVisited(boolean visited) {
this.visited = visited;
}
/**
* @return the relativeCompletionTime
*/
......
......@@ -5,7 +5,6 @@ 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;
......@@ -207,14 +206,12 @@ public class SystemSetup<T extends Task> {
private long numberOfProcessors = 4;
private long minimumWcet = 1;
private long maximumWcet = 100;
private long maxNumberOfBranches = 3; // TODO: change back to 5
private long depth = 1; // change back to 2
private long maxNumberOfBranches = 5;
private long depth = 2;
private long p_par = 80;
private long p_add = 20;
private final Random random;
public DagTaskBuilder(long seed) {
random = new Random(seed);
public DagTaskBuilder() {
}
public double getBeta() {
......@@ -222,8 +219,7 @@ public class SystemSetup<T extends Task> {
}
private long randomProbability() {
return random.nextInt(100);
// return ThreadLocalRandom.current().nextLong(0, 100);
return ThreadLocalRandom.current().nextLong(0, 100);
}
public Set<DagTask> generateTaskSet(final double totalUtilization) {
......@@ -327,20 +323,16 @@ 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()));
return ThreadLocalRandom.current().nextLong(criticalPathLength,
(long) (workload / getBeta()));
}
private long randomNumberOfBranches() {
return random.nextInt((int) maxNumberOfBranches - 2) + 2;
// return ThreadLocalRandom.current().nextLong(2, maxNumberOfBranches);
return ThreadLocalRandom.current().nextLong(2, maxNumberOfBranches);
}
private long randomWcet() {
return random.nextInt((int) (maximumWcet - minimumWcet)) + minimumWcet;
// return ThreadLocalRandom.current().nextLong(minimumWcet, maximumWcet);
return ThreadLocalRandom.current().nextLong(minimumWcet, maximumWcet);
}
/**
......
......@@ -233,6 +233,10 @@ public class FonsecaNelis extends AbstractTest<DagTask> {
final long totalInterference = (long) Math.floor(taskInterference + selfInterference);
responseTime = criticalPath + totalInterference;
// TODO: remove check of deadline if bug is found
if (responseTime > task.getDeadline()) {
return responseTime;
}
} while (responseTime != previousResponseTime);
return responseTime;
......@@ -262,10 +266,10 @@ public class FonsecaNelis extends AbstractTest<DagTask> {
long workload = getCarryOutWorkload(task, carryOutDistribution, carryInAndOutPeriod);
long carryInPeriod = task.getPeriod() - responseTimes.get(task).getResponseTime();
long carryOutPeriod = 0;
final List<Segment> carryInList = Lists.newArrayList(carryInDistribution);
Collections.reverse(carryInList);
final List<Segment> reverseCarryInList = Lists.newArrayList(carryInDistribution);
Collections.reverse(reverseCarryInList);
for (final Segment s : carryInList) {
for (final Segment s : reverseCarryInList) {
carryInPeriod += s.getJobWcet();
carryOutPeriod = carryInAndOutPeriod - carryInPeriod;
final long carryInWorkload =
......@@ -323,11 +327,11 @@ public class FonsecaNelis extends AbstractTest<DagTask> {
final long responseTime = responseTimes.get(task).getResponseTime();
final List<Segment> distributionList = Lists.newArrayList(carryInDistribution);
for (int i = 0; i < carryInDistribution.size(); ++i) {
final Segment s = distributionList.get(i);
for (int b = 0; b < carryInDistribution.size(); ++b) {
final Segment s = distributionList.get(b);
long weightOfRemainingSegments = 0;
for (int j = i + 1; j < carryInDistribution.size(); ++j) {
weightOfRemainingSegments += distributionList.get(j).getJobWcet();
for (int p = b + 1; p < carryInDistribution.size(); ++p) {
weightOfRemainingSegments += distributionList.get(p).getJobWcet();
}
final long width = carryInPeriod - period + responseTime - weightOfRemainingSegments;
......
......@@ -13,7 +13,7 @@ import com.google.common.collect.Sets;
import org.jgrapht.Graphs;
import org.jgrapht.experimental.dag.DirectedAcyclicGraph;
import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.traverse.ClosestFirstIterator;
import org.jgrapht.traverse.TopologicalOrderIterator;
import mvd.jester.model.Job;
import mvd.jester.model.Segment;
import mvd.jester.utils.BinaryDecompositionTree.Node;
......@@ -32,10 +32,6 @@ public class DagUtils {
public static long calculateCriticalPath(final DirectedAcyclicGraph<Job, DefaultEdge> jobDag) {
long criticalPath = 0;
// BreadthFirstIterator<Job, DefaultEdge> breadthFirstIterator =
// new BreadthFirstIterator<>(jobDag);
// while (breadthFirstIterator.hasNext()) {
// Job job = breadthFirstIterator.next();
for (final Job job : jobDag) {
final Set<DefaultEdge> edges = jobDag.incomingEdgesOf(job);
long longestRelativeCompletionTime = 0;
......@@ -110,10 +106,11 @@ public class DagUtils {
private static LinkedList<Job> getUnvisitedJoinNodes(
final DirectedAcyclicGraph<Job, DefaultEdge> jobDag, final Set<Job> visitedJobs) {
final LinkedList<Job> joinNodes = new LinkedList<>();
final ClosestFirstIterator<Job, DefaultEdge> it = new ClosestFirstIterator<>(jobDag);
final TopologicalOrderIterator<Job, DefaultEdge> it =
new TopologicalOrderIterator<>(jobDag);
for (; it.hasNext();) {
final Job j = it.next();
if (jobDag.inDegreeOf(j) > 1 && /* /* !j.getVisited() */!visitedJobs.contains(j)) {
if (jobDag.inDegreeOf(j) > 1 && !visitedJobs.contains(j)) {
joinNodes.add(j);
}
}
......@@ -139,16 +136,11 @@ public class DagUtils {
}
final Job joinNode = joins.getFirst();
visitedJobs.add(joinNode);
joinNode.setVisited(true);
nextEdge: while (modifiedJobDag.inDegreeOf(joinNode) > 1) {
final List<Job> predecessors = Graphs.predecessorListOf(modifiedJobDag, joinNode);
for (final Job p : predecessors) {
if (!checkPredecessors(modifiedJobDag, joinNode, p)) {
// || !checkPredecessors(modifiedJobDag, p, joinNode, ancestorsOfJ)) {
// DefaultEdge e = modifiedJobDag.getEdge(p, joinNode);
// if ((modifiedJobDag.outDegreeOf(p) > 1)
// || checkForFork(modifiedJobDag, joinNode, e)) {
final DefaultEdge conflictingEdge = modifiedJobDag.getEdge(p, joinNode);
modifiedJobDag.removeEdge(conflictingEdge);
if (modifiedJobDag.outDegreeOf(p) == 0) {
......@@ -169,66 +161,11 @@ public class DagUtils {
}
public static boolean checkForFork(final DirectedAcyclicGraph<Job, DefaultEdge> jobDag,
final Job joinNode, final DefaultEdge edge) {
Set<Job> ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode);
nextFork: for (final Job f : jobDag) {
if (jobDag.outDegreeOf(f) > 1) {
final Set<Job> descendantsOfF = jobDag.getDescendants(jobDag, f);
final Set<Job> inbetweenJobs = new HashSet<>(ancestorsOfJ);
inbetweenJobs.retainAll(descendantsOfF);
if (inbetweenJobs.isEmpty()) {
continue;
}
for (final Job a : inbetweenJobs) {
final List<Job> neighboursOfA = Graphs.neighborListOf(jobDag, a);
for (final Job b : neighboursOfA) {
if (!((jobDag.getAncestors(jobDag, joinNode).contains(b) || b == joinNode)
&& (jobDag.getDescendants(jobDag, f).contains(b) || b == f))) {
continue nextFork;
}
}
}
Job source = jobDag.getEdgeSource(edge);
if (inbetweenJobs.contains(source)) {
return true;
}
}
}
return false;
}
private static boolean checkPredecessors(final DirectedAcyclicGraph<Job, DefaultEdge> jobDag,
final Job current, final Job joinNode, final Set<Job> ancestorsOfJ2) {
final List<Job> successorsOfCurrent = Graphs.successorListOf(jobDag, current);
final Set<Job> ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode);
ancestorsOfJ.add(joinNode);
if (ancestorsOfJ.containsAll(successorsOfCurrent)) {
final Set<Job> descendantsOfCurrent = jobDag.getDescendants(jobDag, current);
if (descendantsOfCurrent.containsAll(Graphs.predecessorListOf(jobDag, joinNode))) {
return true;
} else {
for (final Job p : Graphs.predecessorListOf(jobDag, current)) {
if (!checkPredecessors(jobDag, p, joinNode, ancestorsOfJ)) {
return false;
}
}
return true;
}
} else {
return false;
}
}
private static boolean checkPredecessors(final DirectedAcyclicGraph<Job, DefaultEdge> jobDag,
final Job joinNode, Job current) {
final Set<Job> ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode);
ancestorsOfJ.add(joinNode);
if (jobDag.outDegreeOf(current) > 1) {
final Set<Job> ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode);
ancestorsOfJ.add(joinNode);
if (!ancestorsOfJ.containsAll(Graphs.successorListOf(jobDag, current))) {
return false;
}
......
......@@ -3,7 +3,6 @@ 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;
......@@ -40,10 +39,7 @@ public class TestDagUtils {
@DisplayName("Check if NFJ DAGs are created correctly.")
void checkNfjDagCreation() {
for (int i = 0; i < 10000; ++i) {
// {
// int i = 1992;
System.out.println(i);
DagTaskBuilder b = new DagTaskBuilder(i);
DagTaskBuilder b = new DagTaskBuilder();
DagTask t = b.generateTask();
DirectedAcyclicGraph<Job, DefaultEdge> nfjDag = DagUtils.createNFJGraph(t.getJobDag());
......@@ -98,11 +94,11 @@ public class TestDagUtils {
void checkDecompositionTreeCreation() {
for (int i = 0; i < 10000; ++i) {
// {
// int i = 847;
// int i = 610;
// System.out.println(i);
long numberOfProcessors = ThreadLocalRandom.current().nextLong(4, 16);
// long numberOfProcessors = 4;
DagTaskBuilder b = new DagTaskBuilder(i).setNumberOfProcessors(numberOfProcessors);
// long numberOfProcessors = ThreadLocalRandom.current().nextLong(4, 16);
long numberOfProcessors = 4;
DagTaskBuilder b = new DagTaskBuilder().setNumberOfProcessors(numberOfProcessors);
DagTask t = b.generateTask();
DirectedAcyclicGraph<Job, DefaultEdge> jobDag = t.getJobDag();
DirectedAcyclicGraph<Job, DefaultEdge> nfjJobDag = DagUtils.createNFJGraph(jobDag);
......@@ -124,9 +120,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);
// }
if (!jobDagFromTree.containsEdge(source, target)) {
drawGraph(jobDag);
}
assertTrue(jobDagFromTree.containsEdge(source, target));
}
......
......@@ -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(i);
DagTaskBuilder builder = new DagTaskBuilder();
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(i);
DagTaskBuilder builder = new DagTaskBuilder();
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