Advertisement
Neotank

Untitled

May 4th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.42 KB | None | 0 0
  1. package main;
  2.  
  3. import java.io.BufferedWriter;
  4. import java.io.File;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import java.text.SimpleDateFormat;
  8. import java.util.Arrays;
  9. import java.util.Date;
  10. import java.util.List;
  11.  
  12. import library.LibGraph;
  13.  
  14.  
  15. public class Main {
  16.    
  17.    
  18.  
  19.     //n
  20.     //m
  21.     //d_medio -> grau médio
  22.     //distribuição empíricas(qtd de vertices com cada grau)
  23.  
  24.    
  25.     //TODO LISTA BFS OK
  26.     //TODO Alterar BFS para retornar árvore de busca + nível(lista com duas listas)
  27.     //TODO Fazer DFS/DFT inteiro
  28.     //TODO DFT com tamanho de componente conexa e a qtd de componentes existentes
  29.     //TODO DFT com lista de vertice de cada componente >D
  30.     //TODO DFT COM ORDEM DECRESCENTE... why
  31.     //TODO Arrumar parte de graus//distribuição empirica//BFS das matrizes
  32.     //TODO Catar Library de qtd de memória utilizada
  33.     //TODO Catar library de tempo de execução OU usar famoso tick/tock
  34.     //TODO Traçar graficos das distrib empirica dos casos de uso
  35.     //TODO Arrumar saída de graus/distrib -> QQER COISA TACA NO LOOP
  36.     //TODO Fazer o output dos bagui
  37.     //TODO ->vertices, qtd arestas, grau medio, distrib empirica
  38.     //TODO ->arvore de busca, nível de cada vértice
  39.     //TODO ->qtd componentes conexos, tamanho em vertices de cada componente, lista de vertices de cada componente
  40.     //TODO ->(ordem decrescente)
  41.     /**
  42.      * Main para Lista de Adjacencias
  43.      * @param args
  44.      * @throws NumberFormatException
  45.      * @throws IOException
  46.      * @throws InterruptedException
  47.      */
  48.     public static void main(String[] args) throws NumberFormatException, IOException, InterruptedException {
  49.  
  50.         //Colocar thread para dormir para poder selecionar a thread no JVM Monitor
  51.         Thread.sleep(6000);
  52.        
  53.        
  54.         //String path = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/grafoExemploProfessor.txt";
  55.         //String nomeArquivo = "grafoExemploProfessor";
  56.         //String path = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/grafoExemploLoopDesconexo.txt";
  57.         //String nomeArquivo = "grafoExemploLoopDesconexo";
  58.         String path = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/as_graph.txt";
  59.         String nomeArquivo = "as_graph";
  60.         //String path = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/collaboration_graph.txt";
  61.         //String nomeArquivo = "collaboration_graph";
  62.        
  63.         String date = new SimpleDateFormat("yyyyMMddhhmm").format(new Date());
  64.         String OUTPUT_FILE_NAME = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/resultadoListaAdj"+nomeArquivo+date+".txt";
  65.        
  66.         //Atributos para busca pelo BFS
  67.         int buscaBFS = 5;
  68.         int verticeInicialBFS = 1;
  69.        
  70.         LibGraph lib = new LibGraph();
  71.        
  72.         long tempoInicial = System.currentTimeMillis();  
  73.         lib.lerArquivo(path);
  74.         System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
  75.        
  76.        
  77.         //Chamadas
  78.         tempoInicial = System.currentTimeMillis();  
  79.         long tempoInicialPrograma = System.currentTimeMillis();  
  80.        
  81.         List<String> arestas = lib.getArestas();
  82.         System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
  83.         tempoInicial = System.currentTimeMillis();  
  84.        
  85.         int vertices = lib.getVertices();
  86.         System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
  87.         tempoInicial = System.currentTimeMillis();
  88.        
  89.         List<List<Integer>> grafoList = lib.getListAdj(arestas, vertices);
  90.         System.out.println("o metodo getListAdj executou em " + (System.currentTimeMillis()-tempoInicial) );
  91.         tempoInicial = System.currentTimeMillis();  
  92.        
  93.         int qtdArestas = lib.getQtdArestas();
  94.         System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
  95.         tempoInicial = System.currentTimeMillis();  
  96.        
  97.         float grauMedio = lib.grauMedio(vertices, qtdArestas);
  98.         System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
  99.         tempoInicial = System.currentTimeMillis();  
  100.  
  101.         int[] graus = lib.getGraus();
  102.         System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
  103.         tempoInicial = System.currentTimeMillis();  
  104.        
  105.         float[] distEmp = lib.distribuicaoEmpirica(graus);
  106.         System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
  107.         tempoInicial = System.currentTimeMillis();  
  108.        
  109.         int bfsTest = lib.BFS(buscaBFS, grafoList, verticeInicialBFS, vertices);
  110.         System.out.println("o metodo BFS executou em " + (System.currentTimeMillis()-tempoInicial) );
  111.         tempoInicial = System.currentTimeMillis();  
  112.        
  113.         int[] pai = lib.getPai();
  114.         System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
  115.         tempoInicial = System.currentTimeMillis();  
  116.        
  117.         int[] nivelArvore = lib.getNivelArvore();
  118.         System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
  119.         tempoInicial = System.currentTimeMillis();  
  120.        
  121.         int[] componente = lib.componente(grafoList, vertices);
  122.         System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
  123.         tempoInicial = System.currentTimeMillis();  
  124.        
  125.        int qtdComponente = lib.qtdComponente(componente);
  126.         System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
  127.         tempoInicial = System.currentTimeMillis();  
  128.        
  129.        int[] tamanhoComp = lib.tamanhoComponente(componente);
  130.         System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
  131.         tempoInicial = System.currentTimeMillis();  
  132.        
  133.        List<List<Integer>> listaDecre  = lib.listaDecrescente(componente, tamanhoComp);
  134.         System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
  135.         tempoInicial = System.currentTimeMillis();  
  136.        
  137.         //Out Prints - comentados
  138. //      System.out.println("--Representacao de Lista de Adjacencias--");
  139. //      System.out.println("Arquivo de entrada: "+ path);
  140. //      System.out.println("Vértices: "+ vertices);
  141. //      System.out.println("Lista Grafos: " + grafoList.toString());
  142. //      System.out.println("Qtde Arestas: "+ qtdArestas);
  143. //      System.out.println("Grau médio: "+grauMedio);
  144. //      System.out.println("Graus: " + Arrays.toString(graus));
  145. //      System.out.println("Distrib Empirica: "+ Arrays.toString(distEmp));
  146. //      System.out.println("Distrib Empirica: "+ Arrays.toString(distEmp));
  147. //      System.out.println("Vértice Buscado pelo BFS: "+ buscaBFS);
  148. //      System.out.println("Saída Busca BFS: "+ bfsTest);
  149. //      System.out.println("Saída Pais: "+ Arrays.toString(pai));
  150. //      System.out.println("Nível Arvore: "+ Arrays.toString(nivelArvore));
  151. //      System.out.println("Vetor de Componentes:" +Arrays.toString(componente));
  152. //      System.out.println("Qtd Componentes: "+ qtdComponente);
  153. //      System.out.println("Tamanho Componentes: "+ Arrays.toString(tamanhoComp));
  154. //      System.out.println("Lista Decrescente: " + listaDecre.toString());
  155.        
  156.         //Impressão
  157.         File file = new File(OUTPUT_FILE_NAME);
  158.         if (!file.exists()) {
  159.             file.createNewFile();
  160.         }
  161.  
  162.         FileWriter fw = new FileWriter(file.getAbsoluteFile());
  163.         BufferedWriter bw = new BufferedWriter(fw);
  164.        
  165.         bw.write("--Representacao de Lista de Adjacencias--");
  166.         bw.newLine();
  167.         bw.write("Arquivo de Entrada: " + path);
  168.         bw.newLine();
  169.         bw.write("Vértices: " + vertices);
  170.         bw.newLine();
  171.         bw.write("Lista de Adjacências: " + grafoList.toString());
  172.         bw.newLine();
  173.         bw.write("Qtde Arestas: "+ qtdArestas);
  174.         bw.newLine();
  175.         bw.write("Grau médio: "+grauMedio);
  176.         bw.newLine();
  177.         bw.write("Graus: " + Arrays.toString(graus));
  178.         bw.newLine();
  179.         bw.write("Distrib Empirica: "+ Arrays.toString(distEmp));
  180.         bw.newLine();
  181.         bw.write("Vértice Buscado pelo BFS: "+ buscaBFS);
  182.         bw.newLine();
  183.         bw.write("Vértice Inicial BFS: " + verticeInicialBFS);
  184.         bw.newLine();
  185.         bw.write("Saída Busca BFS: "+ bfsTest);
  186.         bw.newLine();
  187.         bw.write("Saída Pais: "+ Arrays.toString(pai));
  188.         bw.newLine();
  189.         bw.write("Nivel Arvore: "+ Arrays.toString(nivelArvore));
  190.         bw.newLine();
  191.         bw.write("Vetor de Componentes: " +Arrays.toString(componente));
  192.         bw.newLine();
  193.         bw.write("Qtd Componentes: "+ qtdComponente);
  194.         bw.newLine();
  195.         bw.write("Tamanho Componentes: "+ Arrays.toString(tamanhoComp));
  196.         bw.newLine();
  197.         bw.write("Lista Decrescente: " + listaDecre.toString());
  198.        
  199.         bw.close();
  200.         System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
  201.         System.out.println("o programa executou em " + (System.currentTimeMillis()-tempoInicialPrograma) );
  202.  
  203.         System.out.println("Arquivo escrito em: "+ OUTPUT_FILE_NAME);
  204.        
  205.     }//end Main - Listas
  206.  
  207.    
  208.     /**
  209.      * Método Main para Matriz de Adjacencias
  210.      * @param args
  211.      * @throws NumberFormatException
  212.      * @throws IOException
  213.      * @throws InterruptedException
  214.      */
  215. //  public static void main(String[] args) throws NumberFormatException, IOException, InterruptedException {
  216. //     
  217. //      //Colocar thread para dormir para poder selecionar a thread no JVM Monitor
  218. //      Thread.sleep(10);
  219. //     
  220. //      //String path = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/grafoExemploProfessor.txt";
  221. //      //String nomeArquivo = "grafoExemploProfessor";
  222. //      //String path = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/grafoExemploLoopDesconexo.txt";
  223. //      //String nomeArquivo = "grafoExemploLoopDesconexo";
  224. //      String path = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/as_graph.txt";
  225. //      String nomeArquivo = "as_graph";
  226. //      //String path = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/collaboration_graph.txt";
  227. //      //String nomeArquivo = "collaboration_graph";
  228. //     
  229. //      String date = new SimpleDateFormat("yyyyMMddhhmm").format(new Date());
  230. //      String OUTPUT_FILE_NAME = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/resultadoMatrizAdj"+nomeArquivo+date+".txt";
  231. //     
  232. //     
  233. //      //Atributos para busca pelo BFS
  234. //      int buscaBFS = 3;
  235. //      int verticeInicialBFS = 1;
  236. //     
  237. //      LibGraph lib = new LibGraph();
  238. //      lib.lerArquivo(path);
  239. //     
  240. //      //Chamadas
  241. //      List<String> arestas = lib.getArestas();
  242. //      int vertices = lib.getVertices();
  243. //      int[][] grafoMat = lib.getMatAdj(arestas, vertices);
  244. //      int qtdArestas = lib.getQtdArestas();
  245. //      float grauMedio = lib.grauMedio(vertices, qtdArestas);
  246. //      int[] graus = lib.getGraus();
  247. //      float[] distEmp = lib.distribuicaoEmpirica(graus);
  248. //      int bfsTest = lib.BFS(buscaBFS, grafoMat, verticeInicialBFS, vertices);
  249. //      int[] pai = lib.getPai();
  250. //      int[] nivelArvore = lib.getNivelArvore();
  251. //      int[] componente = lib.componente(grafoMat, vertices);
  252. //      int qtdComponente = lib.qtdComponente(componente);
  253. //      int[] tamanhoComp = lib.tamanhoComponente(componente);
  254. //      List<List<Integer>> listaDecre  = lib.listaDecrescente(componente, tamanhoComp);
  255. //     
  256. //      //Out Prints - Comentados
  257. ////        System.out.println("--Representacao de Matriz de Adjacencias--");
  258. ////        System.out.println("Arquivo de entrada: "+ path);
  259. ////        System.out.println("Vértices: "+ vertices);
  260. ////        System.out.println("Matriz Grafos: " + Arrays.deepToString(grafoMat));
  261. ////        System.out.println("Qtde Arestas: "+ qtdArestas);
  262. ////        System.out.println("Grau médio: "+grauMedio);
  263. ////        System.out.println("Graus: " + Arrays.toString(graus));
  264. ////        System.out.println("Distrib Empirica: "+ Arrays.toString(distEmp));
  265. ////        System.out.println("Vértice Buscado pelo BFS: "+ buscaBFS);
  266. ////        System.out.println("Vértice Inicial BFS: " + verticeInicialBFS);
  267. ////        System.out.println("Saída Busca BFS: "+ bfsTest);
  268. ////        System.out.println("Saída Pais: "+ Arrays.toString(pai));
  269. ////        System.out.println("Nivel Arvore: "+ Arrays.toString(nivelArvore));
  270. ////        System.out.println("Vetor de Componentes: " +Arrays.toString(componente));
  271. ////        System.out.println("Qtd Componentes: "+ qtdComponente);
  272. ////        System.out.println("Tamanho Componentes: "+ Arrays.toString(tamanhoComp));
  273. ////        System.out.println("Lista Decrescente: " + listaDecre.toString());
  274. //     
  275. //      //Impressão
  276. //      File file = new File(OUTPUT_FILE_NAME);
  277. //      if (!file.exists()) {
  278. //          file.createNewFile();
  279. //      }
  280. //
  281. //      FileWriter fw = new FileWriter(file.getAbsoluteFile());
  282. //      BufferedWriter bw = new BufferedWriter(fw);
  283. //     
  284. //      bw.write("--Representacao de Matriz de Adjacencias--");
  285. //      bw.newLine();
  286. //      bw.write("Arquivo de Entrada: " + path);
  287. //      bw.newLine();
  288. //      bw.write("Vértices: " + vertices);
  289. //      bw.newLine();
  290. //      bw.write("Matriz Grafos: " + Arrays.deepToString(grafoMat));
  291. //      bw.newLine();
  292. //      bw.write("Qtde Arestas: "+ qtdArestas);
  293. //      bw.newLine();
  294. //      bw.write("Grau médio: "+grauMedio);
  295. //      bw.newLine();
  296. //      bw.write("Graus: " + Arrays.toString(graus));
  297. //      bw.newLine();
  298. //      bw.write("Distrib Empirica: "+ Arrays.toString(distEmp));
  299. //      bw.newLine();
  300. //      bw.write("Vértice Buscado pelo BFS: "+ buscaBFS);
  301. //      bw.newLine();
  302. //      bw.write("Vértice Inicial BFS: " + verticeInicialBFS);
  303. //      bw.newLine();
  304. //      bw.write("Saída Busca BFS: "+ bfsTest);
  305. //      bw.newLine();
  306. //      bw.write("Saída Pais: "+ Arrays.toString(pai));
  307. //      bw.newLine();
  308. //      bw.write("Nivel Arvore: "+ Arrays.toString(nivelArvore));
  309. //      bw.newLine();
  310. //      bw.write("Vetor de Componentes: " +Arrays.toString(componente));
  311. //      bw.newLine();
  312. //      bw.write("Qtd Componentes: "+ qtdComponente);
  313. //      bw.newLine();
  314. //      bw.write("Tamanho Componentes: "+ Arrays.toString(tamanhoComp));
  315. //      bw.newLine();
  316. //      bw.write("Lista Decrescente: " + listaDecre.toString());
  317. //     
  318. //      bw.close();
  319. //
  320. //      System.out.println("Arquivo escrito em: "+ OUTPUT_FILE_NAME);
  321. //
  322. //  }//end Main - Matriz
  323.  
  324. }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement