From cfdd32544053ea96258397aa1c003f234d544f8f Mon Sep 17 00:00:00 2001 From: Michael Schmid Date: Wed, 5 Aug 2020 14:23:26 +0200 Subject: [PATCH] Changes names --- src/main/java/mvd/jester/model/DagTask.java | 8 ++++---- src/main/java/mvd/jester/model/Job.java | 30 ------------------------------ src/main/java/mvd/jester/model/Subtask.java | 30 ++++++++++++++++++++++++++++++ src/main/java/mvd/jester/model/SubtaskContext.java | 32 ++++++++++++++++++++++++++++++++ src/main/java/mvd/jester/model/SystemManager.java | 34 +++++++++++++++++----------------- src/main/java/mvd/jester/model/TreeJob.java | 32 -------------------------------- src/main/java/mvd/jester/tests/FonsecaNelis.java | 46 +++++++++++++++++++++++----------------------- src/main/java/mvd/jester/utils/DagUtils.java | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------- src/test/java/mvd/jester/model/TestDagUtils.java | 74 +++++++++++++++++++++++++++++++++++++------------------------------------- src/test/java/mvd/jester/model/TestSystemSetup.java | 8 ++++---- 10 files changed, 248 insertions(+), 248 deletions(-) delete mode 100644 src/main/java/mvd/jester/model/Job.java create mode 100644 src/main/java/mvd/jester/model/Subtask.java create mode 100644 src/main/java/mvd/jester/model/SubtaskContext.java delete mode 100644 src/main/java/mvd/jester/model/TreeJob.java diff --git a/src/main/java/mvd/jester/model/DagTask.java b/src/main/java/mvd/jester/model/DagTask.java index 3c8163e..6ea5256 100644 --- a/src/main/java/mvd/jester/model/DagTask.java +++ b/src/main/java/mvd/jester/model/DagTask.java @@ -7,7 +7,7 @@ import mvd.jester.utils.DagUtils; public class DagTask implements Task { - private DirectedAcyclicGraph jobDag; + private DirectedAcyclicGraph jobDag; private final Set workloadDistribution; private final long workload; private final long criticalPath; @@ -15,7 +15,7 @@ public class DagTask implements Task { private final long deadline; private final long numberOfThreads; - public DagTask(final DirectedAcyclicGraph jobDag, final long period, + public DagTask(final DirectedAcyclicGraph jobDag, final long period, final long numberOfThreads) { this.jobDag = jobDag; this.period = period; @@ -41,14 +41,14 @@ public class DagTask implements Task { /** * @return the jobDag */ - public DirectedAcyclicGraph getJobDag() { + public DirectedAcyclicGraph getJobDag() { return jobDag; } /** * @param jobDag the jobDag to set */ - public void setJobDag(final DirectedAcyclicGraph jobDag) { + public void setJobDag(final DirectedAcyclicGraph jobDag) { this.jobDag = jobDag; } diff --git a/src/main/java/mvd/jester/model/Job.java b/src/main/java/mvd/jester/model/Job.java deleted file mode 100644 index 0ca9ed1..0000000 --- a/src/main/java/mvd/jester/model/Job.java +++ /dev/null @@ -1,30 +0,0 @@ -package mvd.jester.model; - -public class Job { - - private final long wcet; - private long relativeCompletionTime; - - public Job(long wcet) { - this.wcet = wcet; - this.relativeCompletionTime = wcet; - } - - public long getWcet() { - return wcet; - } - - /** - * @return the relativeCompletionTime - */ - public long getRelativeCompletionTime() { - return relativeCompletionTime; - } - - /** - * @param relativeCompletionTime the relativeCompletionTime to set - */ - public void setRelativeCompletionTime(long relativeCompletionTime) { - this.relativeCompletionTime = relativeCompletionTime; - } -} diff --git a/src/main/java/mvd/jester/model/Subtask.java b/src/main/java/mvd/jester/model/Subtask.java new file mode 100644 index 0000000..7e5ddc4 --- /dev/null +++ b/src/main/java/mvd/jester/model/Subtask.java @@ -0,0 +1,30 @@ +package mvd.jester.model; + +public class Subtask { + + private final long wcet; + private long relativeCompletionTime; + + public Subtask(long wcet) { + this.wcet = wcet; + this.relativeCompletionTime = wcet; + } + + public long getWcet() { + return wcet; + } + + /** + * @return the relativeCompletionTime + */ + public long getRelativeCompletionTime() { + return relativeCompletionTime; + } + + /** + * @param relativeCompletionTime the relativeCompletionTime to set + */ + public void setRelativeCompletionTime(long relativeCompletionTime) { + this.relativeCompletionTime = relativeCompletionTime; + } +} diff --git a/src/main/java/mvd/jester/model/SubtaskContext.java b/src/main/java/mvd/jester/model/SubtaskContext.java new file mode 100644 index 0000000..ecad98f --- /dev/null +++ b/src/main/java/mvd/jester/model/SubtaskContext.java @@ -0,0 +1,32 @@ +package mvd.jester.model; + +public class SubtaskContext { + private long wcet; + private final Subtask job; + + public SubtaskContext(final Subtask job) { + this.wcet = job.getWcet(); + this.job = job; + } + + /** + * @return the job + */ + public Subtask getJob() { + return job; + } + + /** + * @return the wcet + */ + public long getWcet() { + return wcet; + } + + /** + * @param wcet the wcet to set + */ + public void setWcet(final long wcet) { + this.wcet = wcet; + } +} diff --git a/src/main/java/mvd/jester/model/SystemManager.java b/src/main/java/mvd/jester/model/SystemManager.java index 97ba7d5..8e881f6 100644 --- a/src/main/java/mvd/jester/model/SystemManager.java +++ b/src/main/java/mvd/jester/model/SystemManager.java @@ -222,10 +222,10 @@ public class SystemManager { } public DagTask generateTask(double utilization) { - final DirectedAcyclicGraph jobDag = + final DirectedAcyclicGraph jobDag = new DirectedAcyclicGraph<>(DefaultEdge.class); - final Job j = fork(jobDag, Optional.empty(), this.depth); + final Subtask j = fork(jobDag, Optional.empty(), this.depth); fork(jobDag, Optional.of(j), this.depth); randomEdges(jobDag); @@ -237,10 +237,10 @@ public class SystemManager { } public DagTask generateTask() { - final DirectedAcyclicGraph jobDag = + final DirectedAcyclicGraph jobDag = new DirectedAcyclicGraph<>(DefaultEdge.class); - final Job j = fork(jobDag, Optional.empty(), this.depth); + final Subtask j = fork(jobDag, Optional.empty(), this.depth); fork(jobDag, Optional.of(j), this.depth); randomEdges(jobDag); @@ -252,12 +252,12 @@ public class SystemManager { return new DagTask(jobDag, period, numberOfProcessors); } - private Job join(final DirectedAcyclicGraph jobDag, final Job current, - final Set childs) { + private Subtask join(final DirectedAcyclicGraph jobDag, final Subtask current, + final Set childs) { if (childs.size() > 0) { - final Job job = new Job(randomWcet()); + final Subtask job = new Subtask(randomWcet()); jobDag.addVertex(job); - for (final Job c : childs) { + for (final Subtask c : childs) { try { jobDag.addDagEdge(c, job); } catch (final Exception e) { @@ -269,11 +269,11 @@ public class SystemManager { return current; } - private Job fork(final DirectedAcyclicGraph jobDag, - final Optional predecessor, final long depth) { - final Job job = new Job(randomWcet()); + private Subtask fork(final DirectedAcyclicGraph jobDag, + final Optional predecessor, final long depth) { + final Subtask job = new Subtask(randomWcet()); jobDag.addVertex(job); - final Set childs = new HashSet<>(); + final Set childs = new HashSet<>(); if (predecessor.isPresent()) { try { jobDag.addDagEdge(predecessor.get(), job); @@ -291,17 +291,17 @@ public class SystemManager { return join(jobDag, job, childs); } - private void randomEdges(final DirectedAcyclicGraph jobDag) { - final Multimap edgePairs = ArrayListMultimap.create(); - for (final Job j1 : jobDag) { - for (final Job j2 : jobDag) { + private void randomEdges(final DirectedAcyclicGraph jobDag) { + final Multimap edgePairs = ArrayListMultimap.create(); + for (final Subtask j1 : jobDag) { + for (final Subtask j2 : jobDag) { if (randomProbability() < p_add) { edgePairs.put(j1, j2); } } } - for (final Map.Entry pairs : edgePairs.entries()) { + for (final Map.Entry pairs : edgePairs.entries()) { try { jobDag.addDagEdge(pairs.getKey(), pairs.getValue()); } catch (final Exception e) { diff --git a/src/main/java/mvd/jester/model/TreeJob.java b/src/main/java/mvd/jester/model/TreeJob.java deleted file mode 100644 index 2c7d97a..0000000 --- a/src/main/java/mvd/jester/model/TreeJob.java +++ /dev/null @@ -1,32 +0,0 @@ -package mvd.jester.model; - -public class TreeJob { - private long wcet; - private final Job job; - - public TreeJob(final Job job) { - this.wcet = job.getWcet(); - this.job = job; - } - - /** - * @return the job - */ - public Job getJob() { - return job; - } - - /** - * @return the wcet - */ - public long getWcet() { - return wcet; - } - - /** - * @param wcet the wcet to set - */ - public void setWcet(final long wcet) { - this.wcet = wcet; - } -} diff --git a/src/main/java/mvd/jester/tests/FonsecaNelis.java b/src/main/java/mvd/jester/tests/FonsecaNelis.java index f575783..55990b9 100644 --- a/src/main/java/mvd/jester/tests/FonsecaNelis.java +++ b/src/main/java/mvd/jester/tests/FonsecaNelis.java @@ -18,12 +18,12 @@ import org.jgrapht.graph.DefaultEdge; import mvd.jester.info.SchedulingInfo; import mvd.jester.info.TerminationInfo; import mvd.jester.model.DagTask; -import mvd.jester.model.Job; +import mvd.jester.model.Subtask; import mvd.jester.model.Segment; import mvd.jester.model.SortedTaskSet; import mvd.jester.model.SystemManager; import mvd.jester.model.Task; -import mvd.jester.model.TreeJob; +import mvd.jester.model.SubtaskContext; import mvd.jester.utils.DagUtils; import mvd.jester.priority.PriorityManager; import mvd.jester.priority.RateMonotonic; @@ -64,32 +64,32 @@ public class FonsecaNelis extends AbstractTest { private void createNFJandDecompositionTree(final SortedTaskSet tasks) { for (final DagTask t : tasks) { - final DirectedAcyclicGraph jobDag = t.getJobDag(); + final DirectedAcyclicGraph jobDag = t.getJobDag(); - final DirectedAcyclicGraph nfjJobDag = + final DirectedAcyclicGraph nfjJobDag = DagUtils.createNFJGraph(jobDag); - final BinaryDecompositionTree tree = DagUtils.createDecompositionTree(nfjJobDag); + final BinaryDecompositionTree tree = DagUtils.createDecompositionTree(nfjJobDag); carryOutSegments.put(t, constructCarryOutDistribution(nfjJobDag, tree)); } } private Set constructCarryOutDistribution( - final DirectedAcyclicGraph nfjDag, - final BinaryDecompositionTree tree) { + final DirectedAcyclicGraph nfjDag, + final BinaryDecompositionTree tree) { // List statt Set final Set carryOutWorkload = new LinkedHashSet<>(); - final BinaryDecompositionTree modifiedTree = transformTree(tree); + final BinaryDecompositionTree modifiedTree = transformTree(tree); boolean isEmpty = false; do { - final Set parallelJobs = getMaximumParallelism(modifiedTree.getRootNode()); - final Optional min = + final Set parallelJobs = getMaximumParallelism(modifiedTree.getRootNode()); + final Optional min = parallelJobs.stream().min((p1, p2) -> Long.compare(p1.getWcet(), p2.getWcet())); if (min.isPresent()) { final long width = min.get().getWcet(); carryOutWorkload.add(new Segment(width, parallelJobs.size())); - for (final TreeJob p : parallelJobs) { + for (final SubtaskContext p : parallelJobs) { p.setWcet(p.getWcet() - width); } } else { @@ -102,34 +102,34 @@ public class FonsecaNelis extends AbstractTest { } - private BinaryDecompositionTree transformTree( - final BinaryDecompositionTree tree) { - final BinaryDecompositionTree modifiedTree = new BinaryDecompositionTree<>(); - final Node root = transformNode(null, tree.getRootNode()); + private BinaryDecompositionTree transformTree( + final BinaryDecompositionTree tree) { + final BinaryDecompositionTree modifiedTree = new BinaryDecompositionTree<>(); + final Node root = transformNode(null, tree.getRootNode()); modifiedTree.setRoot(root); return modifiedTree; } - private Node transformNode(final Node parent, final Node node) { + private Node transformNode(final Node parent, final Node node) { if (node.getNodeType().equals(NodeType.LEAF)) { - return new Node(parent, new TreeJob(node.getObject())); + return new Node(parent, new SubtaskContext(node.getObject())); } else { - final Node modifiedNode = new Node(parent, node.getNodeType()); + final Node modifiedNode = new Node(parent, node.getNodeType()); modifiedNode.setLeftNode(transformNode(modifiedNode, node.getLeftNode())); modifiedNode.setRightNode(transformNode(modifiedNode, node.getRightNode())); return modifiedNode; } } - private Set getMaximumParallelism(final Node node) { + private Set getMaximumParallelism(final Node node) { final NodeType nodeType = node.getNodeType(); if (nodeType.equals(NodeType.PAR)) { - final Set left = getMaximumParallelism(node.getLeftNode()); - final Set right = getMaximumParallelism(node.getRightNode()); + final Set left = getMaximumParallelism(node.getLeftNode()); + final Set right = getMaximumParallelism(node.getRightNode()); return Sets.union(left, right); } else if (nodeType.equals(NodeType.SEQ)) { - final Set left = getMaximumParallelism(node.getLeftNode()); - final Set right = getMaximumParallelism(node.getRightNode()); + final Set left = getMaximumParallelism(node.getLeftNode()); + final Set right = getMaximumParallelism(node.getRightNode()); if (left.size() >= right.size()) { return left; } else { diff --git a/src/main/java/mvd/jester/utils/DagUtils.java b/src/main/java/mvd/jester/utils/DagUtils.java index c99a8f9..ae4f09d 100644 --- a/src/main/java/mvd/jester/utils/DagUtils.java +++ b/src/main/java/mvd/jester/utils/DagUtils.java @@ -14,29 +14,29 @@ import org.jgrapht.Graphs; import org.jgrapht.experimental.dag.DirectedAcyclicGraph; import org.jgrapht.graph.DefaultEdge; import org.jgrapht.traverse.TopologicalOrderIterator; -import mvd.jester.model.Job; +import mvd.jester.model.Subtask; import mvd.jester.model.Segment; import mvd.jester.utils.BinaryDecompositionTree.Node; import mvd.jester.utils.BinaryDecompositionTree.NodeType; public class DagUtils { - public static long calculateWorkload(final DirectedAcyclicGraph jobDag) { + public static long calculateWorkload(final DirectedAcyclicGraph jobDag) { long workload = 0; - for (final Job job : jobDag) { + for (final Subtask job : jobDag) { workload += job.getWcet(); } return workload; } - public static long calculateCriticalPath(final DirectedAcyclicGraph jobDag) { + public static long calculateCriticalPath(final DirectedAcyclicGraph jobDag) { long criticalPath = 0; - for (final Job job : jobDag) { + for (final Subtask job : jobDag) { final Set edges = jobDag.incomingEdgesOf(job); long longestRelativeCompletionTime = 0; for (final DefaultEdge e : edges) { - final Job source = jobDag.getEdgeSource(e); + final Subtask source = jobDag.getEdgeSource(e); longestRelativeCompletionTime = longestRelativeCompletionTime >= source.getRelativeCompletionTime() ? longestRelativeCompletionTime @@ -51,13 +51,13 @@ public class DagUtils { } public static LinkedHashSet calculateWorkloadDistribution( - final DirectedAcyclicGraph jobDag, final long criticalPath) { + final DirectedAcyclicGraph jobDag, final long criticalPath) { final LinkedHashSet segments = new LinkedHashSet<>(); long segmentDuration = 0; long segmentHeight = 1; for (long t = 0; t < criticalPath; ++t) { long currentHeight = 0; - for (final Job j : jobDag) { + for (final Subtask j : jobDag) { if (t >= j.getRelativeCompletionTime() - j.getWcet() && t < j.getRelativeCompletionTime()) { currentHeight++; @@ -85,12 +85,12 @@ public class DagUtils { // return createNFJGraph(jobDag, forkNodes, joinNodes); // } - public static void collectForksAndJoins(final DirectedAcyclicGraph jobDag, - final LinkedList forkNodes, final LinkedList joinNodes) { + public static void collectForksAndJoins(final DirectedAcyclicGraph jobDag, + final LinkedList forkNodes, final LinkedList joinNodes) { // final ClosestFirstIterator it = new ClosestFirstIterator<>(jobDag); - Iterator it = jobDag.iterator(); + Iterator it = jobDag.iterator(); for (; it.hasNext();) { - final Job j = it.next(); + final Subtask j = it.next(); // for (final Job j : jobDag) { if (jobDag.inDegreeOf(j) > 1) { joinNodes.add(j); @@ -103,13 +103,13 @@ public class DagUtils { - private static LinkedList getUnvisitedJoinNodes( - final DirectedAcyclicGraph jobDag, final Set visitedJobs) { - final LinkedList joinNodes = new LinkedList<>(); - final TopologicalOrderIterator it = + private static LinkedList getUnvisitedJoinNodes( + final DirectedAcyclicGraph jobDag, final Set visitedJobs) { + final LinkedList joinNodes = new LinkedList<>(); + final TopologicalOrderIterator it = new TopologicalOrderIterator<>(jobDag); for (; it.hasNext();) { - final Job j = it.next(); + final Subtask j = it.next(); if (jobDag.inDegreeOf(j) > 1 && !visitedJobs.contains(j)) { joinNodes.add(j); } @@ -117,29 +117,29 @@ public class DagUtils { return joinNodes; } - public static DirectedAcyclicGraph createNFJGraph( - final DirectedAcyclicGraph jobDag) { - final DirectedAcyclicGraph modifiedJobDag = + public static DirectedAcyclicGraph createNFJGraph( + final DirectedAcyclicGraph jobDag) { + final DirectedAcyclicGraph modifiedJobDag = new DirectedAcyclicGraph<>(DefaultEdge.class); Graphs.addGraph(modifiedJobDag, jobDag); - Job sink = null; + Subtask sink = null; - for (final Job j : modifiedJobDag) { + for (final Subtask j : modifiedJobDag) { sink = j; } - final Set visitedJobs = new HashSet<>(); + final Set visitedJobs = new HashSet<>(); while (true) { - final LinkedList joins = getUnvisitedJoinNodes(modifiedJobDag, visitedJobs); + final LinkedList joins = getUnvisitedJoinNodes(modifiedJobDag, visitedJobs); if (joins.isEmpty()) { break; } - final Job joinNode = joins.getFirst(); + final Subtask joinNode = joins.getFirst(); visitedJobs.add(joinNode); nextEdge: while (modifiedJobDag.inDegreeOf(joinNode) > 1) { - final List predecessors = Graphs.predecessorListOf(modifiedJobDag, joinNode); - for (final Job p : predecessors) { + final List predecessors = Graphs.predecessorListOf(modifiedJobDag, joinNode); + for (final Subtask p : predecessors) { if (!checkPredecessors(modifiedJobDag, joinNode, p)) { final DefaultEdge conflictingEdge = modifiedJobDag.getEdge(p, joinNode); modifiedJobDag.removeEdge(conflictingEdge); @@ -161,22 +161,22 @@ public class DagUtils { } - private static boolean checkPredecessors(final DirectedAcyclicGraph jobDag, - final Job joinNode, Job current) { + private static boolean checkPredecessors(final DirectedAcyclicGraph jobDag, + final Subtask joinNode, Subtask current) { if (jobDag.outDegreeOf(current) > 1) { - final Set ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode); + final Set ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode); ancestorsOfJ.add(joinNode); if (!ancestorsOfJ.containsAll(Graphs.successorListOf(jobDag, current))) { return false; } - final Set descendantsOfCurrent = jobDag.getDescendants(jobDag, current); + final Set descendantsOfCurrent = jobDag.getDescendants(jobDag, current); if (descendantsOfCurrent.containsAll(Graphs.predecessorListOf(jobDag, joinNode))) { return true; } } - final List predecessorList = Graphs.predecessorListOf(jobDag, current); - for (Job p : predecessorList) { + final List predecessorList = Graphs.predecessorListOf(jobDag, current); + for (Subtask p : predecessorList) { if (!checkPredecessors(jobDag, joinNode, p)) { return false; } @@ -184,23 +184,23 @@ public class DagUtils { return true; } - public static BinaryDecompositionTree createDecompositionTree( - final DirectedAcyclicGraph jobDag) { - final LinkedList joinNodes = new LinkedList<>(); - final LinkedList forkNodes = new LinkedList<>(); + public static BinaryDecompositionTree createDecompositionTree( + final DirectedAcyclicGraph jobDag) { + final LinkedList joinNodes = new LinkedList<>(); + final LinkedList forkNodes = new LinkedList<>(); collectForksAndJoins(jobDag, forkNodes, joinNodes); return createDecompositionTree(jobDag, forkNodes, joinNodes); } - public static BinaryDecompositionTree createDecompositionTree( - final DirectedAcyclicGraph jobDag, final LinkedList forkNodes, - final LinkedList joinNodes) { - final BinaryDecompositionTree tree = new BinaryDecompositionTree<>(); - Optional source = Optional.empty(); - Optional sink = Optional.empty(); + public static BinaryDecompositionTree createDecompositionTree( + final DirectedAcyclicGraph jobDag, final LinkedList forkNodes, + final LinkedList joinNodes) { + final BinaryDecompositionTree tree = new BinaryDecompositionTree<>(); + Optional source = Optional.empty(); + Optional sink = Optional.empty(); boolean firstRun = true; - for (final Job j : jobDag) { + for (final Subtask j : jobDag) { if (firstRun) { firstRun = false; source = Optional.of(j); @@ -209,7 +209,7 @@ public class DagUtils { } if (source.isPresent() && sink.isPresent()) { - final Job current = source.get(); + final Subtask current = source.get(); DagUtils.constructTree(jobDag, null, current, tree, forkNodes, joinNodes, sink.get()); } @@ -217,42 +217,42 @@ public class DagUtils { return tree; } - private static Node constructTree(final DirectedAcyclicGraph jobDag, - final Node parentNode, final Job currentJob, - final BinaryDecompositionTree tree, final LinkedList forkVertices, - final LinkedList joinVertices, final Job sinkJob) { + private static Node constructTree(final DirectedAcyclicGraph jobDag, + final Node parentNode, final Subtask currentJob, + final BinaryDecompositionTree tree, final LinkedList forkVertices, + final LinkedList joinVertices, final Subtask sinkJob) { if (forkVertices.contains(currentJob)) { - final Job forkJob = currentJob; - final Job joinJob = findJoin(jobDag, forkJob, sinkJob, joinVertices); + final Subtask forkJob = currentJob; + final Subtask joinJob = findJoin(jobDag, forkJob, sinkJob, joinVertices); - final Node seqForkNode = new Node(parentNode, NodeType.SEQ); - seqForkNode.setLeftNode(new Node(seqForkNode, forkJob)); + final Node seqForkNode = new Node(parentNode, NodeType.SEQ); + seqForkNode.setLeftNode(new Node(seqForkNode, forkJob)); if (tree.isEmpty()) { tree.setRoot(seqForkNode); } - final Node parContinuationNode; + final Node parContinuationNode; if (!tree.contains(joinJob)) { - final Node seqJoinNode = - seqForkNode.setRightNode(new Node(seqForkNode, NodeType.SEQ)); + final Node seqJoinNode = + seqForkNode.setRightNode(new Node(seqForkNode, NodeType.SEQ)); - final Node subTreeOfJoin = constructTree(jobDag, seqJoinNode, joinJob, tree, + final Node subTreeOfJoin = constructTree(jobDag, seqJoinNode, joinJob, tree, forkVertices, joinVertices, sinkJob); seqJoinNode.setRightNode(subTreeOfJoin); parContinuationNode = - seqJoinNode.setLeftNode(new Node(seqJoinNode, NodeType.PAR)); + seqJoinNode.setLeftNode(new Node(seqJoinNode, NodeType.PAR)); } else { parContinuationNode = - seqForkNode.setRightNode(new Node(seqForkNode, NodeType.PAR)); + seqForkNode.setRightNode(new Node(seqForkNode, NodeType.PAR)); } - Node successorParent = parContinuationNode; - final List successors = Graphs.successorListOf(jobDag, currentJob); + Node successorParent = parContinuationNode; + final List successors = Graphs.successorListOf(jobDag, currentJob); // create leftSide of joinNode for (int i = 0; i < successors.size(); ++i) { - final Job succ = successors.get(i); - final Node thisNode = constructTree(jobDag, successorParent, succ, tree, + final Subtask succ = successors.get(i); + final Node thisNode = constructTree(jobDag, successorParent, succ, tree, forkVertices, joinVertices, sinkJob); if (i == successors.size() - 1) { successorParent.setRightNode(thisNode); @@ -267,22 +267,22 @@ public class DagUtils { return seqForkNode; } else { - final List successorList = Graphs.successorListOf(jobDag, currentJob); + final List successorList = Graphs.successorListOf(jobDag, currentJob); if (successorList.size() > 0) { - final Job successor = successorList.get(0); + final Subtask successor = successorList.get(0); if (!tree.contains(successor)) { - final Node seqJobNode = new Node(parentNode, NodeType.SEQ); + final Node seqJobNode = new Node(parentNode, NodeType.SEQ); if (tree.isEmpty()) { tree.setRoot(seqJobNode); } - seqJobNode.setLeftNode(new Node(seqJobNode, currentJob)); - final Node contNode = constructTree(jobDag, seqJobNode, successor, tree, + seqJobNode.setLeftNode(new Node(seqJobNode, currentJob)); + final Node contNode = constructTree(jobDag, seqJobNode, successor, tree, forkVertices, joinVertices, sinkJob); seqJobNode.setRightNode(contNode); return seqJobNode; } } - final Node jobNode = new Node(parentNode, currentJob); + final Node jobNode = new Node(parentNode, currentJob); if (tree.isEmpty()) { tree.setRoot(jobNode); } @@ -292,20 +292,20 @@ public class DagUtils { - private static Job findJoin(final DirectedAcyclicGraph jobDag, - final Job forkNode, final Job sink, final List joinNodes) { - for (final Job j : joinNodes) { - final Set ancestorsOfJ = jobDag.getAncestors(jobDag, j); - final Set ancestorsOfFork = jobDag.getAncestors(jobDag, forkNode); + private static Subtask findJoin(final DirectedAcyclicGraph jobDag, + final Subtask forkNode, final Subtask sink, final List joinNodes) { + for (final Subtask j : joinNodes) { + final Set ancestorsOfJ = jobDag.getAncestors(jobDag, j); + final Set ancestorsOfFork = jobDag.getAncestors(jobDag, forkNode); ancestorsOfFork.add(forkNode); - final Set inbetweenJobs = new HashSet<>(ancestorsOfJ); + final Set inbetweenJobs = new HashSet<>(ancestorsOfJ); inbetweenJobs.removeAll(ancestorsOfFork); inbetweenJobs.add(j); if (inbetweenJobs.isEmpty()) { continue; } - final List successorOfFork = Graphs.successorListOf(jobDag, forkNode); + final List successorOfFork = Graphs.successorListOf(jobDag, forkNode); if (inbetweenJobs.containsAll(successorOfFork)) { return j; @@ -316,9 +316,9 @@ public class DagUtils { } - public static boolean checkNFJProperty(final DirectedAcyclicGraph jobDag) { - final LinkedList joinNodes = new LinkedList<>(); - final LinkedList forkNodes = new LinkedList<>(); + public static boolean checkNFJProperty(final DirectedAcyclicGraph jobDag) { + final LinkedList joinNodes = new LinkedList<>(); + final LinkedList forkNodes = new LinkedList<>(); collectForksAndJoins(jobDag, forkNodes, joinNodes); @@ -326,19 +326,19 @@ public class DagUtils { return true; } - nextJoin: for (final Job j : joinNodes) { - nextFork: for (final Job f : forkNodes) { - final Set ancestorsOfJ = jobDag.getAncestors(jobDag, j); - final Set descendantsOfF = jobDag.getDescendants(jobDag, f); - final Set inbetweenJobs = new HashSet<>(ancestorsOfJ); + nextJoin: for (final Subtask j : joinNodes) { + nextFork: for (final Subtask f : forkNodes) { + final Set ancestorsOfJ = jobDag.getAncestors(jobDag, j); + final Set descendantsOfF = jobDag.getDescendants(jobDag, f); + final Set inbetweenJobs = new HashSet<>(ancestorsOfJ); inbetweenJobs.retainAll(descendantsOfF); if (inbetweenJobs.isEmpty()) { continue; } - for (final Job a : inbetweenJobs) { - final List neighboursOfA = Graphs.neighborListOf(jobDag, a); - for (final Job b : neighboursOfA) { + for (final Subtask a : inbetweenJobs) { + final List neighboursOfA = Graphs.neighborListOf(jobDag, a); + for (final Subtask b : neighboursOfA) { if ((jobDag.getAncestors(jobDag, j).contains(b) || b == j) && (jobDag.getDescendants(jobDag, f).contains(b) || b == f)) { // this b is ok @@ -355,9 +355,9 @@ public class DagUtils { return true; } - public static DirectedAcyclicGraph createNFJfromDecompositionTree( - final BinaryDecompositionTree tree) { - final DirectedAcyclicGraph jobDag = + public static DirectedAcyclicGraph createNFJfromDecompositionTree( + final BinaryDecompositionTree tree) { + final DirectedAcyclicGraph jobDag = new DirectedAcyclicGraph<>(DefaultEdge.class); if (tree.getRootNode() != null) { @@ -368,20 +368,20 @@ public class DagUtils { } - private static GraphEndPoints traverseNodes(final DirectedAcyclicGraph jobDag, - final Node node) { + private static GraphEndPoints traverseNodes(final DirectedAcyclicGraph jobDag, + final Node node) { switch (node.getNodeType()) { case LEAF: { - final Job j = node.getObject(); + final Subtask j = node.getObject(); jobDag.addVertex(j); - final Set endPoints = new HashSet(Arrays.asList(j)); + final Set endPoints = new HashSet(Arrays.asList(j)); return new GraphEndPoints(endPoints, endPoints); } case SEQ: { final GraphEndPoints leftEndPoints = traverseNodes(jobDag, node.getLeftNode()); final GraphEndPoints rightEndPoints = traverseNodes(jobDag, node.getRightNode()); - for (final Job l : leftEndPoints.right) { - for (final Job r : rightEndPoints.left) { + for (final Subtask l : leftEndPoints.right) { + for (final Subtask r : rightEndPoints.left) { if (r == l) { continue; } @@ -397,9 +397,9 @@ public class DagUtils { case PAR: { final GraphEndPoints leftEndPoints = traverseNodes(jobDag, node.getLeftNode()); final GraphEndPoints rightEndPoints = traverseNodes(jobDag, node.getRightNode()); - final Set leftEndPointJobs = + final Set leftEndPointJobs = Sets.newHashSet(Iterables.concat(leftEndPoints.left, rightEndPoints.left)); - final Set rightEndPointJobs = Sets + final Set rightEndPointJobs = Sets .newHashSet(Iterables.concat(leftEndPoints.right, rightEndPoints.right)); return new GraphEndPoints(leftEndPointJobs, rightEndPointJobs); } @@ -410,10 +410,10 @@ public class DagUtils { } public static class GraphEndPoints { - public Set left; - public Set right; + public Set left; + public Set right; - public GraphEndPoints(final Set left, final Set right) { + public GraphEndPoints(final Set left, final Set right) { this.left = left; this.right = right; } diff --git a/src/test/java/mvd/jester/model/TestDagUtils.java b/src/test/java/mvd/jester/model/TestDagUtils.java index bbf3de6..6c1eba9 100644 --- a/src/test/java/mvd/jester/model/TestDagUtils.java +++ b/src/test/java/mvd/jester/model/TestDagUtils.java @@ -16,15 +16,15 @@ public class TestDagUtils { @Test @DisplayName("Test if dynamic segments are constructed correctly.") public void checkPathLength() { - DirectedAcyclicGraph jobDag = createJobDag(); + DirectedAcyclicGraph jobDag = createJobDag(); long criticalPath = DagUtils.calculateCriticalPath(jobDag); - for (Job j : jobDag) { + for (Subtask j : jobDag) { assertTrue(j.getRelativeCompletionTime() <= criticalPath); } for (DefaultEdge e : jobDag.edgeSet()) { - Job source = jobDag.getEdgeSource(e); - Job target = jobDag.getEdgeTarget(e); + Subtask source = jobDag.getEdgeSource(e); + Subtask target = jobDag.getEdgeTarget(e); assertTrue(source.getRelativeCompletionTime() < target.getRelativeCompletionTime()); } @@ -39,7 +39,7 @@ public class TestDagUtils { DagTaskBuilder b = new DagTaskBuilder(); DagTask t = b.generateTask(); - DirectedAcyclicGraph nfjDag = DagUtils.createNFJGraph(t.getJobDag()); + DirectedAcyclicGraph nfjDag = DagUtils.createNFJGraph(t.getJobDag()); assertTrue(DagUtils.checkNFJProperty(nfjDag)); } @@ -53,11 +53,11 @@ public class TestDagUtils { long numberOfProcessors = ThreadLocalRandom.current().nextLong(4, 16); DagTaskBuilder b = new DagTaskBuilder().setNumberOfProcessors(numberOfProcessors); DagTask t = b.generateTask(); - DirectedAcyclicGraph jobDag = t.getJobDag(); - DirectedAcyclicGraph nfjJobDag = DagUtils.createNFJGraph(jobDag); + DirectedAcyclicGraph jobDag = t.getJobDag(); + DirectedAcyclicGraph nfjJobDag = DagUtils.createNFJGraph(jobDag); - BinaryDecompositionTree tree = DagUtils.createDecompositionTree(nfjJobDag); - DirectedAcyclicGraph jobDagFromTree = + BinaryDecompositionTree tree = DagUtils.createDecompositionTree(nfjJobDag); + DirectedAcyclicGraph jobDagFromTree = DagUtils.createNFJfromDecompositionTree(tree); assertTrue(jobDag.vertexSet().size() == nfjJobDag.vertexSet().size()); @@ -65,14 +65,14 @@ public class TestDagUtils { assertTrue(jobDagFromTree.edgeSet().size() == nfjJobDag.edgeSet().size()); for (DefaultEdge e : nfjJobDag.edgeSet()) { - Job target = nfjJobDag.getEdgeTarget(e); - Job source = nfjJobDag.getEdgeSource(e); + Subtask target = nfjJobDag.getEdgeTarget(e); + Subtask source = nfjJobDag.getEdgeSource(e); assertTrue(jobDagFromTree.containsEdge(source, target)); } - for (Job j : nfjJobDag) { - for (Job n : nfjJobDag) { + for (Subtask j : nfjJobDag) { + for (Subtask n : nfjJobDag) { if (n == j) { continue; } @@ -83,19 +83,19 @@ public class TestDagUtils { assertTrue(nfjJobDag.inDegreeOf(j) == jobDagFromTree.inDegreeOf(j)); assertTrue(nfjJobDag.outDegreeOf(j) == jobDagFromTree.outDegreeOf(j)); - for (Job p : Graphs.predecessorListOf(nfjJobDag, j)) { + for (Subtask p : Graphs.predecessorListOf(nfjJobDag, j)) { assertTrue(Graphs.predecessorListOf(jobDagFromTree, j).contains(p)); } - for (Job s : Graphs.successorListOf(nfjJobDag, j)) { + for (Subtask s : Graphs.successorListOf(nfjJobDag, j)) { assertTrue(Graphs.successorListOf(jobDagFromTree, j).contains(s)); } - for (Job a : nfjJobDag.getAncestors(nfjJobDag, j)) { + for (Subtask a : nfjJobDag.getAncestors(nfjJobDag, j)) { assertTrue(jobDagFromTree.getAncestors(jobDagFromTree, j).contains(a)); } - for (Job d : nfjJobDag.getDescendants(nfjJobDag, j)) { + for (Subtask d : nfjJobDag.getDescendants(nfjJobDag, j)) { assertTrue(jobDagFromTree.getDescendants(jobDagFromTree, j).contains(d)); } } @@ -105,35 +105,35 @@ public class TestDagUtils { } - private DirectedAcyclicGraph createJobDag() { - DirectedAcyclicGraph jobDag = + private DirectedAcyclicGraph createJobDag() { + DirectedAcyclicGraph jobDag = new DirectedAcyclicGraph<>(DefaultEdge.class); - Job source = new Job(20); - Job pathA = new Job(10); - Job pathB = new Job(30); - Job pathC = new Job(40); + Subtask source = new Subtask(20); + Subtask pathA = new Subtask(10); + Subtask pathB = new Subtask(30); + Subtask pathC = new Subtask(40); - Job child1OfA = new Job(5); - Job child2OfA = new Job(15); - Job child3OfA = new Job(5); + Subtask child1OfA = new Subtask(5); + Subtask child2OfA = new Subtask(15); + Subtask child3OfA = new Subtask(5); - Job childsOfAJoin = new Job(10); + Subtask childsOfAJoin = new Subtask(10); - Job child1OfC = new Job(5); - Job child2OfC = new Job(10); - Job child3OfC = new Job(15); - Job child4OfC = new Job(20); + Subtask child1OfC = new Subtask(5); + Subtask child2OfC = new Subtask(10); + Subtask child3OfC = new Subtask(15); + Subtask child4OfC = new Subtask(20); - Job firstJoin = new Job(20); + Subtask firstJoin = new Subtask(20); - Job intermediateFork = new Job(10); + Subtask intermediateFork = new Subtask(10); - Job forkChild1 = new Job(5); - Job forkChild2 = new Job(10); - Job forkChild3 = new Job(15); + Subtask forkChild1 = new Subtask(5); + Subtask forkChild2 = new Subtask(10); + Subtask forkChild3 = new Subtask(15); - Job sink = new Job(30); + Subtask sink = new Subtask(30); try { jobDag.addVertex(source); jobDag.addVertex(pathA); diff --git a/src/test/java/mvd/jester/model/TestSystemSetup.java b/src/test/java/mvd/jester/model/TestSystemSetup.java index bffc2bb..ffa04aa 100644 --- a/src/test/java/mvd/jester/model/TestSystemSetup.java +++ b/src/test/java/mvd/jester/model/TestSystemSetup.java @@ -75,12 +75,12 @@ public class TestSystemSetup { for (int i = 0; i < 100; ++i) { DagTaskBuilder builder = new DagTaskBuilder(); DagTask task = builder.generateTask(); - DirectedAcyclicGraph jobDag = task.getJobDag(); + DirectedAcyclicGraph jobDag = task.getJobDag(); assertTrue(task.getCriticalPath() <= task.getPeriod()); assertTrue(task.getPeriod() <= (long) (task.getWorkload() / builder.getBeta())); - for (Job j : jobDag) { + for (Subtask j : jobDag) { assertTrue(1 <= j.getWcet() && j.getWcet() <= 100); assertTrue(j.getRelativeCompletionTime() <= task.getCriticalPath()); if (jobDag.outDegreeOf(j) == 0) { @@ -88,8 +88,8 @@ public class TestSystemSetup { } } for (DefaultEdge e : jobDag.edgeSet()) { - Job source = jobDag.getEdgeSource(e); - Job target = jobDag.getEdgeTarget(e); + Subtask source = jobDag.getEdgeSource(e); + Subtask target = jobDag.getEdgeTarget(e); assertTrue(source.getRelativeCompletionTime() < target.getRelativeCompletionTime()); } } -- libgit2 0.26.0