CS 232
Algorithms and Data Structures
Skyline Assignment

Background

    This programming project will require you to implement (in Java) a pair of algorithms to determine the two-dimensional skyline of a set of buildings.  The assignment comes in five phases.  The first phase is due Monday, January 24, at the beginning of class.  For this phase, and this phase ONLY, you may work in groups of up to three.  All other phases are due Wednesday, March 23 and must be completed on your own, as an Individual Project with No Collaboration, as outlined in the department's Academic Practices and Policies document.  As you are maturing programmers, your assignment will be graded on correctness and documentation, but also structure and style.  You are encouraged to discuss programming details with the instructor.

    For each phase, it will be expected that the program has incorporated all relevant portions of the previous phases.  Any errors found in one phase and not subsequently corrected, will result in a deduction in subsequent phases as well.  If two or more phases are submitted simultaneously, then it is possible that a single error could result in multiple deductions.  The instructor promises to return each phase to the student within one week (spring break not included) of its receipt.  Should he fail to do so, an extension will be granted to any student so affected.  If the phases are submitted too late, however, it is possible that feedback will not be available in a timely fashion.  It is the student's responsibility to plan around this.

The Problem
 

    We imagine a city situated on a plain, with all of its buildings aligned to the coordinate axes and all of the building are rectangular prisms.  The input to the problem is a list of buildings, each specified by its left x-coordinate, its top y-coordinate, and its right y-coordinate in that order.  The output is an ArrayList of Points, describing the outline of the skyline.  Two examples are shown below:

In this case, the buildings are (20,40,90), (100,150,120), (150,5,190), and the skyline is (20,40), (90,0), (100,150), (120,0), (150,5), (190,0).

In this case, the buildings are (40,60,90), (70,150,130), and the skyline is (40,60), (70,150), (130,0).  Note that the picture does not show the overlap of the buildings in any particular manner.

The skyline proceeds from one point of the skyline to the next by moving horizontally (at the current y-value) until the x-value of the next Point is reached.  It then proceeds vertically until the y-value of that Point is reached.  It continues to do so until all of the Points have been accounted for.  The x-values in a skyline are strictly increasing.

Note that consecutive Points in the skyline should NOT have equal x- or y-values.  Such points indicate the presence of an extraneous Point that is not needed.  All skylines are assumed to start at (0,0), and the y-value of the last Point of all skylines should be 0 as well.

 

Phase I (due Monday, January 24 in class)

    It is always better to determine your test data before you begin writing code.  Doing so prevents you from designing your test data to cover only those cases you dealt with in the code.  Therefore, the first phase of the assignment requires that you create a test suite against which you will run your code.  Your test suite should include triples indicating, the input, the (correct) output, and the condition being tested.  For instance, the two cases above have are shown in the table below:

Phase II (due Wednesday, Mar. 23, at noon)

   The Building and SkylineViewer classes are provided for you.  The Building class is a simple encapsulation (similar to the Point class, but with no public data) that holds the input values.  The SkylineViewer class will permit you to examine your input and output in a graphical context.  The assignment for Phase II is to demonstrate that you can use both of these classes effectively.  You are therefore to write a program that builds an ArrayList of Buildings and an ArrayList of Points and displays them using a SkylineViewer object.  The ArrayList of Points can be "hard-coded"; in this phase you are not required to compute the skyline.  (Note: The classes are part of a package named CS232.  Be sure to treat them properly in your project.) 

Phase III (due Wednesday, Mar. 23, at noon)

   In this phase, you are to write a program that reads the data for a number of buildings from the keyboard and then computes the skyline.  You may use any algorithm that you desire to compute the skyline.  In addition, for this phase only, you may assume that the buildings are disjoint, in fact that there is an alley between all buildings.

    The format of the input is a line with a single integer (N) representing the number of buildings in the skyline.  This is followed by N lines of three integers each, representing the left, top, and right values of each of the N buildings.  You may assume that all of the input is in the correct format.

    The output is two-fold.  You are to display a skyline viewer with both the buildings and the skyline drawn.  You are also to print two lines of output on the console.  The first is the String "Buildings:  ", followed by an ArrayList containing the buildings (in the order they were entered by the user.)  The second is the String "Skyline:  ", followed by the ArrayList containing the Points of the skyline.  In both cases exactly two spaces follow the colon.

Phase IV (due Wednesday, Mar. 23, at noon)

   In this phase, the format of the input and output is the same as in Phase III, but it is possible that some buildings overlap.  The skyline is to be computed by an insertion-sort-like algorithm where each building is added to the skyline of the buildings that preceded it.  This will result in a running time that is quadratic in the length of the input.

Phase V (due Wednesday, Mar. 23, at noon)

   The input and output for this phase is identical to that of Phase III (and IV), but this time, you must use a divide-and-conquer, merge-sort-like alogrithm.  This will result in an O(N*logN) algorithm.  If Phase IV has been coded correctly, the code to merge one building into an existing skyline can easily be modified to merge two existing skylines into one.  This should make Phase V considerably easier than Phase IV.

Note:  Phases II-V should be turned in via email.