Advertisement
Guest User

Untitled

a guest
May 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.60 KB | None | 0 0
  1. // Behram Dossabhoy and Holland Wolf
  2. // 15 May 2019
  3. // CampusRecycling: A program that designs an efficient way to handle how recyclers pick up recycling bins.
  4.  
  5. import jdk.swing.interop.SwingInterOpUtils;
  6.  
  7. import java.util.Scanner;
  8. import java.io.*;
  9.  
  10. public class Main
  11. {
  12.     public static void main(String[] args) throws FileNotFoundException
  13.     {
  14.         Graph<String> map = new Graph<>();
  15.         File vertices = new File("src//vertices.csv");
  16.         Scanner verticesInput = new Scanner(vertices);
  17.         String[] vertex = verticesInput.nextLine().split(", ");
  18.         for (String s : vertex)
  19.             map.addVertex(s);
  20.  
  21.         map.makeAdjMat(vertex.length);
  22.         File edges = new File("src//edges.csv");
  23.         Scanner edgesInput = new Scanner(edges);
  24.         while (edgesInput.hasNextLine())
  25.         {
  26.             String currentEdge = edgesInput.nextLine();
  27.             String[] edge = currentEdge.split(", ");
  28.             Vertex origin = map.findVertex(edge[0]);
  29.             Vertex destination = map.findVertex(edge[1]);
  30.             float weight = Float.parseFloat(edge[2]);
  31.             map.addEdge(origin, destination, weight);
  32.         }
  33.  
  34.         Scanner userInput = new Scanner(System.in);
  35.         System.out.println("Which building would you like to start from? ");
  36.         String input = userInput.nextLine();
  37.         Vertex<String> startingVertex = map.findVertex(input);
  38.  
  39.         if (startingVertex != null)
  40.         {
  41.             map.DFS(map, startingVertex);
  42.             System.out.println();
  43.             System.out.println();
  44.  
  45.             map.BFS(map, startingVertex);
  46.             System.out.println();
  47.             System.out.println();
  48.  
  49.             long startTimeDijkstra = System.currentTimeMillis();
  50.             map.dijkstra(map, startingVertex);
  51.             System.out.println();
  52.             long endTimeDijkstra = System.currentTimeMillis();
  53.             long elapsedTimeDijkstra = endTimeDijkstra - startTimeDijkstra;
  54.             System.out.println("The Dijkstra Algorithm took " + elapsedTimeDijkstra + " ms.");
  55.             System.out.println();
  56.             System.out.println();
  57.  
  58.             long startTimePrim = System.currentTimeMillis();
  59.             map.primMST(map, startingVertex);
  60.             System.out.println();
  61.             long endTimePrim = System.currentTimeMillis();
  62.             long elapsedTimePrim = endTimePrim - startTimePrim;
  63.             System.out.println("The Dijkstra Algorithm took " + elapsedTimePrim + " ms.");
  64.             System.out.println();
  65.             System.out.println();
  66.  
  67.         }
  68.  
  69.         else System.out.println("Error");
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement