Question

Given the following jobs to schedule (already ordered): job numberstart time finish timevalue 6 10 2 6 4 8 6 What will the Pü
0 0
Add a comment Improve this question Transcribed image text
Answer #1
1) First sort jobs according to finish time.
2) Now apply following recursive process. 
   // Here arr[] is array of n jobs
   findMaximumProfit(arr[], n)
   {
     a) if (n == 1) return arr[0];
     b) Return the maximum of following two profits.
         (i) Maximum profit by excluding current job, i.e., 
             findMaximumProfit(arr, n-1)
         (ii) Maximum profit by including the current job            
   }

How to find the profit including current job?
The idea is to find the latest job before the current job (in 
sorted array) that doesn't conflict with current job 'arr[n-1]'. 
Once we find such a job, we recur for all jobs till that job and
add profit of current job to result.

#include <iostream>
#include <algorithm>
using namespace std;

// A job has start time, finish time and profit.
struct Job
{
    int start, finish, profit;
};

// A utility function that is used for sorting events
// according to finish time
bool jobComparataor(Job s1, Job s2)
{
    return (s1.finish < s2.finish);
}

// Find the latest job (in sorted array) that doesn't
// conflict with the job[i]
int latestNonConflict(Job arr[], int i)
{
    for (int j=i-1; j>=0; j--)
    {
        if (arr[j].finish <= arr[i].start)
            return j;
    }
    return -1;
}

// A recursive function that returns the maximum possible
// profit from given array of jobs. The array of jobs must
// be sorted according to finish time.
int findMaxProfitRec(Job arr[], int n)
{
    // Base case
    if (n == 1) return arr[n-1].profit;

    // Find profit when current job is inclueded
    int inclProf = arr[n-1].profit;
    int i = latestNonConflict(arr, n);
    if (i != -1)
      inclProf += findMaxProfitRec(arr, i+1);

    // Find profit when current job is excluded
    int exclProf = findMaxProfitRec(arr, n-1);

    return max(inclProf, exclProf);
}

// The main function that returns the maximum possible
// profit from given array of jobs
int findMaxProfit(Job arr[], int n)
{
    // Sort jobs according to finish time
    sort(arr, arr+n, jobComparataor);

    return findMaxProfitRec(arr, n);
}

// The main function that returns the maximum possible
// profit from given array of jobs
int findMaxProfit_dp(Job arr[], int n)
{
    // Sort jobs according to finish time
    sort(arr, arr+n, jobComparataor);

    // Create an array to store solutions of subproblems. table[i]
    // stores the profit for jobs till arr[i] (including arr[i])
    int *table = new int[n];
    table[0] = arr[0].profit;

    // Fill entries in M[] using recursive property
    for (int i=1; i<n; i++)
    {
        // Find profit including the current job
        int inclProf = arr[i].profit;
        int l = latestNonConflict(arr, i);
        if (l != -1)
            inclProf += table[l];

        // Store maximum of including and excluding
        table[i] = max(inclProf, table[i-1]);
    }

    // Store result and free dynamic memory allocated for table[]
    int result = table[n-1];
    delete[] table;

    return result;
}

// Driver program
int main()
{
    Job arr[] = {{1,3,5},{1,5,6},{2,6,10},{3,6,4},{5,8,6},{6,8,3}};
    int n = sizeof(arr)/sizeof(arr[0]);
    cout << "The optimal profit is " << findMaxProfit_dp(arr, n);
    cout << "Greedy profit is " << findMaxProfit(arr, n);
    return 0;
}

Question 15:

2, 1, 3

4, 6, 5

Question 16:

3, 2, 1

4, 6, 5

Question 17:

1, 5

