Commit 9bc57289 authored by Nils Vreman's avatar Nils Vreman
Browse files

Added DMS and fixed RMS

parent 2be60a65
......@@ -3,13 +3,14 @@
## TODO
1. Write "Help" documentation
2. Change save to include model
3. Fix RMS. Does not work with taskset in exc 6.4
3. Fix QueueStrategy to avoid coupled code (duplicate in all sub-strategies)
## FIXED
1. Fix issue with taskset not arranging correctly when tasks are added before scheduling algorithm is choosen. *FIXED*
2. Fix Strategy-based priority assignment *FIXED*
3. Make space between buttons on left and the taskset-list. *FIXED*
1. EDF IS STILL WRONG :( Take into consideration distance to deadline, not just deadline size. *FIXED*
3. Added DMS and fixed RMS *FIXED*
## SUGGESTIONS
*- Add Task, Change Task, Remove Task på samma rad*
......
package gui.menu;
import model.SchedulingModel;
import strategy.DMS;
public class DMSStrategyMenuItem extends StrategyMenuItem {
public DMSStrategyMenuItem(SchedulingModel scheduleMdl) {
super(scheduleMdl, new DMS(), "DMS");
}
}
......@@ -29,6 +29,7 @@ public class ScheduLearnMenuBar extends JMenuBar {
strategy.add(new FPStrategyMenuItem(scheduleMdl));
strategy.add(new EDFStrategyMenuItem(scheduleMdl));
strategy.add(new RMSStrategyMenuItem(scheduleMdl));
strategy.add(new DMSStrategyMenuItem(scheduleMdl));
add(file);
add(edit);
......
package strategy;
import tasks.Taskset;
import tasks.Task;
import java.util.Comparator;
import java.util.Queue;
import java.util.PriorityQueue;
import java.util.Map;
import java.util.HashMap;
/*
* class DMS extends QueueStrategy
*
* A Deadline monotonic scheduling class
*/
public class DMS extends QueueStrategy {
/*
* Return: Current version of the ready queue according to the DMS strategy
*/
protected Queue<Integer> updateQueue(Queue<Integer> q, Taskset ts, int time) {
// Lambda creation of complex comparator down below
// compares deadline first and then priority
Comparator<Integer> order =
(Integer i1, Integer i2) -> {
int res = ts.getTask(i1).get().deadline() - ts.getTask(i2).get().deadline();
if ( res == 0 ) return i1 - i2;
else return res;
};
// Create new Q that uses order comparator and move all current tasks to that Q
Queue<Integer> internalQ = new PriorityQueue<>(order);
while (q.size() != 0) internalQ.add(q.poll());
//If we are at a job release, add that much CPU usage to the Q.
for (int taskNbr : ts.getPriorities()) {
Task t = ts.getTask(taskNbr).get(); //I know it exists so I can collect it from the optional directly
if (time % t.period() == 0) {
for (int i = 0; i < t.exectime(); i++) {
internalQ.add(taskNbr);
}
}
}
return internalQ;
}
/*
* Return which Strategy you are using
*/
public String toString() {
return "DMS";
}
/*
* Return a Comparator for this scheduling strategy
*/
public Comparator<Task> prioComparator() {
return new DMSComparator();
}
}
package strategy;
import tasks.Task;
/*
* class DMSComparator implements PriorityComparator:
*
* A comparator class for the Deadline Monotonic Scheduling
*/
public class DMSComparator implements PriorityComparator {
/*
* Method compare:
* compares two tasks according to scheduling algorithm.
*
* @param:
* o1 (Object): first object
* o2 (Object): second object
* @return:
* int: comparator output
*/
public int compare(Object o1, Object o2) {
Task t1 = (Task) o1;
Task t2 = (Task) o2;
if (t1.deadline() == t2.deadline()) {
return t1.period() - t2.period();
}
return t1.deadline() - t2.deadline();
}
}
......@@ -16,10 +16,14 @@ public class RMS extends QueueStrategy {
*/
protected Queue<Integer> updateQueue(Queue<Integer> q, Taskset ts, int time) {
//Create new Q that uses order comparator and move all current tasks to that Q
//Compares period first and then priority
Comparator<Integer> order =
(Integer i1, Integer i2)->
ts.getTask(i1).get().period() - time % ts.getTask(i1).get().period() -
(ts.getTask(i2).get().period() - time % ts.getTask(i2).get().period());
(Integer i1, Integer i2)->{
int res = ts.getTask(i1).get().period() - ts.getTask(i2).get().period();
if (res == 0) return i1 - i2;
else return res;
};
//NOTE: ADD PRIORITY COMPARISON //
Queue<Integer> internalQ = new PriorityQueue<>(order);
while (q.size() != 0) internalQ.add(q.poll());
......
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 to comment