public static void main(String[] args) throws IOException { long timeMillis = System.currentTimeMillis(); List<Point> pointList = parseToPoints(readFromFile("resources/data.tsp")); // List<Algorithm> algorithms = firstLab(); // List<Algorithm> algorithms = secondLab(); // List<Algorithm> algorithms = thirdLab(getTimeLimit(pointList)); List<Algorithm> algorithms = forthLab(getTimeLimit(pointList)); printResult(pointList, algorithms); System.out.println(System.currentTimeMillis() - timeMillis); }
public static List<Point> parseToPoints(String data) { List<Point> points = new ArrayList<>(); for (String line : data.split(System.lineSeparator())) { points.add(new Point(line)); } return points; }
public static String readFromFile(String fileName) throws IOException { BufferedReader br = new BufferedReader(new FileReader(fileName)); try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); boolean start = false; while (line != null) { if (line.equals("EOF")) { start = false; } if (start) { sb.append(line); sb.append(System.lineSeparator()); } if (line.equals("NODE_COORD_SECTION")) { start = true; } line = br.readLine(); } return sb.toString(); } catch (IOException e) { e.printStackTrace(); } finally { br.close(); } return null; }
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()); } } }