Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 7. (3 pts) Chapter 16-5: In the problem of unit length task scheduling w

ID: 3750661 • Letter: P

Question

Problem 7. (3 pts) Chapter 16-5: In the problem of unit length task scheduling with deadlines and penalties the input consists of .a set S a, a,.. an of n unit-time tasks (each takes one unit of time) . a set of n positive integerdendlines di such that task at must conclude by timed (ach di S n) . a set of n penalties w wn such that if task ai is not finished by deadline di we incur a penalty of wi (other we incur no penalties) and the output is a schedule for S that minimizes the total penalty incurred by all tasks for which we've missed the deadline. Since al tasks take a unit of time, such a scheduling is given in the form of a permutation of the elements of S: we first run task ar(1) for one unit of time until it concludes, then run task ar/(2) for one unit of time till it concludes, and so on and so forth. Under this scheduling, task AT(1) concludes at time one, task an(2) concludes at time 2, and in general, ar(i) concludes at time Prove that the algorithm that greedily finds the maximum-cost set of tasks we can schedule without incurring any penalty (and then builds a suitable schedule) indeed solves this problem, by identifying the underlying matroid structure of the problem. (Prove this is indeed a matroid.)

Explanation / Answer

If selected, activity i takes place during the half-open time
interval (si, fi).


We have the SET of jobs where every job has a deadline and associated profit
if the job is finished before the deadline. It is also given that every job takes single unit of time,
so the minimum possible deadline for any job is 1.


First we generate all subsets of set of jobs and check individual subset for feasibility of job
in
subset
Programme:

public class JobSeqFast
{
private
static class Item implements Comparable
{
private int profit; ivate int deadlin
private deadline;
private String name;
public Item(int p, int d, String n)
{
profit= p;
deadline= d;
name= n;
}
public int compareTo(Object o)
{
Item other = (Item) o;
if (profit > other.profit)
return -1;
else if (profit < other.profit)
return 1;
else
return 0;
}
}

public static int[] findjob(Item[] jobs, int b)
{
int n= jobs.length;
int[] j= new int[n];
Set jobSet=new Set(b);
  
int[] f = new int[b];
for (int i = 0; i < b; i++)
f[i] = i;
for (int i = 1; i < n; i++)
{
int q = jobSet.collapsingFind(Math.min(n, jobs[i].deadline));
if (f[q] != 0)
{
jjq[q] = i; / int m = jobSet.collapsingFind(f[q] -1);
jobSet.weightedUnion(m, q);
f[q] = f[m];
}
}
return j;
}


public static void main(String args[])
{
Item sentinel= new Item(0, 0,”s”);
Item a = new Item(100, 2, “a”); /
Item[] jobs = { sentinel, a, b, c, d, e };
Arrays sort(jobs 1 jobs length-1);

Arrays.jobs, 1, jobs.int maxD= -1;

if (i.deadline > maxD)

maxD= i.deadline;
maxD++;

int bb= Math.min(maxD, jobs.length);

int[] j= findjob(jobs, bb);

System.out.println("Jobs done:");
for (int i= 1; i < maxD; i++)
{
if (j[i]>0)
{
System.out.println(" Job "+ jobs[j[i]].name + " at time "+ i);
}
}
}
}