Project-ASP-report

advertisement
ALGORITHMS PROJECT WORK - 1
11/17/2013
Version 1.0
Pankaj Kumar(pxk131330@utdallas.edu)
Sagar Davasam(sxd137130@utdallas.edu)
Muthupalaniappan Ramanathan(mxr134630@utdallas.edu)
Problem Statement:
Consider the activity selection problem with N activities from class. Activity a_i has start time s_i, finish
time f_i, and profit of P_i if it is scheduled. An activity is *short* if its duration is at most 4 (i.e., a_i is
short if f_i-s_i <= 4), and long otherwise. Consider the problem of finding a set S of compatible activities
to generate maximum total profit, with the additional restriction that S must have more short activities
than long ones.
Main Idea:
1. Taken ASP Dynamic Programming as base idea and added the logic constraint: Number of short jobs > Number of long jobs, when solution is realized at an event, other values
are stored as probable solutions for sub-problems of future compatible event
2. Data Structure Used:
a. An array of “n” objects where n is the total number of activities and each object
represents one event. For every activity object, a two dimensional array
representing the maximum profit for the short jobs (as rows)*long jobs (as columns)
is used. (Using three dimensional array for larger input activities caused “out of
memory Exception”, which triggered to use objects).
Program Flow:
1.
2.
3.
4.
5.
Fetch the first instance from the input file.
Sort the activities in the first instance on finish time.
Perform the ASP logic for this instance.
Print the output and finish the solution for first instance.
Repeat from Step 1 for the next instance, until end of file.
RECURRENCE:
𝐴𝑆𝑃 (π‘˜, π‘ π‘˜ + π‘π‘’π‘Ÿπ‘†β„Žπ‘œπ‘Ÿπ‘‘, π‘™π‘˜ + π‘π‘’π‘ŸπΏπ‘œπ‘›π‘”)
={
max{𝐴𝑆𝑃(𝑗, π‘ π‘˜ + π‘π‘’π‘Ÿπ‘†β„Žπ‘œπ‘Ÿπ‘‘, π‘™π‘˜ + π‘π‘’π‘ŸπΏπ‘œπ‘›π‘”),
0,
𝑖𝑓 π‘˜ = 0
π‘π‘Ÿπ‘œπ‘“π‘–π‘‘π‘˜ + 𝐴𝑆𝑃(𝑗, π‘ π‘˜, π‘™π‘˜)} , 0 ≤ π‘ π‘˜ ≤ π‘ π‘π‘œπ‘’π‘›π‘‘π‘˜, 0 ≤ π‘™π‘˜ ≤ π‘™π‘π‘œπ‘’π‘›π‘‘ π‘˜
k – Represents the event number for which profit is updated
j – Previous compatible event number, for every k’th event, there could be multiple j events
sk – row index of short n long activity matrix
lk – column index of short n long activity matrix
curShort – is 1, if k’th event is short, otherwise , 0
curLong – is 1, if k’th event is long, otherwise, 0
profitk – profit of k’th event
scount k – total number of short events compatible at k’th event
lcount k – total number of long events compatible at k’th event
Sample Input File:
asptemp.txt
Sample Run:
Enter name of the file as input
E:\\Study-Material\\Sem-1-Fall-2013\\Algo\\Project\\Project-1\\asptemp.txt
Max Profit for instance 1 with 10 input activities is:15
Number of selected short and long events is : 4 and 0
-----------------------------------------Max Profit for instance 2 with 20 input activities is:203
Number of selected short and long events is : 4 and 2
-----------------------------------------Max Profit for instance 3 with 100 input activities is:1178
Number of selected short and long events is : 15 and 14
-----------------------------------------Max Profit for instance 4 with 1000 input activities is:10209
Number of selected short and long events is : 144 and 122
------------------------------------------
Execution Time:
Input Size
10
20
100
1000
Execution Time
0.1 Sec
0.1 Sec
0.4 Sec
2.3 Sec
And Finally
Download