Algorithm for determining what order to perform a set of tasks in

311 Views Asked by At

Consider a set of $n$ items. Each item has a date $d$ by which it must be completed. Each item also has a priority level of $p$ and takes a time $t$ to complete. Is there an algorithm for determining in what order the set of items should be completed?

1

There are 1 best solutions below

0
On

I would suggest creating an ultimate weight for each task factoring d p and t, then executing the list according to weight (greatest to smallest). You could scale each value to a range, for example date from 0-100, priority 0-60, and t 0-30. Then add the values together for a total weight. An example implementation in java psuedocode:

class Task contains values:
 double d = 0-30 days due
 double p = 0-100 priority rating
 double t = 0-500 minutes to complete
 String n = task name

ArrayList<Task> tasks = new ArrayList<Task>(); // contains all tasks 

//if you assume an initial range of likely values
//for example 0-30 days (d) 0-100 (p) 0-500 minutes (t)
//use Irritate's algorithm to get a new range with method scale

//for each value:    

double dweight = scale(task.getD(),0,30,0,100);
double pweight = scale(task.getP(),0,100,0,60);
double tweight = scale(task.getT(),0,500,0,30);
double totalweight = dweight + pweight + tweight;

//now re-sort the arraylist based on totalweight.  TADA! 


//rescale code
public double scale(final double valueIn, final double baseMin, final double baseMax, final double limitMin, final double limitMax) {
    return ((limitMax - limitMin) * (valueIn - baseMin) / (baseMax - baseMin)) + limitMin;
}