public static void main(String[] args) throws NumberFormatException, IOException { // Questao 01 System.out.println("Questao 01"); System.out.println("--------------------------------"); Grafo grafo = new LeitorDeArquivo("src/main/resources/exemploQuestao01.txt").ler(); FloydWarshall floydWarshall = new FloydWarshall(grafo); floydWarshall.computar(); System.out.println("--------------------------------"); // Questao 02 System.out.println("Questao 02"); grafo = new LeitorDeArquivo("src/main/resources/matrizQuestao02.txt").ler(); Kruskal kruskal = new Kruskal(grafo); kruskal.executar(); System.out.println("--------------------------------"); // Questao 03 System.out.println("Questao 03"); grafo = new LeitorDeArquivo("src/main/resources/exemploMatriz.txt").ler(); BellmanFord bellmanFord = new BellmanFord(grafo, 0); bellmanFord.computar(); System.out.println("Tem ciclos negativos? " + bellmanFord.temCiclosNegativos()); }
public static void main(String[] args) { BellmanFord f = new BellmanFord(); Edge[] edges = new Edge[9]; edges[0] = (new Edge(0, 1, 5)); edges[1] = (new Edge(1, 2, 1)); edges[2] = (new Edge(2, 5, 3)); edges[3] = (new Edge(0, 3, -2)); edges[4] = (new Edge(4, 3, 3)); edges[5] = (new Edge(4, 5, 10)); edges[6] = (new Edge(3, 1, 2)); edges[7] = (new Edge(2, 3, 2)); edges[8] = (new Edge(2, 4, -7)); f.findShortestPath(edges, 6, 0); f.print_result(edges, 0); }
/** * Execute multiple runs (5) for each coefficient in the "coefficients" array and store the * average online and greedy competitive ratios for each coefficient. * * @param numNodes Number of nodes/vertices in Set A. * @param dataSource Type of data source to be used. (Same dataSource values as generateSingleRun) * <pre> * output * Each line represents a coefficient * Column 1: online competitive ratio for a coefficient * Column 2: greedy competitive ratio for a coefficient * </pre> */ public static void generateChartResults(int numNodes, String dataSource) { DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); Calendar cal = Calendar.getInstance(); System.out.println("Start: " + dateFormat.format(cal.getTime())); Double[] coefficients = {1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 5.0, 10.0, 25.0}; BellmanFord bell = new BellmanFord(); ArrayList<Integer> destinationOrder = bell.permuteDestinations(numNodes); bell.generateCostMatrix(dataSource, numNodes); double offlineCost = bell.execute(numNodes, "offline", destinationOrder); double onlineGreedyCost = bell.execute(numNodes, "greedy", destinationOrder); for (int i = 0; i < coefficients.length; i++) { bell.setConstant(coefficients[i]); double competetiveRatioOnline = 0; double competetiveRatioGreedy = 0; for (int j = 0; j < 5; j++) { double onlineCost = bell.execute(numNodes, "online", destinationOrder); competetiveRatioOnline += onlineCost / offlineCost; competetiveRatioGreedy += onlineGreedyCost / offlineCost; } System.out.print(competetiveRatioOnline / 5 + "\t"); System.out.print(competetiveRatioGreedy / 5 + "\t"); System.out.println(); } cal = Calendar.getInstance(); System.out.println("End: " + dateFormat.format(cal.getTime())); }
/** * Execute a single run to compute the offline, online and greedy costs and their respective * competitive ratios. * * @param numNodes Number of nodes/vertices in Set A. * @param dataSource Type of data source to be used. * @param constant Constant multiplier to be used for better competitive ratio * <pre> * "trip_data_test.csv" - Uber Data Set * * "synthetic1D" - Random points on a 1D line where distance * between points is cost * * "synthetic2D" - Random (x,y) points on a 2D unit square space * where distance formula is cost * * "synthetic2DExample1" - (x,y) integer points 0 <= x,y < * sqrt(numNodes*2), shuffled then divided between taxis and * requests * * "synthetic2DExample2" - {@link SyntheticData#generateSynthetic2DExample2(int)} * </pre> */ public static void generateSingleRun(int numNodes, String dataSource, double constant) { DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); Calendar cal = Calendar.getInstance(); System.out.println("Start: " + dateFormat.format(cal.getTime())); // BELLMAN BellmanFord bell = new BellmanFord(); bell.setConstant(constant); bell.generateCostMatrix(dataSource, numNodes); ArrayList<Integer> destinationOrder = bell.permuteDestinations(numNodes); System.out.println("Destination Index Order: " + destinationOrder.toString()); double offlineCost = bell.execute(numNodes, "offline", destinationOrder); double onlineCost = bell.execute(numNodes, "online", destinationOrder); double onlineGreedyCost = bell.execute(numNodes, "greedy", destinationOrder); System.out.println("OFFLINE COST: " + offlineCost); System.out.println("ONLINE COST: " + onlineCost); System.out.println("GREEDY COST: " + onlineGreedyCost); double onlineCompetetiveRatio = onlineCost / offlineCost; double greedyCompetetiveRatio = onlineGreedyCost / offlineCost; System.out.println("Competitive Ratio between online and offline: " + onlineCompetetiveRatio); System.out.println( "Competitive Ratio between greedy online and offline: " + greedyCompetetiveRatio); // HUNGARIAN // double hungarianCost = bell.execute(numNodes, "hungarian", // destinationOrder); // System.out.println("HUNGARIAN COST: " + hungarianCost); cal = Calendar.getInstance(); System.out.println("End: " + dateFormat.format(cal.getTime())); }