Lab Report – Problem 3 - People Server at UNCW

advertisement
Lab Report – Problem 3
Researcher/affiliations
Jui Sun CSC532
Student ID: 850291753
Abstract
The lab report is designing an experimental design and probe into the result of a typical NP-hard
problem. Learning some information from the reference, try to figure out the problems
requirement, and design an experiment to implement the algorithm. Observe the research data
and retrieve information from it. After all, think about the application, talk about the
improvement way, and the direction of the future work should be.
1. Introduction
Typically, given a set of numbers, how to separate into two problems, and make the sum of each
set equal to each other. Here the problem comes to solve if we have to differ the origin set to 3
subsets.
This problem is an extension of an exact cover problem. Given a universe U of elements and a
collection S, a sub-collection S’ of S such that every element in U is contained in exactly one set
in S and the exact cover problem is to find the exact cover S’ or else determine there is none.
For instance, Let S = {A, B, C, D, E}, and U = {1, 2, 3, 4, 5, 6, 7}
And
A = {1, 2}
B = {3, 4}
C = {5, 6}
D = {7}
E = {1, 3, 5}
The sub-collection S’ = {A, B, C, D} is an exact cover of U. And for this problem, we need to
find and possible sub-collection S’ = {A, B, C}, and the sum of every elements in A = the sum of
every elements in B = the sum of every elements in C and S’ is an exact cover of U, which is set
at the beginning.
2. Background
Donald Knuths “Algorithm X”, cf. [6], first presented in 2000, and is a recursive,
nondeterministic, depth-first, brute-force algorithm that finds all solutions to the exact cover
problem for a given input set. He suggested a technique named “Dancing Links” to efficiently
implement his Algorithm X on a computer. From that algorithm, using a parallel programming
approach can make the total computing time for this problem getting shorter.
3. Experimental Design
As problem 2, I use the algorithm related to the carrying. This time, the problem’s solution
focuses on “three subsets”. How can we show all combinations by separation them to 3 subsets?
I still used the algorithm by observing truth table. This time, there is an extra value “2” adding to
this table. So the table would be composed of three numbers, “0, 1, and 2”. In this table, 0 and 1
do not mean” take” or “don’t take” anymore. Number represent which subset it is belonged to.
The target solution of this problem is to find a solution that the sums of each subset are nearly
the same.
And in the algorithm this time, I try to design the way that transfers decimal number to base-3
number. The transfer solution is similar, using a for-loop, divided the decimal number by 3, and
the remainder represents the element in this bit belong to what subset.
For clearly and fundamentally implement in the experimental design, I declare arrays: Val for
recording total set elements, subset1 ~ subset3 to record the result after dividing, and variables:
count1 ~count3 stand for the counters of subset 1 ~3, subsetsum1 ~subsetsum3 stand for the sum
of each subset element, in order to compare the value with each other.
Random select N numbers and save them into array Val. Initialize other variables and arrays if
necessary. Create a double layers for-loop. The outside set each number from 0 to 3n − 1, and
the inside for-loop set transferring those numbers. In the inside for-loop, use the algorithm to get
those subsets elements. For instance, if the remainder appears 1, exact the value from the array
Val, save it to the second subset, and plus 1 to the second subsets counter. And each loop
calculates the sum and uses a counter to record it (for printing out if necessary). Set an ifcondition to check the sum of each set is larger than one third plus ten of the sum of the original
set or not, if it is, break the loop and go through the next number (it would not need to go
through the remaining because whatever the combination of the rest of subsets are, the difference
between each subset would never less than ten). After transferring, check the difference between
the sums of each subset is less than ten or not, if it is, prints these three subsets out. After running
all loops, the result printed out would be the answer to this problem.
4. Findings
Let the total element numbers be 10. The duration of the running time would be about a second.
And the solution would be over 100. But since putting the same elements into other subsets and
other subsets did the same thing is the same situation, the real solution numbers need to divide
the result by 6 (that is, the permutation of 3 subsets.)
Let the total numbers n be 20. Set the minimum difference be 10. And get results over 100000
easily. Make the difference d be 5, it stills easily get over 20000 solutions. So I reduce d to 1.
After many experiment implements, sometimes it got solutions fast enough (about 5 to 10
seconds). But most time it did not get any results. That is, by reducing d, solutions seem to be
reducing as a geometric progressing.
5. Conclusions
As it is a NP-hard problem, the time complexity of computing time is O (nk ). Since it cannot be
calculate within polynomial time, we can use the infinite computing algorithm with time
complexity O (nk ).
This problem solved here is using an LVTG method, which using a large amount of calculate
duration, shows every possible combination, trying to solve this problem within a finite time
duration. As we change the condition to solve this problem, the solutions variation changed huge.
To get a closest result, as the difference number reducing, the result reduced in a huge ratio. That
is, if we cannot get any result from the a very small difference number, try to increase the
number by 1 or more, many option would appear in a short period of time.
The application used for this problem can also be in the job allocations. Given each job a
completing time, try to allocate those jobs to three people. For the principle of fair, we try to
make this allocation approximately near. By reducing time difference between each job, we need
to spend much more time to calculate than previous. That is, as the requirements getting more
serious, the decision time would increase in an exponent way.
6. Future work
To solve a NP-hard problem, not only using a typical brute – force type algorithm, we need to
find some way to reduce the time duration, like using if statement to reduce amount of loops or
use partial search to get an approximately solution. The job needs to “imitate” being solved in
the polynomial time, not trying to solve it really in the polynomial time. For this purpose, we
need to study more and more reference, to make our algorithm much more perfect.
7. References
Sanjoy Dasgupta, Christos Papadimitriou, Umesh Vazirani, “NP-complete problems”,
Algorithms, P.232 – P.247
R.C.T.Lee, S.S.Tseng, R.C.Chang, Y.T.Tsai, “The Theory of NP-Completeness”,
INTRODUCTION TO THE DESIGN AND ANALYSIS OF ALGORITHM, P.364-365
S. M. Ashraful Kadir, “A Parallel Programming Approach to Solve the Exact Cover Problem”,
Scientific Computing, Royal Institute of Technology (KTH), Stockholm, Sweden
Download