From 471ee8c4459ec9d16593de07e65af78dae4cbaeb Mon Sep 17 00:00:00 2001 From: Michael Schmid Date: Tue, 2 Jun 2020 13:37:17 +0200 Subject: [PATCH] nfj creation does not work --- src/main/java/mvd/jester/model/SystemSetup.java | 26 +++++++++++++------------- src/main/java/mvd/jester/utils/DagUtils.java | 27 +++++++++++++++------------ 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/main/java/mvd/jester/model/SystemSetup.java b/src/main/java/mvd/jester/model/SystemSetup.java index 8774aef..d6e8308 100644 --- a/src/main/java/mvd/jester/model/SystemSetup.java +++ b/src/main/java/mvd/jester/model/SystemSetup.java @@ -222,8 +222,8 @@ public class SystemSetup { } private long randomProbability() { - // return random.nextInt(99) + 1; - return ThreadLocalRandom.current().nextLong(0, 100); + return random.nextInt(100); + // return ThreadLocalRandom.current().nextLong(0, 100); } public Set generateTaskSet(final double totalUtilization) { @@ -258,7 +258,7 @@ public class SystemSetup { final Job j = fork(jobDag, Optional.empty(), this.depth); fork(jobDag, Optional.of(j), this.depth); - // randomEdges(jobDag); // TODO: uncomment + randomEdges(jobDag); final long workload = DagUtils.calculateWorkload(jobDag); final long criticalPath = DagUtils.calculateCriticalPath(jobDag); @@ -297,7 +297,7 @@ public class SystemSetup { System.out.println("Adding fork edge failed!"); } } - if (depth >= 0 && randomProbability() <= p_par) { + if (depth >= 0 && randomProbability() < p_par) { final long numberOfJobs = randomNumberOfBranches(); for (int i = 0; i < numberOfJobs; ++i) { childs.add(fork(jobDag, Optional.of(job), depth - 1)); @@ -311,7 +311,7 @@ public class SystemSetup { final Multimap edgePairs = ArrayListMultimap.create(); for (final Job j1 : jobDag) { for (final Job j2 : jobDag) { - if (randomProbability() <= p_add) { + if (randomProbability() < p_add) { edgePairs.put(j1, j2); } } @@ -327,20 +327,20 @@ public class SystemSetup { } 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())); + 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); + 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); + return random.nextInt((int) (maximumWcet - minimumWcet)) + minimumWcet; + // return ThreadLocalRandom.current().nextLong(minimumWcet, maximumWcet); } /** diff --git a/src/main/java/mvd/jester/utils/DagUtils.java b/src/main/java/mvd/jester/utils/DagUtils.java index 247765a..0af8249 100644 --- a/src/main/java/mvd/jester/utils/DagUtils.java +++ b/src/main/java/mvd/jester/utils/DagUtils.java @@ -108,12 +108,12 @@ public class DagUtils { private static LinkedList getUnvisitedJoinNodes( - final DirectedAcyclicGraph jobDag) { + final DirectedAcyclicGraph jobDag, final Set visitedJobs) { final LinkedList joinNodes = new LinkedList<>(); final ClosestFirstIterator it = new ClosestFirstIterator<>(jobDag); for (; it.hasNext();) { 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); } } @@ -131,24 +131,24 @@ public class DagUtils { sink = j; } + final Set visitedJobs = new HashSet<>(); while (true) { - final LinkedList joins = getUnvisitedJoinNodes(modifiedJobDag); + final LinkedList joins = getUnvisitedJoinNodes(modifiedJobDag, visitedJobs); if (joins.isEmpty()) { break; } final Job joinNode = joins.getFirst(); + visitedJobs.add(joinNode); joinNode.setVisited(true); - final Set ancestorsOfJ = jobDag.getAncestors(modifiedJobDag, joinNode); - ancestorsOfJ.add(joinNode); + nextEdge: while (modifiedJobDag.inDegreeOf(joinNode) > 1) { final List predecessors = Graphs.predecessorListOf(modifiedJobDag, joinNode); for (final Job p : predecessors) { - if (modifiedJobDag.outDegreeOf(p) > 1 - || !checkPredecessors(modifiedJobDag, joinNode, ancestorsOfJ, p)) { + if (!checkPredecessors(modifiedJobDag, joinNode, p)) { // || !checkPredecessors(modifiedJobDag, p, joinNode, ancestorsOfJ)) { // DefaultEdge e = modifiedJobDag.getEdge(p, joinNode); // if ((modifiedJobDag.outDegreeOf(p) > 1) - // || checkForFork(modifiedJobDag, joinNode, ancestorsOfJ, e)) { + // || checkForFork(modifiedJobDag, joinNode, e)) { final DefaultEdge conflictingEdge = modifiedJobDag.getEdge(p, joinNode); modifiedJobDag.removeEdge(conflictingEdge); if (modifiedJobDag.outDegreeOf(p) == 0) { @@ -170,7 +170,7 @@ public class DagUtils { } public static boolean checkForFork(final DirectedAcyclicGraph jobDag, - final Job joinNode, Set ancestorsOfJ2, final DefaultEdge edge) { + final Job joinNode, final DefaultEdge edge) { Set ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode); nextFork: for (final Job f : jobDag) { @@ -206,6 +206,7 @@ public class DagUtils { final Job current, final Job joinNode, final Set ancestorsOfJ2) { final List successorsOfCurrent = Graphs.successorListOf(jobDag, current); final Set ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode); + ancestorsOfJ.add(joinNode); if (ancestorsOfJ.containsAll(successorsOfCurrent)) { final Set descendantsOfCurrent = jobDag.getDescendants(jobDag, current); if (descendantsOfCurrent.containsAll(Graphs.predecessorListOf(jobDag, joinNode))) { @@ -224,12 +225,14 @@ public class DagUtils { } private static boolean checkPredecessors(final DirectedAcyclicGraph jobDag, - final Job joinNode, final Set ancestorsOfJ2, Job current) { - Set ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode); + final Job joinNode, Job current) { + final Set ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode); + ancestorsOfJ.add(joinNode); if (jobDag.outDegreeOf(current) > 1) { if (!ancestorsOfJ.containsAll(Graphs.successorListOf(jobDag, current))) { return false; } + final Set descendantsOfCurrent = jobDag.getDescendants(jobDag, current); if (descendantsOfCurrent.containsAll(Graphs.predecessorListOf(jobDag, joinNode))) { return true; @@ -237,7 +240,7 @@ public class DagUtils { } final List predecessorList = Graphs.predecessorListOf(jobDag, current); for (Job p : predecessorList) { - if (!checkPredecessors(jobDag, joinNode, ancestorsOfJ, p)) { + if (!checkPredecessors(jobDag, joinNode, p)) { return false; } } -- libgit2 0.26.0