Commit 471ee8c4 by Michael Schmid

nfj creation does not work

parent bc29a6dc
...@@ -222,8 +222,8 @@ public class SystemSetup<T extends Task> { ...@@ -222,8 +222,8 @@ public class SystemSetup<T extends Task> {
} }
private long randomProbability() { private long randomProbability() {
// return random.nextInt(99) + 1; return random.nextInt(100);
return ThreadLocalRandom.current().nextLong(0, 100); // return ThreadLocalRandom.current().nextLong(0, 100);
} }
public Set<DagTask> generateTaskSet(final double totalUtilization) { public Set<DagTask> generateTaskSet(final double totalUtilization) {
...@@ -258,7 +258,7 @@ public class SystemSetup<T extends Task> { ...@@ -258,7 +258,7 @@ public class SystemSetup<T extends Task> {
final Job j = fork(jobDag, Optional.empty(), this.depth); final Job j = fork(jobDag, Optional.empty(), this.depth);
fork(jobDag, Optional.of(j), this.depth); fork(jobDag, Optional.of(j), this.depth);
// randomEdges(jobDag); // TODO: uncomment randomEdges(jobDag);
final long workload = DagUtils.calculateWorkload(jobDag); final long workload = DagUtils.calculateWorkload(jobDag);
final long criticalPath = DagUtils.calculateCriticalPath(jobDag); final long criticalPath = DagUtils.calculateCriticalPath(jobDag);
...@@ -297,7 +297,7 @@ public class SystemSetup<T extends Task> { ...@@ -297,7 +297,7 @@ public class SystemSetup<T extends Task> {
System.out.println("Adding fork edge failed!"); System.out.println("Adding fork edge failed!");
} }
} }
if (depth >= 0 && randomProbability() <= p_par) { if (depth >= 0 && randomProbability() < p_par) {
final long numberOfJobs = randomNumberOfBranches(); final long numberOfJobs = randomNumberOfBranches();
for (int i = 0; i < numberOfJobs; ++i) { for (int i = 0; i < numberOfJobs; ++i) {
childs.add(fork(jobDag, Optional.of(job), depth - 1)); childs.add(fork(jobDag, Optional.of(job), depth - 1));
...@@ -311,7 +311,7 @@ public class SystemSetup<T extends Task> { ...@@ -311,7 +311,7 @@ public class SystemSetup<T extends Task> {
final Multimap<Job, Job> edgePairs = ArrayListMultimap.create(); final Multimap<Job, Job> edgePairs = ArrayListMultimap.create();
for (final Job j1 : jobDag) { for (final Job j1 : jobDag) {
for (final Job j2 : jobDag) { for (final Job j2 : jobDag) {
if (randomProbability() <= p_add) { if (randomProbability() < p_add) {
edgePairs.put(j1, j2); edgePairs.put(j1, j2);
} }
} }
...@@ -327,20 +327,20 @@ public class SystemSetup<T extends Task> { ...@@ -327,20 +327,20 @@ public class SystemSetup<T extends Task> {
} }
private long randomTaskPeriod(final long criticalPathLength, final long workload) { private long randomTaskPeriod(final long criticalPathLength, final long workload) {
// long upper = (long) (workload / getBeta()); long upper = (long) (workload / getBeta());
// return random.nextInt((int) (upper - criticalPathLength)) + criticalPathLength; return random.nextInt((int) (upper - criticalPathLength)) + criticalPathLength;
return ThreadLocalRandom.current().nextLong(criticalPathLength, // return ThreadLocalRandom.current().nextLong(criticalPathLength,
(long) (workload / getBeta())); // (long) (workload / getBeta()));
} }
private long randomNumberOfBranches() { private long randomNumberOfBranches() {
// return random.nextInt((int) maxNumberOfBranches - 2) + 2; return random.nextInt((int) maxNumberOfBranches - 2) + 2;
return ThreadLocalRandom.current().nextLong(2, maxNumberOfBranches); // return ThreadLocalRandom.current().nextLong(2, maxNumberOfBranches);
} }
private long randomWcet() { private long randomWcet() {
// return random.nextInt((int) (maximumWcet - minimumWcet)) + minimumWcet; return random.nextInt((int) (maximumWcet - minimumWcet)) + minimumWcet;
return ThreadLocalRandom.current().nextLong(minimumWcet, maximumWcet); // return ThreadLocalRandom.current().nextLong(minimumWcet, maximumWcet);
} }
/** /**
......
...@@ -108,12 +108,12 @@ public class DagUtils { ...@@ -108,12 +108,12 @@ public class DagUtils {
private static LinkedList<Job> getUnvisitedJoinNodes( private static LinkedList<Job> getUnvisitedJoinNodes(
final DirectedAcyclicGraph<Job, DefaultEdge> jobDag) { final DirectedAcyclicGraph<Job, DefaultEdge> jobDag, final Set<Job> visitedJobs) {
final LinkedList<Job> joinNodes = new LinkedList<>(); final LinkedList<Job> joinNodes = new LinkedList<>();
final ClosestFirstIterator<Job, DefaultEdge> it = new ClosestFirstIterator<>(jobDag); final ClosestFirstIterator<Job, DefaultEdge> it = new ClosestFirstIterator<>(jobDag);
for (; it.hasNext();) { for (; it.hasNext();) {
final Job j = it.next(); final Job j = it.next();
if (jobDag.inDegreeOf(j) > 1 && !j.getVisited()) { if (jobDag.inDegreeOf(j) > 1 && /* /* !j.getVisited() */!visitedJobs.contains(j)) {
joinNodes.add(j); joinNodes.add(j);
} }
} }
...@@ -131,24 +131,24 @@ public class DagUtils { ...@@ -131,24 +131,24 @@ public class DagUtils {
sink = j; sink = j;
} }
final Set<Job> visitedJobs = new HashSet<>();
while (true) { while (true) {
final LinkedList<Job> joins = getUnvisitedJoinNodes(modifiedJobDag); final LinkedList<Job> joins = getUnvisitedJoinNodes(modifiedJobDag, visitedJobs);
if (joins.isEmpty()) { if (joins.isEmpty()) {
break; break;
} }
final Job joinNode = joins.getFirst(); final Job joinNode = joins.getFirst();
visitedJobs.add(joinNode);
joinNode.setVisited(true); joinNode.setVisited(true);
final Set<Job> ancestorsOfJ = jobDag.getAncestors(modifiedJobDag, joinNode);
ancestorsOfJ.add(joinNode);
nextEdge: while (modifiedJobDag.inDegreeOf(joinNode) > 1) { nextEdge: while (modifiedJobDag.inDegreeOf(joinNode) > 1) {
final List<Job> predecessors = Graphs.predecessorListOf(modifiedJobDag, joinNode); final List<Job> predecessors = Graphs.predecessorListOf(modifiedJobDag, joinNode);
for (final Job p : predecessors) { for (final Job p : predecessors) {
if (modifiedJobDag.outDegreeOf(p) > 1 if (!checkPredecessors(modifiedJobDag, joinNode, p)) {
|| !checkPredecessors(modifiedJobDag, joinNode, ancestorsOfJ, p)) {
// || !checkPredecessors(modifiedJobDag, p, joinNode, ancestorsOfJ)) { // || !checkPredecessors(modifiedJobDag, p, joinNode, ancestorsOfJ)) {
// DefaultEdge e = modifiedJobDag.getEdge(p, joinNode); // DefaultEdge e = modifiedJobDag.getEdge(p, joinNode);
// if ((modifiedJobDag.outDegreeOf(p) > 1) // if ((modifiedJobDag.outDegreeOf(p) > 1)
// || checkForFork(modifiedJobDag, joinNode, ancestorsOfJ, e)) { // || checkForFork(modifiedJobDag, joinNode, e)) {
final DefaultEdge conflictingEdge = modifiedJobDag.getEdge(p, joinNode); final DefaultEdge conflictingEdge = modifiedJobDag.getEdge(p, joinNode);
modifiedJobDag.removeEdge(conflictingEdge); modifiedJobDag.removeEdge(conflictingEdge);
if (modifiedJobDag.outDegreeOf(p) == 0) { if (modifiedJobDag.outDegreeOf(p) == 0) {
...@@ -170,7 +170,7 @@ public class DagUtils { ...@@ -170,7 +170,7 @@ public class DagUtils {
} }
public static boolean checkForFork(final DirectedAcyclicGraph<Job, DefaultEdge> jobDag, public static boolean checkForFork(final DirectedAcyclicGraph<Job, DefaultEdge> jobDag,
final Job joinNode, Set<Job> ancestorsOfJ2, final DefaultEdge edge) { final Job joinNode, final DefaultEdge edge) {
Set<Job> ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode); Set<Job> ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode);
nextFork: for (final Job f : jobDag) { nextFork: for (final Job f : jobDag) {
...@@ -206,6 +206,7 @@ public class DagUtils { ...@@ -206,6 +206,7 @@ public class DagUtils {
final Job current, final Job joinNode, final Set<Job> ancestorsOfJ2) { final Job current, final Job joinNode, final Set<Job> ancestorsOfJ2) {
final List<Job> successorsOfCurrent = Graphs.successorListOf(jobDag, current); final List<Job> successorsOfCurrent = Graphs.successorListOf(jobDag, current);
final Set<Job> ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode); final Set<Job> ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode);
ancestorsOfJ.add(joinNode);
if (ancestorsOfJ.containsAll(successorsOfCurrent)) { if (ancestorsOfJ.containsAll(successorsOfCurrent)) {
final Set<Job> descendantsOfCurrent = jobDag.getDescendants(jobDag, current); final Set<Job> descendantsOfCurrent = jobDag.getDescendants(jobDag, current);
if (descendantsOfCurrent.containsAll(Graphs.predecessorListOf(jobDag, joinNode))) { if (descendantsOfCurrent.containsAll(Graphs.predecessorListOf(jobDag, joinNode))) {
...@@ -224,12 +225,14 @@ public class DagUtils { ...@@ -224,12 +225,14 @@ public class DagUtils {
} }
private static boolean checkPredecessors(final DirectedAcyclicGraph<Job, DefaultEdge> jobDag, private static boolean checkPredecessors(final DirectedAcyclicGraph<Job, DefaultEdge> jobDag,
final Job joinNode, final Set<Job> ancestorsOfJ2, Job current) { final Job joinNode, Job current) {
Set<Job> ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode); final Set<Job> ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode);
ancestorsOfJ.add(joinNode);
if (jobDag.outDegreeOf(current) > 1) { if (jobDag.outDegreeOf(current) > 1) {
if (!ancestorsOfJ.containsAll(Graphs.successorListOf(jobDag, current))) { if (!ancestorsOfJ.containsAll(Graphs.successorListOf(jobDag, current))) {
return false; return false;
} }
final Set<Job> descendantsOfCurrent = jobDag.getDescendants(jobDag, current); final Set<Job> descendantsOfCurrent = jobDag.getDescendants(jobDag, current);
if (descendantsOfCurrent.containsAll(Graphs.predecessorListOf(jobDag, joinNode))) { if (descendantsOfCurrent.containsAll(Graphs.predecessorListOf(jobDag, joinNode))) {
return true; return true;
...@@ -237,7 +240,7 @@ public class DagUtils { ...@@ -237,7 +240,7 @@ public class DagUtils {
} }
final List<Job> predecessorList = Graphs.predecessorListOf(jobDag, current); final List<Job> predecessorList = Graphs.predecessorListOf(jobDag, current);
for (Job p : predecessorList) { for (Job p : predecessorList) {
if (!checkPredecessors(jobDag, joinNode, ancestorsOfJ, p)) { if (!checkPredecessors(jobDag, joinNode, p)) {
return false; return false;
} }
} }
......
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