-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
87 lines (66 loc) · 2.78 KB
/
Main.java
File metadata and controls
87 lines (66 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.io.*;
import java.util.Scanner;
class Main {
public static void main(String[] args) throws IOException {
Boolean condition = true;
Scanner scan = new Scanner(System.in);
while (condition) {
System.out.println("Informe a tarefa:");
System.out.println("\t 1 - Caminho Mínimo");
System.out.println("\t 2 - Labirinto");
System.out.println("\t 3 - Sair");
int option = scan.nextInt();
if (option == 1) {
System.out.print("Arquivo:");
String arquivo = scan.next();
System.out.print("Algoritmo:");
System.out.println("\n\t 1 - Dijkstra - Não funcional");
System.out.println("\t 2 - Bellman-Ford");
System.out.println("\t 3 - Bellman-Ford Melhorado");
System.out.println("\t 4 - Floyd-Warshall");
int alg = scan.nextInt();
System.out.print("Origem:");
int origem = scan.nextInt();
System.out.print("Destino:");
int destino = scan.nextInt();
if(alg == 1){
long startTime = System.nanoTime();
GraphMatrix g1 = new GraphMatrix(arquivo);
g1.dijkstra(origem);
long endTime = System.nanoTime();
long timeElapsed = endTime - startTime;
System.out.println("Tempo: " + timeElapsed / 1000000000 +" seg");;
}
if(alg == 2 || alg == 3){
long startTime = System.nanoTime();
GraphMatrix g1 = new GraphMatrix(arquivo);
g1.BellmanFord(origem,destino);
long endTime = System.nanoTime();
long timeElapsed = endTime - startTime;
System.out.println("Tempo: " + timeElapsed / 1000000000 +" seg"); }
if(alg == 4){
long startTime = System.nanoTime();
GraphMatrix g1 = new GraphMatrix(arquivo);
g1.floydWarshal(origem,destino);
long endTime = System.nanoTime();
long timeElapsed = endTime - startTime;
System.out.println("Tempo: " + timeElapsed / 1000000000 +" seg"); }
}
if (option == 2) {
System.out.print("Arquivo:");
String arquivo = scan.next();
System.out.println("\nO arquivo selecionado foi: " +arquivo + ", ainda não é possível realizar essa execução. Estamos trabalhando nisso!");
}
if (option == 3) {
condition = false;
}
}
GraphMatrix g2 = new GraphMatrix("graph2.txt");
System.out.println(g2);
g2.floydWarshal(0, 1);
Graph g3 = new Graph("graph2.txt");
GraphMatrix g4 = new GraphMatrix("cm/toy.txt");
System.out.println(g4);
g4.BellmanFord(0,3);
}
}