Tspdaa
Tspdaa
Submitted by:
Chiranjeev Kumar
10100EN038
B.Tech (Part III), VI- Semester
Department of Computer Science and Engineering,
Indian Institute of Technology (BHU), Varanasi
Supervisor:
Dr. A.K. TRIPATHI
PROFESSOR,
VARANASI.
ACKNOWLEDGEMENT
Chiranjeev Kumar
2
CERTIFICATE
This is to certify that, Mr. CHIRANJEEV KUMAR has completed his project
on “making a java application which will teach approximation
algorithm” satisfactorily in partial fulfilment under the department of
Computer Engineering IIT(BHU),Varanasi during academic year 2012-
2013.
____________________________
Teacher In-Charge
3
ABSTRACT
This application for learning APPROXIMATION ALGORITHM has been
designed in Java which will make user comfortable in learning the
very complex subject “NP-Completeness” and the solution to NP-
Complete problem using approximation algorithm.
4
Table of Contents
1. Introduction..................................................................................................................5
5. Approximation methods............................................................................................12
6. Implementation …………………………………………………………….15
7. Results ……………………………………………………………………...16
8. Conclusion…………….……………………...…………………………......19
5
1. Introduction
There are various problems in computer science for which no polynomial time
algorithm is known till now. These special problems are categorized as NP (not
polynomial time) problems. A problem P is NP-hard if a polynomial-time
algorithm for P would imply a polynomial-time algorithm for every problem in
NP.
Many problems of practical significance are NP-complete, yet they are too
important to abandon merely because we don’t know how to find an optimal
solution in polynomial time. Even if a problem is NP-complete, there may be
hope. We have at least three ways to get around NP-completeness.
6
2. Working of the application
Once the application is started, this will guide the user step-by-step and
the user will learn the subject in an easy way.
If the user clicks on the rectangular box, next window appears like-
7
Pressing next button will open the next window like-
Problem list
8
Utilities and concepts
9
3. Uses of the application
An old engineering slogan says, “fast. Cheep. Reliable. Choose two.” Similarly,
if P!= NP, we can’t simultaneously have two algorithms that (1) find optimal
solution (2) in polynomial time (3) for any instance. At least one of these
requirements must be relaxed in any approach to dealing with an NP-hard
optimization problem.
One approach relaxes the “for any instance” requirement, and finds the
polynomial time algorithms for special cases of the problem at hand. This is
useful if the instances one desires to solve fall into one of these special cases,
but this is not frequently the case.
10
4. Approximation techniques
No polynomial-time algorithm has yet been discovered for an NP-complete
problem, nor has anyone yet been able to prove that no polynomial-time
algorithm can exist for any one of them. This so-called P ¤ NP question has
been one of the deepest, most perplexing open research problems in
theoretical computer science since it was first posed in 1971. Several NP-
complete problems are particularly tantalizing because they seem on the
surface to be similar to problems that we know how to solve in polynomial
time.
We say that an algorithm for a problem has an approximation ratio of ρ(n) if,
for any input of size n, the cost C of the solution produced by the algorithm is
within a factor of ρ(n) of the cost C* of an optimal solution:
11
5. Approximation methods
Some Problems used in the application have been implemented using
approximation algorithms. These solutions are mostly polynomial time 2-
approximation algorithms.
1. Vertex-cover problem
1. C=Ø
2. E’ = G.E
3. while E != Ø
4. let (u ,v) be an arbitrary edge of E’
5. C = C U {u ,v}
6. remove from E’ every edge incident on either u or v
7. return C
3. Subset-sum problem
13
• EXACT-SUBSET-SUM(S,t)
1. N = |S|
2. L0 = <0>
3. For i=1 to n
• APPROX-SUBSET-SUM(S, t, ἐ)
1. N = |S|
2. L0 = <0>
3. For i=1 to n
2. Li = TRIM(Li, ἐ/2n)
5. Return z*.
14
6. Implementation
Because this project is somewhat small and straightforward, a waterfall
type of model has been used. We start the design activity by identifying classes
of objects in the problem domain and relationship between the classes. From
the problem specification we can clearly identify the objects as the list of NP-
problems as well as their solutions. Besides that one extra main class has been
used. All the necessary data structure and utility functions have been
separately implemented in different classes to reduce coupling.
15
7. Results
The application is packaged in JAR file. Some windows describing the solution
to the problems on executing the application appear as-
16
Knapsack problem window
17
Travelling Salesman solution window
18
8. Conclusion
There are many complex subjects of discussions like the topic discussed in this
project. They can be made possible to be learnt using this type of software
application in a different style. This can be implemented using network or
without network. In case of network application, the idea has to be extended
from single user application to client server model where the application will
be requested to server from client side which may be a java applet rather than
an application.
19
9. Code Snippet
For every problem as well solution there is a separate class. To bring cohesion
related functionality is embedded in the respective class. The Main class is like-
package se;
/**
* @author chiranjeev
*/
/**
*/
java.awt.EventQueue.invokeLater(new Runnable() {
new Tutorial().setVisible(true);
});
This calls Tutorial class which then uses other classes and make environment
flexible. Actual code can be found in the CD. It is about 2500 LOC.
20
10. References
Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, Ronald
L. Rivest and Clifford Stein (Jul 31, 2009)
www.wikipedia.org
http://www.designofapproxalgs.com/
http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Aprox
Algor/AproxIntro.htm
http://pages.cs.wisc.edu/~shuchi/courses/880-S07/
http://www.youtube.com/watch?v=YS0VKIM8zyY
http://en.wikipedia.org/wiki/Approximation_algorithm
21