Vous êtes sur la page 1sur 5

Lectures Covered: 21 to 32

Objective
To solve daily life problems by Dynamic Programming techniques.

Uploading instructions:
Please view the Assignment Submission Process document provided to you by the Virtual University for uploadin
assignments.

Your assignment must be in .doc format. (Any other formats like scan images, PDF, Zip, rar, bmp etc. will n
be accepted).
Save your assignment with your ID (e.g. bc020200786.doc).
No assignment will be accepted through email.

Rules for Marking:


It should be clear that your assignment will not get any credit if:
The assignment is submitted after due date.
The submitted assignment does not open or file is corrupted.
Your assignment is copied from internet, handouts or from any other student
(Strict disciplinary action will be taken in this case).
Question No.1:

(12 Mark

Mr. Rashid is a visiting Lecturer by profession and he has several teaching opportunities available for the comin
session. A number of educational institutes have offered him salary per day with number of hours for which h
lecturing services are required. These institutes have flexible time scheduling for lectures but have restrictions on t
total hours per day teaching requirement. For example, if offer is of 5 hours per day then teaching schedule for M
Rashid can be set at any time in the day but he must has to give 5 hours each day to that institute. Mr. Rashid ca
work for total of 12 hours in day at maximum. Below is the list of his teaching opportunities with per day workin
hours and payments in Rs. for the next session.
Offer
(o)
o1
o2
o3
o4
o5

No Work Hours (h)


2
3
5
7
8

Payment (p) in Rs.


1500
2500
3000
5000
6000

You need to apply 0/1-Knapsack problem optimization for Mr. Rashid for selection of offers to maximize his incom
per day.
What is the maximum payment (in Rs.) he can get using Dynamic programming approach on 0/1-Knapsack problem

Note: Show each step of table filling. You have to tell the best possible profit only and need not to tell the
corresponding offer selection i.e. no need to maintain keep [] matrix.
Weight Limit
w1 = 2 v1 = 1500
w2 = 3 v2 = 2500
w3 = 5 v3 = 3000
w4 = 7 v4 = 5000
w5 = 8 v5 = 6000

10 11 12

Weight Limit
w1 = 2 v1 = 1500
w2 = 3 v2 = 2500
w3 = 5 v3 = 3000
w4 = 7 v4 = 5000
w5 = 8 v5 = 6000

0
0
0
0
0
0

1
0
0
0
0
0

2
3
4
5
6
7
8
9
10
11
12
1500 1500 1500 1500 1500 1500 1500 1500 1500 1500 1500

Weight Limit
w1 = 2 v1 = 1500
w2 = 3 v2 = 2500
w3 = 5 v3 = 3000
w4 = 7 v4 = 5000
w5 = 8 v5 = 6000

0
0
0
0
0
0

1
0
0
0
0
0

2
3
4
5
6
7
8
9
10
11
12
1500 1500 1500 1500 1500 1500 1500 1500 1500 1500 1500
1500 2500 2500 2500 2500 2500 2500 2500 2500 2500 2500

Weight Limit
w1 = 2 v1 = 1500
w2 = 3 v2 = 2500
w3 = 5 v3 = 3000
w4 = 7 v4 = 5000
w5 = 8 v5 = 6000

0
0
0
0
0
0

1
0
0
0
0
0

2
1500
1500
1500

3
1500
2500
2500

4
1500
2500
2500

5
1500
2500
4000

6
1500
2500
4000

7
1500
2500
4500

8
1500
2500
5500

9
1500
2500
5500

10
1500
2500
7000

11
1500
2500
7000

12
1500
2500
7000

Weight Limit
w1 = 2 v1 = 1500
w2 = 3 v2 = 2500
w3 = 5 v3 = 3000
w4 = 7 v4 = 5000
w5 = 8 v5 = 6000

0
0
0
0
0
0

1
0
0
0
0
0

2
1500
1500
1500
1500

3
1500
2500
2500
2500

4
1500
2500
2500
2500

5
1500
2500
4000
4000

6
1500
2500
4000
4000

7
1500
2500
4500
5000

8
1500
2500
5500
5500

9
1500
2500
5500
6500

10
1500
2500
7000
7500

11
1500
2500
7000
7500

12
1500
2500
7000
9000

Weight Limit
w1 = 2 v1 = 1500
w2 = 3 v2 = 2500
w3 = 5 v3 = 3000
w4 = 7 v4 = 5000
w5 = 8 v5 = 6000

0
0
0
0
0
0

1
0
0
0
0
0

2
1500
1500
1500
1500
1500

3
1500
2500
2500
2500
2500

4
1500
2500
2500
2500
2500

5
1500
4000
4000
4000
4000

6
1500
4000
4000
4000
4000

7
1500
4000
4500
5000
5000

8
1500
4000
5500
5500
6000

9
1500
4000
5500
6500
6500

10
1500
4000
7000
7500
7500

11
1500
4000
7000
7500
8500

12
1500
4000
7000
9000
9000

The maximum value of Hours in the knapsack is 9000, the right-bottom entry.

Question No.2:

(8 Mark

Suppose teaching opportunities (in number of hours) are same as above case but all these institutes offer Rs. 700 p
hour fix rate payment for teaching. Also suppose that services at all institutes are required to be for continuous hou
and have restriction of time schedules of teaching as below;
Offer
(o)
o1
o2
o3
o4
o5

No

Start time (s)

Finish time (f)

16:00
18:00
14:00
08:00
09:00

18:00
21:00
19:00
15:00
17:00

In these circumstances, you are required to apply Greedy approach of Activity Selection problem to select maximu
number of possible options for Mr. Rashid among these teaching opportunities in order to maximize his earning.
What will be the selected offers of teaching by Mr. Rashid according to Activity Selection optimization?

Note: Show the process of Greedy Activity Selection. Using of drawing bars for showing teaching activiti
arrangement is optional, instead you are allowed to do re-arranging/sorting/selection in the table simply.
Solution:
Offer
(o)
o4
o5
o1
o3
o2

No

Start time (s)

Finish time (f)

(f) (s)

08:00
09:00
16:00
14:00
18:00

15:00
17:00
18:00
19:00
21:00

7
8
2
5
3

10

11

12

13

14

15

16

17

18

19

20

21
0
4
0
1
0
2

According to Activity Selection optimization, Activities with Green bars will be selected which are 04, 01, and 0
which will maximize his earnings.

NOTE: Submit .doc file only. Every student should provide his/her own work, exact copying of the assignment (
some portion of the assignment) from the internet or other students will lead to copy case and zero marks will
awarded. Different softwares will be used to check plagiarism in assignments. Do not put any query on MDB abo
this assignment, if you have any query then email at CS502@vu.edu.pk

Vous aimerez peut-être aussi