Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.text.SimpleDateFormat;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.List;
- import library.LibGraph;
- public class Main {
- //n
- //m
- //d_medio -> grau médio
- //distribuição empíricas(qtd de vertices com cada grau)
- //TODO LISTA BFS OK
- //TODO Alterar BFS para retornar árvore de busca + nível(lista com duas listas)
- //TODO Fazer DFS/DFT inteiro
- //TODO DFT com tamanho de componente conexa e a qtd de componentes existentes
- //TODO DFT com lista de vertice de cada componente >D
- //TODO DFT COM ORDEM DECRESCENTE... why
- //TODO Arrumar parte de graus//distribuição empirica//BFS das matrizes
- //TODO Catar Library de qtd de memória utilizada
- //TODO Catar library de tempo de execução OU usar famoso tick/tock
- //TODO Traçar graficos das distrib empirica dos casos de uso
- //TODO Arrumar saída de graus/distrib -> QQER COISA TACA NO LOOP
- //TODO Fazer o output dos bagui
- //TODO ->vertices, qtd arestas, grau medio, distrib empirica
- //TODO ->arvore de busca, nível de cada vértice
- //TODO ->qtd componentes conexos, tamanho em vertices de cada componente, lista de vertices de cada componente
- //TODO ->(ordem decrescente)
- /**
- * Main para Lista de Adjacencias
- * @param args
- * @throws NumberFormatException
- * @throws IOException
- * @throws InterruptedException
- */
- public static void main(String[] args) throws NumberFormatException, IOException, InterruptedException {
- //Colocar thread para dormir para poder selecionar a thread no JVM Monitor
- Thread.sleep(6000);
- //String path = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/grafoExemploProfessor.txt";
- //String nomeArquivo = "grafoExemploProfessor";
- //String path = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/grafoExemploLoopDesconexo.txt";
- //String nomeArquivo = "grafoExemploLoopDesconexo";
- String path = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/as_graph.txt";
- String nomeArquivo = "as_graph";
- //String path = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/collaboration_graph.txt";
- //String nomeArquivo = "collaboration_graph";
- String date = new SimpleDateFormat("yyyyMMddhhmm").format(new Date());
- String OUTPUT_FILE_NAME = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/resultadoListaAdj"+nomeArquivo+date+".txt";
- //Atributos para busca pelo BFS
- int buscaBFS = 5;
- int verticeInicialBFS = 1;
- LibGraph lib = new LibGraph();
- long tempoInicial = System.currentTimeMillis();
- lib.lerArquivo(path);
- System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
- //Chamadas
- tempoInicial = System.currentTimeMillis();
- long tempoInicialPrograma = System.currentTimeMillis();
- List<String> arestas = lib.getArestas();
- System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
- tempoInicial = System.currentTimeMillis();
- int vertices = lib.getVertices();
- System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
- tempoInicial = System.currentTimeMillis();
- List<List<Integer>> grafoList = lib.getListAdj(arestas, vertices);
- System.out.println("o metodo getListAdj executou em " + (System.currentTimeMillis()-tempoInicial) );
- tempoInicial = System.currentTimeMillis();
- int qtdArestas = lib.getQtdArestas();
- System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
- tempoInicial = System.currentTimeMillis();
- float grauMedio = lib.grauMedio(vertices, qtdArestas);
- System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
- tempoInicial = System.currentTimeMillis();
- int[] graus = lib.getGraus();
- System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
- tempoInicial = System.currentTimeMillis();
- float[] distEmp = lib.distribuicaoEmpirica(graus);
- System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
- tempoInicial = System.currentTimeMillis();
- int bfsTest = lib.BFS(buscaBFS, grafoList, verticeInicialBFS, vertices);
- System.out.println("o metodo BFS executou em " + (System.currentTimeMillis()-tempoInicial) );
- tempoInicial = System.currentTimeMillis();
- int[] pai = lib.getPai();
- System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
- tempoInicial = System.currentTimeMillis();
- int[] nivelArvore = lib.getNivelArvore();
- System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
- tempoInicial = System.currentTimeMillis();
- int[] componente = lib.componente(grafoList, vertices);
- System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
- tempoInicial = System.currentTimeMillis();
- int qtdComponente = lib.qtdComponente(componente);
- System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
- tempoInicial = System.currentTimeMillis();
- int[] tamanhoComp = lib.tamanhoComponente(componente);
- System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
- tempoInicial = System.currentTimeMillis();
- List<List<Integer>> listaDecre = lib.listaDecrescente(componente, tamanhoComp);
- System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
- tempoInicial = System.currentTimeMillis();
- //Out Prints - comentados
- // System.out.println("--Representacao de Lista de Adjacencias--");
- // System.out.println("Arquivo de entrada: "+ path);
- // System.out.println("Vértices: "+ vertices);
- // System.out.println("Lista Grafos: " + grafoList.toString());
- // System.out.println("Qtde Arestas: "+ qtdArestas);
- // System.out.println("Grau médio: "+grauMedio);
- // System.out.println("Graus: " + Arrays.toString(graus));
- // System.out.println("Distrib Empirica: "+ Arrays.toString(distEmp));
- // System.out.println("Distrib Empirica: "+ Arrays.toString(distEmp));
- // System.out.println("Vértice Buscado pelo BFS: "+ buscaBFS);
- // System.out.println("Saída Busca BFS: "+ bfsTest);
- // System.out.println("Saída Pais: "+ Arrays.toString(pai));
- // System.out.println("Nível Arvore: "+ Arrays.toString(nivelArvore));
- // System.out.println("Vetor de Componentes:" +Arrays.toString(componente));
- // System.out.println("Qtd Componentes: "+ qtdComponente);
- // System.out.println("Tamanho Componentes: "+ Arrays.toString(tamanhoComp));
- // System.out.println("Lista Decrescente: " + listaDecre.toString());
- //Impressão
- File file = new File(OUTPUT_FILE_NAME);
- if (!file.exists()) {
- file.createNewFile();
- }
- FileWriter fw = new FileWriter(file.getAbsoluteFile());
- BufferedWriter bw = new BufferedWriter(fw);
- bw.write("--Representacao de Lista de Adjacencias--");
- bw.newLine();
- bw.write("Arquivo de Entrada: " + path);
- bw.newLine();
- bw.write("Vértices: " + vertices);
- bw.newLine();
- bw.write("Lista de Adjacências: " + grafoList.toString());
- bw.newLine();
- bw.write("Qtde Arestas: "+ qtdArestas);
- bw.newLine();
- bw.write("Grau médio: "+grauMedio);
- bw.newLine();
- bw.write("Graus: " + Arrays.toString(graus));
- bw.newLine();
- bw.write("Distrib Empirica: "+ Arrays.toString(distEmp));
- bw.newLine();
- bw.write("Vértice Buscado pelo BFS: "+ buscaBFS);
- bw.newLine();
- bw.write("Vértice Inicial BFS: " + verticeInicialBFS);
- bw.newLine();
- bw.write("Saída Busca BFS: "+ bfsTest);
- bw.newLine();
- bw.write("Saída Pais: "+ Arrays.toString(pai));
- bw.newLine();
- bw.write("Nivel Arvore: "+ Arrays.toString(nivelArvore));
- bw.newLine();
- bw.write("Vetor de Componentes: " +Arrays.toString(componente));
- bw.newLine();
- bw.write("Qtd Componentes: "+ qtdComponente);
- bw.newLine();
- bw.write("Tamanho Componentes: "+ Arrays.toString(tamanhoComp));
- bw.newLine();
- bw.write("Lista Decrescente: " + listaDecre.toString());
- bw.close();
- System.out.println("o metodo executou em " + (System.currentTimeMillis()-tempoInicial) );
- System.out.println("o programa executou em " + (System.currentTimeMillis()-tempoInicialPrograma) );
- System.out.println("Arquivo escrito em: "+ OUTPUT_FILE_NAME);
- }//end Main - Listas
- /**
- * Método Main para Matriz de Adjacencias
- * @param args
- * @throws NumberFormatException
- * @throws IOException
- * @throws InterruptedException
- */
- // public static void main(String[] args) throws NumberFormatException, IOException, InterruptedException {
- //
- // //Colocar thread para dormir para poder selecionar a thread no JVM Monitor
- // Thread.sleep(10);
- //
- // //String path = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/grafoExemploProfessor.txt";
- // //String nomeArquivo = "grafoExemploProfessor";
- // //String path = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/grafoExemploLoopDesconexo.txt";
- // //String nomeArquivo = "grafoExemploLoopDesconexo";
- // String path = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/as_graph.txt";
- // String nomeArquivo = "as_graph";
- // //String path = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/collaboration_graph.txt";
- // //String nomeArquivo = "collaboration_graph";
- //
- // String date = new SimpleDateFormat("yyyyMMddhhmm").format(new Date());
- // String OUTPUT_FILE_NAME = "C:/Users/Francisco/workspaceDescente/GrafosT1FranciscoWalter/files/resultadoMatrizAdj"+nomeArquivo+date+".txt";
- //
- //
- // //Atributos para busca pelo BFS
- // int buscaBFS = 3;
- // int verticeInicialBFS = 1;
- //
- // LibGraph lib = new LibGraph();
- // lib.lerArquivo(path);
- //
- // //Chamadas
- // List<String> arestas = lib.getArestas();
- // int vertices = lib.getVertices();
- // int[][] grafoMat = lib.getMatAdj(arestas, vertices);
- // int qtdArestas = lib.getQtdArestas();
- // float grauMedio = lib.grauMedio(vertices, qtdArestas);
- // int[] graus = lib.getGraus();
- // float[] distEmp = lib.distribuicaoEmpirica(graus);
- // int bfsTest = lib.BFS(buscaBFS, grafoMat, verticeInicialBFS, vertices);
- // int[] pai = lib.getPai();
- // int[] nivelArvore = lib.getNivelArvore();
- // int[] componente = lib.componente(grafoMat, vertices);
- // int qtdComponente = lib.qtdComponente(componente);
- // int[] tamanhoComp = lib.tamanhoComponente(componente);
- // List<List<Integer>> listaDecre = lib.listaDecrescente(componente, tamanhoComp);
- //
- // //Out Prints - Comentados
- //// System.out.println("--Representacao de Matriz de Adjacencias--");
- //// System.out.println("Arquivo de entrada: "+ path);
- //// System.out.println("Vértices: "+ vertices);
- //// System.out.println("Matriz Grafos: " + Arrays.deepToString(grafoMat));
- //// System.out.println("Qtde Arestas: "+ qtdArestas);
- //// System.out.println("Grau médio: "+grauMedio);
- //// System.out.println("Graus: " + Arrays.toString(graus));
- //// System.out.println("Distrib Empirica: "+ Arrays.toString(distEmp));
- //// System.out.println("Vértice Buscado pelo BFS: "+ buscaBFS);
- //// System.out.println("Vértice Inicial BFS: " + verticeInicialBFS);
- //// System.out.println("Saída Busca BFS: "+ bfsTest);
- //// System.out.println("Saída Pais: "+ Arrays.toString(pai));
- //// System.out.println("Nivel Arvore: "+ Arrays.toString(nivelArvore));
- //// System.out.println("Vetor de Componentes: " +Arrays.toString(componente));
- //// System.out.println("Qtd Componentes: "+ qtdComponente);
- //// System.out.println("Tamanho Componentes: "+ Arrays.toString(tamanhoComp));
- //// System.out.println("Lista Decrescente: " + listaDecre.toString());
- //
- // //Impressão
- // File file = new File(OUTPUT_FILE_NAME);
- // if (!file.exists()) {
- // file.createNewFile();
- // }
- //
- // FileWriter fw = new FileWriter(file.getAbsoluteFile());
- // BufferedWriter bw = new BufferedWriter(fw);
- //
- // bw.write("--Representacao de Matriz de Adjacencias--");
- // bw.newLine();
- // bw.write("Arquivo de Entrada: " + path);
- // bw.newLine();
- // bw.write("Vértices: " + vertices);
- // bw.newLine();
- // bw.write("Matriz Grafos: " + Arrays.deepToString(grafoMat));
- // bw.newLine();
- // bw.write("Qtde Arestas: "+ qtdArestas);
- // bw.newLine();
- // bw.write("Grau médio: "+grauMedio);
- // bw.newLine();
- // bw.write("Graus: " + Arrays.toString(graus));
- // bw.newLine();
- // bw.write("Distrib Empirica: "+ Arrays.toString(distEmp));
- // bw.newLine();
- // bw.write("Vértice Buscado pelo BFS: "+ buscaBFS);
- // bw.newLine();
- // bw.write("Vértice Inicial BFS: " + verticeInicialBFS);
- // bw.newLine();
- // bw.write("Saída Busca BFS: "+ bfsTest);
- // bw.newLine();
- // bw.write("Saída Pais: "+ Arrays.toString(pai));
- // bw.newLine();
- // bw.write("Nivel Arvore: "+ Arrays.toString(nivelArvore));
- // bw.newLine();
- // bw.write("Vetor de Componentes: " +Arrays.toString(componente));
- // bw.newLine();
- // bw.write("Qtd Componentes: "+ qtdComponente);
- // bw.newLine();
- // bw.write("Tamanho Componentes: "+ Arrays.toString(tamanhoComp));
- // bw.newLine();
- // bw.write("Lista Decrescente: " + listaDecre.toString());
- //
- // bw.close();
- //
- // System.out.println("Arquivo escrito em: "+ OUTPUT_FILE_NAME);
- //
- // }//end Main - Matriz
- }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement