Ejemplo n.º 1
0
 /**
  * Creates a skyline by dividing the array of buildings and merging them back together, adding
  * buildings in at the base case
  *
  * @param input list of buildings to be put into the skyline
  * @param first starting index in the array
  * @param last final index in the array
  * @param size size of the skyine that the buildings will be put into
  * @return A skyline of buildings
  */
 public static Skyline divideAndConquerSkyline(
     ArrayList<Building> input, int first, int last, int size) {
   if (first == last) {
     Skyline skyline = new Skyline(size);
     skyline = Skyline.addToSkyline(input.get(first), skyline);
     return skyline;
   } else {
     int half = (first + last) / 2;
     Skyline firstSkyline = divideAndConquerSkyline(input, first, half, size);
     Skyline secondSkyline = divideAndConquerSkyline(input, half + 1, last, size);
     return Skyline.mergeSkylines(firstSkyline, secondSkyline);
   }
 }
Ejemplo n.º 2
0
 /**
  * Creates a skyline inductively.
  *
  * @param input array of buidling to be put into a skyline
  * @param size width of desired skyline
  * @return Skyline with buildings put in.
  */
 public static Skyline inductiveSkyline(ArrayList<Building> input, int size) {
   Skyline skyline = new Skyline(size);
   for (int i = 0; i < input.size(); i++) {
     skyline = Skyline.addToSkyline(input.get(i), skyline);
   }
   return skyline;
 }
Ejemplo n.º 3
0
  public static void main(String[] args) {
    // Getting input
    Scanner scanMan = new Scanner(System.in);
    System.out.println("0 for inductive, 1 for divide and conquer");
    int type = scanMan.nextInt();
    System.out.println("What data set? (1-3 plz)");
    int set = scanMan.nextInt();

    // dataSets is the object that retrives data from the sky.dat files
    DataSets info = new DataSets();
    LinkedList<City> cloudySky = info.set(set);

    Skyline sky = new Skyline(cloudySky); // creating

    if (type == 0) sky.mergeInductive();
    else sky.mergeRecursive();

    // System.out.print(sky.toGraph());
    System.out.print(sky.toString());
  }
Ejemplo n.º 4
0
 /**
  * Converts a skyline from spike format to position height position format
  *
  * @param skyline Skyline to be converted from spike to position height position format
  * @return a skyline in position height position form
  */
 public static int[] convert(Skyline skyline) {
   int[] heightOnly = skyline.getSkyline();
   ArrayList<Integer> php = new ArrayList<Integer>();
   php.add(0, 0);
   php.add(1, heightOnly[0]);
   int counter = 2;
   for (int i = 1; i < heightOnly.length; i++) {
     if (heightOnly[i - 1] != heightOnly[i]) {
       php.add(counter, i);
       php.add(counter + 1, heightOnly[i]);
       counter += 2;
     }
   }
   if (heightOnly[heightOnly.length - 1] != 0) {
     php.add(heightOnly.length);
     php.add(0);
   }
   int[] phpFinal = new int[php.size()];
   for (int i = 0; i < phpFinal.length; i++) {
     phpFinal[i] = php.get(i);
   }
   return phpFinal;
 }