Graph Theory and Algorithms: Covering by Trees Problem, Study Guides, Projects, Research of Engineering

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

Pre 2010

Uploaded on 09/17/2009

koofers-user-psv-1
koofers-user-psv-1 🇺🇸

7 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMPE177
AppliedGraphtheoryandAlgorithms
Fall2002
ProgrammingProject:CoveringbyTrees1
ProgressReportdue:ThursdayOctober24
FinalProjectReportdue:ThursdayNovember14
ElectronicSubmissiondue:WednesdayNovember13,10:00pm
ProblemSpecification:
Given a graph ),( EVG
=
together with a distinguished set of vertices VL
, determine a set of
subtrees 1
T, 2
T,…. k
T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= )(
1i
k
i
TE
=
.
Yourgoalisthentodeviseandimplementanalgorithmwhich,giventhedata ),( EVG
=
and VL
,
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
pf3
pf4
pf5

Partial preview of the text

Download Graph Theory and Algorithms: Covering by Trees Problem and more Study Guides, Projects, Research Engineering in PDF only on Docsity!

CMPE 177

Applied Graph theory and Algorithms Fall 2002

Programming Project : Covering by Trees

1

Progress Report due: Thursday October 24

Final Project Report due: Thursday November 14

Electronic Submission due: Wednesday November 13, 10:00 pm

Problem Specification: Given a graph G = ( V , E ) together with a distinguished set of vertices LV , 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

 E^ T

=

Your goal is then to devise and implement an algorithm which, given the data G = ( V , E )and LV , 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 LV ( G ), to have a solution is

that each edge eE ( 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

trees = t

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

trees = 3

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:

  1. Progress report: Thursday October 24, in class. What is your current approach to the problem? Give a description of your algorithm and its strategies (whether implemented or not), including pseudo-code. Describe how you plan to implement this algorithm, i.e. what data structures you will use, how you will represent graphs, trees, etc. 2. Final Report: Thursday November 14, in class. Explain the algorithms and strategies you used in your program. Describe your algorithm in detail, include pseudo-code and an outline of your program. Analyze its asymptotic space and time complexity where appropriate. This complexity should be polynomial in n and m (the number of vertices and edges). Include a table giving the cost of the solution produced for each of the graphs in the directory cmpe177-pt/graphs. Include your source code as an appendix. 3. Electronic Submission: Wednesday November 13, 10:00 pm. Submit your source code (.c, .cc, .h, or .java files), along with a Makefile which creates the executable treecover described above. Also submit a brief README file listing all the files submitted and their function in your project, as well as any notes or special compilation instructions.

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.