



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The covering by trees problem, which is part of the applied graph theory and algorithms course (cmpe□177□) at the university of california, santa cruz in fall 2002. The problem requires determining a set of subtrees in a graph that satisfy certain conditions, and the goal is to devise and implement an algorithm that finds a solution of minimum cost. Examples, input/output file formats, project requirements, and advice for students.
Typology: Study Guides, Projects, Research
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Applied Graph theory and Algorithms Fall 2002
1
Problem Specification: Given a graph G = ( V , E ) together with a distinguished set of vertices L ⊆ V , determine a set of
subtrees T 1 , T 2 , …. Tk in G satisfying the following conditions:
(i) The leaves of each tree belong to L. (ii) Each edge in G belongs to at least one tree.
We define the cost of a solution to be the total number of edges in all trees, i.e.
cost = ( ) 1
i
k
i
=
Your goal is then to devise and implement an algorithm which, given the data G = ( V , E )and L ⊆ V , will determine a solution of minimum cost.
Example 1
The initial graph on the left contains 24 edges and 21 vertices. The white vertices constitute the set L. The solution on the right consists of two trees whose leaves (i.e. vertices of degree 1) belong to L. This solution is optimal since its cost is 24, i.e. no edge has been covered twice. Observe that there are other optimal solutions, such as:
Note that we make no attempt to minimize the number of trees in a solution, only the total cost.
(^1) Thanks to Martine Schlag
Example 2
The graph on the left has 17 edges, which is the cost of the solution consisting of the three trees on the right. The solution is therefore optimal.
Example 3 1
1 2 2 3 3 7 5 4 6 5
4 The solution in this example has cost 8, which is not optimal (edge 3 is repeated). Here is a solution of cost 7:
Example 4 There exist problems of this type in which the optimal cost is greater than the number of edges in the graph, i.e. some edges must be covered more than once:
The solution on the right, which is optimal, has cost 8, while the graph on the left only has 6 edges.
Example 5 There also exist problems with no solution, such as:
A necessary and sufficient condition for a graph G , together with a set L ⊆ V ( G ), to have a solution is
that each edge e ∈ E ( G ) satisfies the following condition: There exists a path in G which includes e ,
and has distinct end vertices lying in L.
You may assume that the input graph is simple (i.e. has no loops or multiple edges.). You may also
assume that both V ( G ) and E ( G ) will not exceed 5000.
Output File Format Your program will generate an output file with the extension .trs corresponding to the given input file. For example, when given the file foo.gr your program will create a new file called foo.trs containing a solution. The first two lines of a .trs file will give the graph name, followed by the number of subtrees in the solution.
Graph: name
Here t is the number of trees. Each tree is then presented as
Tree i j Edge e 1
Edge e 2
Edge e 3
Edge ej
indicating the tree number i , the number of edges j in this tree, and the edge numbers e (^) 1 ,, ej of the
edges in this tree. Returning to example 3 from above, the given solution would be placed in a file called ex3.trs containing the text:
Graph: ex
Tree 1 4 Edge 1 Edge 2 Edge 3 Edge 6 Tree 2 2 Edge 4 Edge 5 Tree 3 2 Edge 3 Edge 7
The tree numbers should appear in numerical order, i.e. Tree 1, followed by Tree 2, etc. However the edges in each tree may appear in any order.
Project Requirements If you don't already have one, get a computer account with CATS (Communications and Technology Services). You can request an account by going to:
http://www2.ucsc.edu/cats/sc/services/accounts/acct-cats-student.shtml
Your project should be written in C, C++, or Java, and should compile and run without errors on the IC (Instructional Computing) Solaris machines (teach.ic, learn.ic, hawking, curie) using the GNU compilers gcc, g++, or the javac compiler. If you develop your project on a different platform, such as your home PC, be sure to test it throughly on the IC Solaris platform before turning it in, since that is where it will be evaluated.
Submit your source files and a Makefile which compiles your code and generates an executable called treecover. This executable will take one command line argument (a .gr file) and write one output file (a .trs file). Thus the command treecover foo.gr will create the file foo.trs. Sample .gr files (including examples used in this handout) will be placed in the directory: /afs/cats.ucsc.edu/courses/cmpe177-pt/graphs.
There is also an executable file called check in the directory /afs/cats.ucsc.edu/courses/cmpe177-pt which will determine if a given .trs file is a valid solution for a given .gr file. To use it you would do: check foo.gr foo.trs
To submit files electronically, type
submit cmpe177-pt.f02 project filename filename... filename
To check that this command was successful: peek cmpe177-pt.f02 project. If you wish to submit an improved version of a file (before the deadline of course), just resubmit as above. The new submission overwrites the old.
Turn in the following:
Advice Spend some time exploring examples to increase your understanding of the problem. Begin by trying to create an algorithm which will just produce a legal solution, i.e. a collection of trees which covers all the edges, and having all leaves in L , then think about ways to improve the cost of the solution. In parallel to this effort think about how you will implement your strategies. You should strive for a program design which is flexible enough to allow for changes as you refine and improve your algorithm.