GithubHelp home page GithubHelp logo

valeriapineda23 / job-scheduling Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 104 KB

Applying Dynamic Programming for Job Scheduling Problem

Python 100.00%
dynamic-programming job-scheduling optimization-algorithms python

job-scheduling's Introduction

Applying Dynamic Programming for Job Scheduling Problem

Problem

Suppose you have one machine and a set of $n$ jobs $a_1, a_2, ..., a_n$ to process on that machine. Each job $a_j$ has a processing time $t_j$ , a profit $p_j$ and a deadline $d_j$ . The machine can only do one job at a time, and job $a_j$ must run uninterruptedly for $t_j$ consecutive time units. If job $a_j$ is completed by its deadline $d_j$, you receive a profit $p_j$, but if it’s completed after its deadline, you receive a profit of $0$. Give a dynamic programming algorithm to find the schedule that obtains the maximum amount of profit, assuming that all processing times are integers between $1$ and $n$.

Solution

Now we provide the solution for the problem, considering that we have the following data:

Job (j) Processing time ($t_j$) Deadline ($d_j$) Profit ($p_j$)
1 4 10 2
2 4 15 5
3 5 5 3
4 6 10 4

First Iteration

$𝑓_1[π‘Ž_1]= 2 \quad\quad\quad\quad π‘˜[1] = 1$
$𝑓_1[π‘Ž_2]= 5 \quad\quad\quad\quad π‘˜[2] = 2$
$𝑓_1[π‘Ž_3]= 3 \quad\quad\quad\quad π‘˜[3] = 3$
$𝑓_1[π‘Ž_4]= 4 \quad\quad\quad\quad π‘˜[4] = 4$

Second Iteration

$𝑓_2[π‘Ž_1,a_2]= max \big[f_1[a_1]+h_2(t_1+t_2), f_1[a_2]+h_1(t_1+t_2)\big]$
$\quad\quad\quad\quad =max\big[2+5,5+2\big]$
$\quad\quad\quad\quad =max\big[7,7\big]$
$\quad\quad\quad\quad =7$
$\quad k[1,2] = 1,2$

$𝑓_2[π‘Ž_1,a_3]= max \big[f_1[a_1]+h_3(t_1+t_3), f_1[a_3]+h_1(t_1+t_3)\big]$
$\quad\quad\quad\quad =max\big[2+0,3+2\big]$
$\quad\quad\quad\quad =max\big[2,5\big]$
$\quad\quad\quad\quad =5$
$\quad k[1,3] = 1$

$𝑓_2[π‘Ž_1,a_4]= max \big[f_1[a_1]+h_4(t_1+t_4), f_1[a_4]+h_1(t_1+t_4)\big]$
$\quad\quad\quad\quad =max\big[2+4,4+2\big]$
$\quad\quad\quad\quad =max\big[6,6\big]$
$\quad\quad\quad\quad =6$
$\quad k[1,4] = 1,4$

$𝑓_2[π‘Ž_2,a_3]= max \big[f_1[a_2]+h_3(t_2+t_3), f_1[a_3]+h_2(t_2+t_3)\big]$
$\quad\quad\quad\quad =max\big[5+0,3+5\big]$
$\quad\quad\quad\quad =max\big[5,8\big]$
$\quad\quad\quad\quad =8$
$\quad k[2,3] = 2$

$𝑓_2[π‘Ž_2,a_4]= max \big[f_1[a_2]+h_4(t_2+t_4), f_1[a_4]+h_2(t_2+t_4)\big]$
$\quad\quad\quad\quad =max\big[5+4,4+5\big]$
$\quad\quad\quad\quad =max\big[9,9\big]$
$\quad\quad\quad\quad =9$
$\quad k[2,4] = 2,4 $

$𝑓_2[π‘Ž_3,a_4]= max \big[f_1[a_3]+h_4(t_3+t_4), f_1[a_4]+h_3(t_3+t_4)\big]$
$\quad\quad\quad\quad =max\big[3+0,4+0\big]$
$\quad\quad\quad\quad =max\big[3,4\big]$
$\quad\quad\quad\quad =4$
$\quad k[3,4] = 3 $

Third Iteration

$𝑓_3[π‘Ž_1,a_2,a_3]= max \big[f_2[a_1,a_2]+h_3(t_1+t_2+t_3), f_2[a_1,a_3]+h_2(t_1+t_2+t_3), f_2[a_2,a_3]+h_1(t_1+t_2+t_3)\big]$
$\quad\quad\quad\quad\quad\quad =max\big[7+0,5+5,8+0\big]$
$\quad\quad\quad\quad\quad\quad =max\big[7,10,8\big]$
$\quad\quad\quad\quad\quad\quad =10$
$\quad\quad k[1,2,3] = 2$

$𝑓_3[π‘Ž_1,a_2,a_4]= max \big[f_2[a_1,a_2]+h_3(t_1+t_2+t_4), f_2[a_1,a_4]+h_2(t_1+t_2+t_4), f_2[a_2,a_4]+h_1(t_1+t_2+t_4)\big]$
$\quad\quad\quad\quad\quad\quad =max\big[7+0,6+5,9+0\big]$
$\quad\quad\quad\quad\quad\quad =max\big[7,11,9\big]$
$\quad\quad\quad\quad\quad\quad =11$
$\quad\quad k[1,2,4] = 2$

$𝑓_3[π‘Ž_1,a_3,a_4]= max \big[f_2[a_1,a_3]+h_3(t_1+t_3+t_4), f_2[a_1,a_4]+h_3(t_1+t_3+t_4), f_2[a_3,a_4]+h_1(t_1+t_3+t_4)\big]$
$\quad\quad\quad\quad\quad\quad =max\big[5+0,6+0,4+0\big]$
$\quad\quad\quad\quad\quad\quad =max\big[5,6,4\big]$
$\quad\quad\quad\quad\quad\quad =6$
$\quad\quad k[1,3,4] = 3$

$𝑓_3[π‘Ž_2,a_3,a_4]= max \big[f_2[a_2,a_3]+h_3(t_2+t_3+t_4), f_2[a_2,a_4]+h_3(t_2+t_3+t_4), f_2[a_3,a_4]+h_2(t_2+t_3+t_4)\big]$
$\quad\quad\quad\quad\quad\quad =max\big[8+0,9+0,4+5\big]$
$\quad\quad\quad\quad\quad\quad =max\big[5,9,9\big]$
$\quad\quad\quad\quad\quad\quad =9$
$\quad\quad k[2,3,4] = 2,3$

Fourth Iteration

$𝑓_4[π‘Ž_1,a_2,a_3,a_4]= max \big[f_3[π‘Ž_1,a_2,a_3]+h_4(t_1+t_2+t_3+t_4), f_3[π‘Ž_1,a_2,a_4]+h_3(t_1+t_2+t_3+t_4), f_3[π‘Ž_1,a_3,a_4]+$
$\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad h_2(t_1+t_2+t_3+t_4), f_1[a_2,a_3,a_4]+h_4(t_1+t_2+t_3+t_4)\big]$
$\quad\quad\quad\quad\quad\quad =max\big[10+0,11+0,6+0,9+0\big]$
$\quad\quad\quad\quad\quad\quad =max\big[10,11,6,9\big]$
$\quad\quad\quad\quad\quad\quad =11$
$\quad\quad k[1,2,3,4] = 3$

Solution

1 --> 4 --> 2 --> 3

job-scheduling's People

Contributors

valeriapineda23 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.