예제 #1
0
 @Override
 public Result run(List<Point> pointList) {
   Result result = new Result();
   for (Point startPoint : pointList) {
     this.pointList = new ArrayList<>(pointList);
     RoundResult r = calculate(startPoint);
     result.addResult(r);
     System.out.println(r.print(false));
   }
   return result;
 }
예제 #2
0
 private RoundResult calculate(Point startPoint) {
   RoundResult result = new RoundResult(startPoint);
   Point previouslyAdded = startPoint;
   pointList.remove(startPoint);
   while (!pointList.isEmpty()) {
     Point nearest = getNearestPoint(previouslyAdded);
     pointList.remove(nearest);
     result.add(nearest);
     previouslyAdded = nearest;
   }
   return result;
 }
예제 #3
0
 private static void printResult(List<Point> pointList, List<Algorithm> algorithms) {
   for (Algorithm algorithm : algorithms) {
     Result r = algorithm.run(pointList);
     r.stop();
     System.err.println(algorithm.toString());
     System.err.println("Time: " + r.getTime());
     System.err.println("Iterations: " + r.getIterationCount());
     for (RoundResult rr : r.getResultsToReport()) {
       System.err.println(rr.printResult());
     }
     //            System.out.println(r.getBestResult().print(true));
     System.err.println();
   }
 }
예제 #4
0
 private static void writeToFile(Algorithm a, RoundResult[] resultsToReport) {
   try {
     PrintWriter pw =
         new PrintWriter(
             "resources/results_"
                 + a.getClass().getSimpleName()
                 + "_"
                 + new SimpleDateFormat("yyyyMMdd_kkmm")
                     .format(new Date(System.currentTimeMillis())));
     for (RoundResult r : resultsToReport) {
       pw.println(r.toString());
     }
     pw.flush();
     pw.close();
   } catch (FileNotFoundException e) {
     System.err.println("File not found: " + e.getMessage());
     for (RoundResult r : resultsToReport) {
       System.out.println(r.toString());
     }
   }
 }