From 928a5fed1577204a7216d1bc568128ea9f4d6c79 Mon Sep 17 00:00:00 2001 From: dimgrichr <32580033+dimgrichr@users.noreply.github.com> Date: Wed, 9 Jan 2019 14:11:48 +0200 Subject: [PATCH 1/6] Add files via upload SkyLine Algorithm --- divideconquer/SkylineAlgorithm.java | 241 ++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 divideconquer/SkylineAlgorithm.java diff --git a/divideconquer/SkylineAlgorithm.java b/divideconquer/SkylineAlgorithm.java new file mode 100644 index 000000000000..a1d4918ce326 --- /dev/null +++ b/divideconquer/SkylineAlgorithm.java @@ -0,0 +1,241 @@ + +package skylinealgorithm; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Scanner; + +/** + * + * @author Dimitrios Panagiotis Grigoriou / dimgrichr + * + * Space complexity: O(n) + * Time complexity: O(nlogn), because it is a divide and conquer algorithm + */ +public class SkylineAlgorithm { + private Scanner scanner; + private File file; + private ArrayList points; + private int tableSize; + + + /** + * Main constructor of the application. + * ArrayList points gets created, which represents the sum of all edges, + * which are read from input file. + * File's(built-in class) object file is created, + * and gets combined with Scanner's(built-in class) object scanner, + * so that the points are read. + * @param name , the name of the input file. + * @throws FileNotFoundException , if input file is not found. + */ + public SkylineAlgorithm(String name) throws FileNotFoundException{ + File file = new File(name); + scanner = new Scanner(file); + points = new ArrayList<>(); + tableSize=scanner.nextInt(); + } + + + /** + * ArrayList points is filled with all points that are included + * in the input file. + * Points are sorted based on the x-value, using a Comparator. + * @see XComparator + */ + public void fillMass(){ + for(int i=0;scanner.hasNextInt();i++){ + //points get added to the ArrayList + points.add(new Point(scanner.nextInt(),scanner.nextInt())); + } + //ArrayList points gets sorted + Collections.sort(points,new XComparator()); + } + + + /** + * @return points, the ArrayList that includes all points. + */ + public ArrayList getPoints(){ + return points; + } + + + /** + * The main divide and conquer, and also recursive algorithm. + * It gets an ArrayList full of points as an argument. + * If the size of that ArrayList is 1 or 2, + * the ArrayList is returned as it is, or with one less point + * (if the initial size is 2 and one of it's points, is dominated by the other one). + * On the other hand, if the ArrayList's size is bigger than 2, + * the function is called again, twice, + * with arguments the corresponding half of the initial ArrayList each time. + * Once the flashback has ended, the function produceFinalSkyLine gets called, + * in order to produce the final skyline, and return it. + * @param list, the initial list of points + * @return leftSkyLine, the combination of first half's and second half's skyline + * @see Point + * @see produceFinalSkyLine + */ + public ArrayList produceSubSkyLines(ArrayList list){ + + //part where function exits flashback + int size = list.size(); + if(size == 1){ + return list; + } + else if(size==2){ + if(list.get(0).dominates(list.get(1))){ + list.remove(1); + } + else{ + if(list.get(1).dominates(list.get(0))){ + list.remove(0); + } + } + return list; + } + + //recursive part of the function + ArrayList leftHalf=new ArrayList<>(); + ArrayList rightHalf=new ArrayList<>(); + for (int i=0;i leftSubSkyLine=new ArrayList<>(); + ArrayList rightSubSkyLine=new ArrayList<>(); + leftSubSkyLine=produceSubSkyLines(leftHalf); + rightSubSkyLine=produceSubSkyLines(rightHalf); + + //skyline is produced + return produceFinalSkyLine(leftSubSkyLine,rightSubSkyLine); + } + + + /** + * The first half's skyline gets cleared + * from some points that are not part of the final skyline + * (Points with same x-value and different y=values. The point with the smallest y-value is kept). + * Then, the minimum y-value of the points of first half's skyline is found. + * That helps us to clear the second half's skyline, because, the points + * of second half's skyline that have greater y-value of the minimum y-value that we found before, + * are dominated, so they are not part of the final skyline. + * Finally, the "cleaned" first half's and second half's skylines, are combined, + * producing the final skyline, which is returned. + * @param left the skyline of the left part of points + * @param right the skyline of the right part of points + * @return left the final skyline + */ + public ArrayList produceFinalSkyLine(ArrayList left, ArrayList right){ + + //dominated points of ArrayList left are removed + for(int i=0;ileft.get(i+1).y){ + left.remove(i); + i--; + } + } + + //minimum y-value is found + int min=left.get(0).y; + for(int i=1;ileft.get(i).y){ + min = left.get(i).y; + if(min==1){ + i=left.size(); + } + } + } + + //dominated points of ArrayList right are removed + for(int i=0;i=min){ + right.remove(i); + i--; + } + } + + //final skyline found and returned + left.addAll(right); + return left; + } + + + + public static class Point{ + private int x; + private int y; + /** + * The main constructor of Point Class, used to represent the 2 Dimension points. + * @param x the point's x-value. + * @param y the point's y-value. + */ + public Point(int x, int y){ + this.x=x; + this.y=y; + } + /** + * @return x, the x-value + */ + public int getX(){ + return x; + } + /** + * @return y, the y-value + */ + public int getY(){ + return y; + } + /** + * Based on the skyline theory, + * it checks if the point that calls the function dominates the argument point. + * @param p1 the point that is compared + * @return true if the point wich calls the function dominates p1 + * false otherwise. + */ + public boolean dominates(Point p1){ + + //checks if p1 is dominated + if((this.x { + @Override + public int compare(Point a, Point b) { + return a.x < b.x ? -1 : a.x == b.x ? 0 : 1; + } + } + + + //main function + public static void main(String[] args) throws FileNotFoundException { + if (args.length != 1) + { + System.out.println("Insert the input file"); + return; + } + SkylineAlgorithm skyline = new SkylineAlgorithm(args[0]); + skyline.fillMass(); + ArrayList list = skyline.produceSubSkyLines(skyline.getPoints()); + for(Point x: list){ + System.out.println(x.getX() + " " + x.getY()); + } + } +} From a85b36db9557b4abe1b39b3be7a6c8425793fde8 Mon Sep 17 00:00:00 2001 From: dimgrichr <32580033+dimgrichr@users.noreply.github.com> Date: Wed, 9 Jan 2019 14:22:34 +0200 Subject: [PATCH 2/6] Add files via upload --- Dynamic Programming/TaskCosts.java | 118 +++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 Dynamic Programming/TaskCosts.java diff --git a/Dynamic Programming/TaskCosts.java b/Dynamic Programming/TaskCosts.java new file mode 100644 index 000000000000..10e5457b626c --- /dev/null +++ b/Dynamic Programming/TaskCosts.java @@ -0,0 +1,118 @@ +package projectb; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +/** + * + * @author dimig + */ +public class TaskCosts { + + private Scanner scanner; + private File file; + + private int tasks; + private int vms; + + private int[][] vmsPer; + private int[][] vmsCom; + private int[][] costs; + + + private TaskCosts(String nameOfInputFile) throws FileNotFoundException{ + File file = new File(nameOfInputFile); + scanner = new Scanner(file); + tasks = scanner.nextInt(); + vms = scanner.nextInt(); + costs = new int[tasks][vms]; + vmsPer = new int[tasks][vms]; + vmsCom = new int[vms][vms]; + for(int i=0;i Date: Tue, 15 Jan 2019 12:39:14 +0200 Subject: [PATCH 3/6] Delete SkylineAlgorithm.java --- divideconquer/SkylineAlgorithm.java | 241 ---------------------------- 1 file changed, 241 deletions(-) delete mode 100644 divideconquer/SkylineAlgorithm.java diff --git a/divideconquer/SkylineAlgorithm.java b/divideconquer/SkylineAlgorithm.java deleted file mode 100644 index a1d4918ce326..000000000000 --- a/divideconquer/SkylineAlgorithm.java +++ /dev/null @@ -1,241 +0,0 @@ - -package skylinealgorithm; - -import java.io.File; -import java.io.FileNotFoundException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.Scanner; - -/** - * - * @author Dimitrios Panagiotis Grigoriou / dimgrichr - * - * Space complexity: O(n) - * Time complexity: O(nlogn), because it is a divide and conquer algorithm - */ -public class SkylineAlgorithm { - private Scanner scanner; - private File file; - private ArrayList points; - private int tableSize; - - - /** - * Main constructor of the application. - * ArrayList points gets created, which represents the sum of all edges, - * which are read from input file. - * File's(built-in class) object file is created, - * and gets combined with Scanner's(built-in class) object scanner, - * so that the points are read. - * @param name , the name of the input file. - * @throws FileNotFoundException , if input file is not found. - */ - public SkylineAlgorithm(String name) throws FileNotFoundException{ - File file = new File(name); - scanner = new Scanner(file); - points = new ArrayList<>(); - tableSize=scanner.nextInt(); - } - - - /** - * ArrayList points is filled with all points that are included - * in the input file. - * Points are sorted based on the x-value, using a Comparator. - * @see XComparator - */ - public void fillMass(){ - for(int i=0;scanner.hasNextInt();i++){ - //points get added to the ArrayList - points.add(new Point(scanner.nextInt(),scanner.nextInt())); - } - //ArrayList points gets sorted - Collections.sort(points,new XComparator()); - } - - - /** - * @return points, the ArrayList that includes all points. - */ - public ArrayList getPoints(){ - return points; - } - - - /** - * The main divide and conquer, and also recursive algorithm. - * It gets an ArrayList full of points as an argument. - * If the size of that ArrayList is 1 or 2, - * the ArrayList is returned as it is, or with one less point - * (if the initial size is 2 and one of it's points, is dominated by the other one). - * On the other hand, if the ArrayList's size is bigger than 2, - * the function is called again, twice, - * with arguments the corresponding half of the initial ArrayList each time. - * Once the flashback has ended, the function produceFinalSkyLine gets called, - * in order to produce the final skyline, and return it. - * @param list, the initial list of points - * @return leftSkyLine, the combination of first half's and second half's skyline - * @see Point - * @see produceFinalSkyLine - */ - public ArrayList produceSubSkyLines(ArrayList list){ - - //part where function exits flashback - int size = list.size(); - if(size == 1){ - return list; - } - else if(size==2){ - if(list.get(0).dominates(list.get(1))){ - list.remove(1); - } - else{ - if(list.get(1).dominates(list.get(0))){ - list.remove(0); - } - } - return list; - } - - //recursive part of the function - ArrayList leftHalf=new ArrayList<>(); - ArrayList rightHalf=new ArrayList<>(); - for (int i=0;i leftSubSkyLine=new ArrayList<>(); - ArrayList rightSubSkyLine=new ArrayList<>(); - leftSubSkyLine=produceSubSkyLines(leftHalf); - rightSubSkyLine=produceSubSkyLines(rightHalf); - - //skyline is produced - return produceFinalSkyLine(leftSubSkyLine,rightSubSkyLine); - } - - - /** - * The first half's skyline gets cleared - * from some points that are not part of the final skyline - * (Points with same x-value and different y=values. The point with the smallest y-value is kept). - * Then, the minimum y-value of the points of first half's skyline is found. - * That helps us to clear the second half's skyline, because, the points - * of second half's skyline that have greater y-value of the minimum y-value that we found before, - * are dominated, so they are not part of the final skyline. - * Finally, the "cleaned" first half's and second half's skylines, are combined, - * producing the final skyline, which is returned. - * @param left the skyline of the left part of points - * @param right the skyline of the right part of points - * @return left the final skyline - */ - public ArrayList produceFinalSkyLine(ArrayList left, ArrayList right){ - - //dominated points of ArrayList left are removed - for(int i=0;ileft.get(i+1).y){ - left.remove(i); - i--; - } - } - - //minimum y-value is found - int min=left.get(0).y; - for(int i=1;ileft.get(i).y){ - min = left.get(i).y; - if(min==1){ - i=left.size(); - } - } - } - - //dominated points of ArrayList right are removed - for(int i=0;i=min){ - right.remove(i); - i--; - } - } - - //final skyline found and returned - left.addAll(right); - return left; - } - - - - public static class Point{ - private int x; - private int y; - /** - * The main constructor of Point Class, used to represent the 2 Dimension points. - * @param x the point's x-value. - * @param y the point's y-value. - */ - public Point(int x, int y){ - this.x=x; - this.y=y; - } - /** - * @return x, the x-value - */ - public int getX(){ - return x; - } - /** - * @return y, the y-value - */ - public int getY(){ - return y; - } - /** - * Based on the skyline theory, - * it checks if the point that calls the function dominates the argument point. - * @param p1 the point that is compared - * @return true if the point wich calls the function dominates p1 - * false otherwise. - */ - public boolean dominates(Point p1){ - - //checks if p1 is dominated - if((this.x { - @Override - public int compare(Point a, Point b) { - return a.x < b.x ? -1 : a.x == b.x ? 0 : 1; - } - } - - - //main function - public static void main(String[] args) throws FileNotFoundException { - if (args.length != 1) - { - System.out.println("Insert the input file"); - return; - } - SkylineAlgorithm skyline = new SkylineAlgorithm(args[0]); - skyline.fillMass(); - ArrayList list = skyline.produceSubSkyLines(skyline.getPoints()); - for(Point x: list){ - System.out.println(x.getX() + " " + x.getY()); - } - } -} From 96ad920ce5975e17ac4c644819dc3e204b8e772b Mon Sep 17 00:00:00 2001 From: dimgrichr <32580033+dimgrichr@users.noreply.github.com> Date: Tue, 15 Jan 2019 12:41:26 +0200 Subject: [PATCH 4/6] Addition of the Skyline Algorithm Implementation of the skyline algorithm --- divideconquer/SkylineAlgorithm.java | 190 ++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 divideconquer/SkylineAlgorithm.java diff --git a/divideconquer/SkylineAlgorithm.java b/divideconquer/SkylineAlgorithm.java new file mode 100644 index 000000000000..f1b1f44c7433 --- /dev/null +++ b/divideconquer/SkylineAlgorithm.java @@ -0,0 +1,190 @@ +package skylinealgorithm; + +import java.util.ArrayList; +import java.util.Comparator; + +/** + * + * @author dimgrichr + * + * Space complexity: O(n) + * Time complexity: O(nlogn), because it is a divide and conquer algorithm + */ +public class SkylineAlgorithm { + private ArrayList points; + + + /** + * Main constructor of the application. + * ArrayList points gets created, which represents the sum of all edges. + */ + public SkylineAlgorithm(){ + points = new ArrayList<>(); + } + + + /** + * @return points, the ArrayList that includes all points. + */ + public ArrayList getPoints(){ + return points; + } + + + /** + * The main divide and conquer, and also recursive algorithm. + * It gets an ArrayList full of points as an argument. + * If the size of that ArrayList is 1 or 2, + * the ArrayList is returned as it is, or with one less point + * (if the initial size is 2 and one of it's points, is dominated by the other one). + * On the other hand, if the ArrayList's size is bigger than 2, + * the function is called again, twice, + * with arguments the corresponding half of the initial ArrayList each time. + * Once the flashback has ended, the function produceFinalSkyLine gets called, + * in order to produce the final skyline, and return it. + * @param list, the initial list of points + * @return leftSkyLine, the combination of first half's and second half's skyline + * @see Point + * @see produceFinalSkyLine + */ + public ArrayList produceSubSkyLines(ArrayList list){ + + //part where function exits flashback + int size = list.size(); + if(size == 1){ + return list; + } + else if(size==2){ + if(list.get(0).dominates(list.get(1))){ + list.remove(1); + } + else{ + if(list.get(1).dominates(list.get(0))){ + list.remove(0); + } + } + return list; + } + + //recursive part of the function + ArrayList leftHalf=new ArrayList<>(); + ArrayList rightHalf=new ArrayList<>(); + for (int i=0;i leftSubSkyLine=new ArrayList<>(); + ArrayList rightSubSkyLine=new ArrayList<>(); + leftSubSkyLine=produceSubSkyLines(leftHalf); + rightSubSkyLine=produceSubSkyLines(rightHalf); + + //skyline is produced + return produceFinalSkyLine(leftSubSkyLine,rightSubSkyLine); + } + + + /** + * The first half's skyline gets cleared + * from some points that are not part of the final skyline + * (Points with same x-value and different y=values. The point with the smallest y-value is kept). + * Then, the minimum y-value of the points of first half's skyline is found. + * That helps us to clear the second half's skyline, because, the points + * of second half's skyline that have greater y-value of the minimum y-value that we found before, + * are dominated, so they are not part of the final skyline. + * Finally, the "cleaned" first half's and second half's skylines, are combined, + * producing the final skyline, which is returned. + * @param left the skyline of the left part of points + * @param right the skyline of the right part of points + * @return left the final skyline + */ + public ArrayList produceFinalSkyLine(ArrayList left, ArrayList right){ + + //dominated points of ArrayList left are removed + for(int i=0;ileft.get(i+1).y){ + left.remove(i); + i--; + } + } + + //minimum y-value is found + int min=left.get(0).y; + for(int i=1;ileft.get(i).y){ + min = left.get(i).y; + if(min==1){ + i=left.size(); + } + } + } + + //dominated points of ArrayList right are removed + for(int i=0;i=min){ + right.remove(i); + i--; + } + } + + //final skyline found and returned + left.addAll(right); + return left; + } + + + + public static class Point{ + private int x; + private int y; + /** + * The main constructor of Point Class, used to represent the 2 Dimension points. + * @param x the point's x-value. + * @param y the point's y-value. + */ + public Point(int x, int y){ + this.x=x; + this.y=y; + } + /** + * @return x, the x-value + */ + public int getX(){ + return x; + } + /** + * @return y, the y-value + */ + public int getY(){ + return y; + } + /** + * Based on the skyline theory, + * it checks if the point that calls the function dominates the argument point. + * @param p1 the point that is compared + * @return true if the point wich calls the function dominates p1 + * false otherwise. + */ + public boolean dominates(Point p1){ + + //checks if p1 is dominated + if((this.x { + @Override + public int compare(Point a, Point b) { + return a.x < b.x ? -1 : a.x == b.x ? 0 : 1; + } + } +} From 8f78a3fe6cbd79029f5213c783880b6308890132 Mon Sep 17 00:00:00 2001 From: dimgrichr <32580033+dimgrichr@users.noreply.github.com> Date: Tue, 15 Jan 2019 12:44:48 +0200 Subject: [PATCH 5/6] Delete TaskCosts.java --- Dynamic Programming/TaskCosts.java | 118 ----------------------------- 1 file changed, 118 deletions(-) delete mode 100644 Dynamic Programming/TaskCosts.java diff --git a/Dynamic Programming/TaskCosts.java b/Dynamic Programming/TaskCosts.java deleted file mode 100644 index 10e5457b626c..000000000000 --- a/Dynamic Programming/TaskCosts.java +++ /dev/null @@ -1,118 +0,0 @@ -package projectb; - -import java.io.File; -import java.io.FileNotFoundException; -import java.util.Scanner; - -/** - * - * @author dimig - */ -public class TaskCosts { - - private Scanner scanner; - private File file; - - private int tasks; - private int vms; - - private int[][] vmsPer; - private int[][] vmsCom; - private int[][] costs; - - - private TaskCosts(String nameOfInputFile) throws FileNotFoundException{ - File file = new File(nameOfInputFile); - scanner = new Scanner(file); - tasks = scanner.nextInt(); - vms = scanner.nextInt(); - costs = new int[tasks][vms]; - vmsPer = new int[tasks][vms]; - vmsCom = new int[vms][vms]; - for(int i=0;i Date: Tue, 15 Jan 2019 19:54:43 +0800 Subject: [PATCH 6/6] Update SkylineAlgorithm.java --- divideconquer/SkylineAlgorithm.java | 153 ++++++++++++++-------------- 1 file changed, 74 insertions(+), 79 deletions(-) diff --git a/divideconquer/SkylineAlgorithm.java b/divideconquer/SkylineAlgorithm.java index f1b1f44c7433..51bce90c98d2 100644 --- a/divideconquer/SkylineAlgorithm.java +++ b/divideconquer/SkylineAlgorithm.java @@ -1,36 +1,32 @@ -package skylinealgorithm; - import java.util.ArrayList; import java.util.Comparator; /** - * * @author dimgrichr - * + *

* Space complexity: O(n) * Time complexity: O(nlogn), because it is a divide and conquer algorithm */ public class SkylineAlgorithm { private ArrayList points; - - + /** * Main constructor of the application. * ArrayList points gets created, which represents the sum of all edges. */ - public SkylineAlgorithm(){ + public SkylineAlgorithm() { points = new ArrayList<>(); } - - + + /** * @return points, the ArrayList that includes all points. */ - public ArrayList getPoints(){ + public ArrayList getPoints() { return points; } - - + + /** * The main divide and conquer, and also recursive algorithm. * It gets an ArrayList full of points as an argument. @@ -38,55 +34,51 @@ public ArrayList getPoints(){ * the ArrayList is returned as it is, or with one less point * (if the initial size is 2 and one of it's points, is dominated by the other one). * On the other hand, if the ArrayList's size is bigger than 2, - * the function is called again, twice, + * the function is called again, twice, * with arguments the corresponding half of the initial ArrayList each time. * Once the flashback has ended, the function produceFinalSkyLine gets called, * in order to produce the final skyline, and return it. + * * @param list, the initial list of points * @return leftSkyLine, the combination of first half's and second half's skyline * @see Point * @see produceFinalSkyLine */ - public ArrayList produceSubSkyLines(ArrayList list){ - - //part where function exits flashback + public ArrayList produceSubSkyLines(ArrayList list) { + + // part where function exits flashback int size = list.size(); - if(size == 1){ + if (size == 1) { return list; - } - else if(size==2){ - if(list.get(0).dominates(list.get(1))){ + } else if (size == 2) { + if (list.get(0).dominates(list.get(1))) { list.remove(1); - } - else{ - if(list.get(1).dominates(list.get(0))){ + } else { + if (list.get(1).dominates(list.get(0))) { list.remove(0); } } return list; } - - //recursive part of the function - ArrayList leftHalf=new ArrayList<>(); - ArrayList rightHalf=new ArrayList<>(); - for (int i=0;i leftHalf = new ArrayList<>(); + ArrayList rightHalf = new ArrayList<>(); + for (int i = 0; i < list.size(); i++) { + if (i < list.size() / 2) { leftHalf.add(list.get(i)); - } - else{ + } else { rightHalf.add(list.get(i)); } } - ArrayList leftSubSkyLine=new ArrayList<>(); - ArrayList rightSubSkyLine=new ArrayList<>(); - leftSubSkyLine=produceSubSkyLines(leftHalf); - rightSubSkyLine=produceSubSkyLines(rightHalf); - - //skyline is produced - return produceFinalSkyLine(leftSubSkyLine,rightSubSkyLine); + ArrayList leftSubSkyLine = produceSubSkyLines(leftHalf); + ArrayList rightSubSkyLine= produceSubSkyLines(rightHalf); + + // skyline is produced + return produceFinalSkyLine(leftSubSkyLine, rightSubSkyLine); } - - + + /** * The first half's skyline gets cleared * from some points that are not part of the final skyline @@ -97,94 +89,97 @@ else if(size==2){ * are dominated, so they are not part of the final skyline. * Finally, the "cleaned" first half's and second half's skylines, are combined, * producing the final skyline, which is returned. - * @param left the skyline of the left part of points + * + * @param left the skyline of the left part of points * @param right the skyline of the right part of points * @return left the final skyline */ - public ArrayList produceFinalSkyLine(ArrayList left, ArrayList right){ - - //dominated points of ArrayList left are removed - for(int i=0;ileft.get(i+1).y){ + public ArrayList produceFinalSkyLine(ArrayList left, ArrayList right) { + + // dominated points of ArrayList left are removed + for (int i = 0; i < left.size() - 1; i++) { + if (left.get(i).x == left.get(i + 1).x && left.get(i).y > left.get(i + 1).y) { left.remove(i); i--; } } - - //minimum y-value is found - int min=left.get(0).y; - for(int i=1;ileft.get(i).y){ + + // minimum y-value is found + int min = left.get(0).y; + for (int i = 1; i < left.size(); i++) { + if (min > left.get(i).y) { min = left.get(i).y; - if(min==1){ - i=left.size(); + if (min == 1) { + i = left.size(); } } } - - //dominated points of ArrayList right are removed - for(int i=0;i=min){ + + // dominated points of ArrayList right are removed + for (int i = 0; i < right.size(); i++) { + if (right.get(i).y >= min) { right.remove(i); i--; } } - - //final skyline found and returned + + // final skyline found and returned left.addAll(right); return left; } - - - public static class Point{ + + public static class Point { private int x; private int y; + /** * The main constructor of Point Class, used to represent the 2 Dimension points. + * * @param x the point's x-value. * @param y the point's y-value. */ - public Point(int x, int y){ - this.x=x; - this.y=y; + public Point(int x, int y) { + this.x = x; + this.y = y; } + /** * @return x, the x-value */ - public int getX(){ + public int getX() { return x; } + /** * @return y, the y-value */ - public int getY(){ + public int getY() { return y; } + /** * Based on the skyline theory, * it checks if the point that calls the function dominates the argument point. + * * @param p1 the point that is compared * @return true if the point wich calls the function dominates p1 - * false otherwise. + * false otherwise. */ - public boolean dominates(Point p1){ - - //checks if p1 is dominated - if((this.x { - @Override - public int compare(Point a, Point b) { - return a.x < b.x ? -1 : a.x == b.x ? 0 : 1; - } + @Override + public int compare(Point a, Point b) { + return Integer.compare(a.x, b.x); + } } }