Add a comment
Know the answer?
Add Answer to:
Given the following jobs to schedule (already ordered): job numberstart time finish timevalue 6 1...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Six jobs are to be processed through a​ two-step operation. The first operation involves​ sanding, and...

    Six jobs are to be processed through a​ two-step operation. The first operation involves​ sanding, and the second involves painting. Processing times are as​ follows: JOB OPERATION 1 (HOURS) OPERATION 2 (HOURS) A 4 8 B 10 5 C 3 11 D 14 14 E 6 1 F 7 12 a. Using​ Johnson's rule for​ 2-machine scheduling, the sequence​ is: Scheduled Order Job 1 ? 2 ? 3 ? 4 ? 5 ? 6 ? b. For the schedule developed...

  • A local welding shop has the following jobs to schedule. Each job needs cleaning first for...

    A local welding shop has the following jobs to schedule. Each job needs cleaning first for performing welding . How much will be total makespan time. ( Use Johnson's scheduling rule) Job Cleaning (Hours) Welding( Hours) Job Cleaning Welding a 3 1 b 5 5 c 2 6 answers: A.12 B. 11 C.14 D.15

  • Processing times and due dates of 9 jobs are given as follows: Job Proc Time Due Date 15 43 10 38...

    Processing times and due dates of 9 jobs are given as follows: Job Proc Time Due Date 15 43 10 38 35 40 25 20 40 Assume that all jobs arrive at time 0 a) (3 points) Generate a schedule that minimizes the mean flow time. Break ties with the smallest job number first (i.e., if 3 and 8 have identical parameters, 3 should be scheduled first). b) (3 points) Calculate mean flow time, mean tardiness, and maximum tardiness of...

  • 3. Consider the following seven-job problem. Each job must be processed by two ma chines A...

    3. Consider the following seven-job problem. Each job must be processed by two ma chines A and B, first on machine A and then machine B. The operation processing times at machine A and B are as follows: Job i 1 2 3 5 6 Processing time on machine A (a9 8 5 10 6 8 5 Processing time on machine B (b) 6 5 7912 11 4 a. Suppose jobs arrived in their natural order (i.e, job before job...

  • a) Using the FCFS​ (first come, first served​ ) decision rule for sequencing the​ jobs, the...

    a) Using the FCFS​ (first come, first served​ ) decision rule for sequencing the​ jobs, the order is​ (assume that jobs came in the order in which they are listed in the​ table): Sequence Job 1 A 2 B 3 C 4 D 5 E The average tardiness​ (job lateness) for the sequence developed using the FCFS rule​ = ___ days ​(round your response to two decimal​ places). The following jobs are waiting to be processed at the same machine...

  • First Printing and Copy Center has 4 jobs to be scheduled. Production scheduling personnel are reviewing...

    First Printing and Copy Center has 4 jobs to be scheduled. Production scheduling personnel are reviewing the Gantt chart at the end of day 4. Job D was scheduled to begin early on day 2 and take 6.5 days. As of now (the review point after day 4), it is 2 days ahead of schedule. Job E should begin on day 1 and take 3 days. It was on time. Job F was to begin on day 3, but maintenance...

  • First Printing and Copy Center has 4 jobs to be scheduled. Production scheduling personnel are reviewing...

    First Printing and Copy Center has 4 jobs to be scheduled. Production scheduling personnel are reviewing the Gantt chart at the end of day 4. Job D was scheduled to begin early on day 2 and take 6.5 days. As of now (the review point after day 4), it is 2 days ahead of schedule. Job E should begin on day 1 and take 3 days. It was on time. Job F was to begin on day 3, but maintenance...

  • The following table contains information regarding jobs that are to be scheduled through one machine. Assume...

    The following table contains information regarding jobs that are to be scheduled through one machine. Assume jobs are listed in order of arrival (i.e., A, then B, then C, etc.). JOB PROCESSING TIME (DAYS) DUE DATE     A 7 20     B 15 21     C 1 16     D 12 17     E 11 15     F 4 6     G 5 12 Round your answers to 1 decimal place. a. What is the first-come, first-served (FCFS) schedule? b. What is the shortest operating time...

  • Question 1: Sequence the jobs shown below by using a Gantt chart. Assume that the move...

    Question 1: Sequence the jobs shown below by using a Gantt chart. Assume that the move time between machines is one hour. Sequence the jobs in priority order 1, 2, 3, 4. Job Work Center/Machine Hours                                  Due Date (days) 1 A/3, B/2, C/2 3 2 C/2, A/4 2 3 B/6, A/1, C/3 4 4 C/4, A/1, B/2 3 Using finite capacity scheduling, draw a Gantt chart for the schedule (Marks 0.5) What is the makespan? (Marks 0.5) How much machine...

  • Using java create the following program and post the answer as well. The Weighted Interval Scheduling...

    Using java create the following program and post the answer as well. The Weighted Interval Scheduling problem is this: Given a set of weighted intervals, choose a set of non-overlapping intervals such that the total weight is maximal. You may think of the “weight” as the profit for doing the work in the given interval A weighted interval x can be represented by a triple        x = (s, f, v), where          s = start time of x,    f...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT