CG_HW1_S05

advertisement
UML CS
Advanced Algorithms (Computational Geometry) 91.504
Spring, 2005
Homework Set #1
Assigned:
Wednesday, 1/26
Due:
Wednesday, 2/9 at start of lecture
This assignment covers:
O’Rourke textbook material in Chapter 1
Introduction to LEDA
1. (15 points) p. 9, Exercise 1.1.4 (1) Guarding the walls.
2. (15 points) p. 16, Exercise 1.2.5 (6) Polygon mouths.
3. (15 points) Star polygon triangulation: As defined in Exercise 1.1.4 (5) on p. 11, a star
polygon is one that can be covered by a single (point) guard. Does the O(n2) worst-case
asymptotic upper bound on the running time of the Triangulate algorithm of Code 1.14
on p. 39 change when the input is restricted to be a star polygon? Why or why not?
4. (20 points) Compile and run the C Triangulate code that accompanies the O’Rourke
textbook. This can be found on our course web site under Homework. Run it for the
polygon whose vertex list is: <(0,0), (20,-10), (40,10), (60,-10), (50,20), (20,30), (40,50),
(0,40)>. The program generates as output a PostScript file containing a picture of the
polygon together with its triangulation. You may either print out the PostScript file on a
PostScript enabled printer and submit the paper printout or email the PostScript file to
Prof. Daniels. It is recommended that you create an input file for the vertex list. Sample
input files are on our course web site; their filenames are of the form “i.xx”.
5. (35 points) Write a LEDA C++ program that creates a polygon and then iterates through
the vertex list, printing out the coordinates of each vertex. Test your program on the
vertex list of Problem 4 above. The program must be run on the research machine
named minkowski because that is where our LEDA license resides. You must ssh into
minkowski from one of our CS servers and use secure ftp to transfer files between
minkowski and our CS servers. A sample makefile is on our course web site under
Homework. The makefile is set up to work with source files that have a .C suffix. You
will need to execute the following UNIX setenv commands prior to making and running
your executable:
setenv LEDAROOTI /usr/local/LEDA-4.3.1/incl
UML CS
Advanced Algorithms (Computational Geometry) 91.504
Spring, 2005
setenv LEDAROOTL /usr/local/LEDA-4.3.1/
setenv LD_LIBRARY_PATH /usr/local/lib:/usr/local/LEDA-4.3.1
It is suggested that you add the above 3 statements to your local.login file. (Note: If
using the bash shell instead of csh you need to modify your bash profile and use export
instead of setenv.)
Put the following 3 statements at the start of your main.C file:
#ifdef LEDA_PREFIX
#undef LEDA_PREFIX
#endif
We recommend that you experiment with the different LEDA loop macros for list iteration,
such as forall_items and forall.
You may choose whether or not you want to use the LEDA rational kernel. If you want
to use it you need to add –D_RATKERNEL_ to your makefile. It is recommended that
you write your code to be kernel independent. We also suggest that you explicitly use
the LEDA prefix when you use most of the LEDA data types to avoid confusion with
types in other libraries (such as CGAL or the C++ STL). Both of these goals can be
accomplished by using leda_point instead of point, leda_polygon instead of polygon,
and leda_list instead of list. You do not need a leda_ prefix when using LEDA’s
list_item type.
Extra Credit: p. 15, Exercise 1.2.5 (4) Number of different triangulations. (Hint: The
91.503 textbook (Rivest, et al.) alludes to the answer in several places…)
Download