-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.java
More file actions
87 lines (82 loc) · 2.86 KB
/
Graph.java
File metadata and controls
87 lines (82 loc) · 2.86 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.FileNotFoundException;
import java.util.Scanner;
import representation.*;
import search.*;
import disjoint.*;
public class Graph {
public static Scanner sc = new Scanner(System.in);
public static int op;
public static String fileOp, activity, rep;
public static String smallFile = "run-files/graph-test-100.txt";
public static String largeFile = "run-files/graph-test-50000.txt";
public static String tinyFile = "run-files/graph-test-5.txt";
public static void main(String[] args) throws FileNotFoundException {
if(args.length == 1 && args[0].equals("-h")) {
System.err.println("Usage: java Graph [0] [1] [2]");
System.err.println("[0] graph file: -t to tiny file; -s to small file; -l to large file");
System.err.println("[1] action: -r to representation; -s to search; -d to disjoint path");
System.err.println("[2] type of representation: -i to inverse matrix; -a to adjacence matrix; -r to reverse star");
return;
}
else if(args.length != 3) {
System.err.println("Arguments out of bounds. 3 arguments expected but " + args.length + " was given.");
System.err.println("Type \" java Graph -h\" to show commands");
return;
} else {
fileOp = args[0];
activity = args[1];
rep = args[2];
switch(fileOp) {
case "-s": fileOp = smallFile;
break;
case "-l": fileOp = largeFile;
break;
case "-t": fileOp = tinyFile;
break;
default: System.err.println("Command [0] not found.");
System.err.println("Type \" java Graph -h\" to show commands");
return;
}
switch(activity) {
case "-r":
IncidenceMatrix im;
AdjacenceMatrix am;
ReverseStar rs;
if (rep.equals("-i")) {
im = new IncidenceMatrix(fileOp);
im.printInfo();
}
else if (rep.equals("-a")) {
am = new AdjacenceMatrix(fileOp);
am.printInfo();
}
else if (rep.equals("-r")) {
rs = new ReverseStar(fileOp);
rs.getVertex();
rs.getVertexPredecessor();
}
else {
System.err.println("Command [2] not found.");
System.err.println("Type \" java Graph -h\" to show commands");
return;
}
break;
case "-s":
DepthFirstSearch dfs = new DepthFirstSearch(fileOp);
dfs.print();
System.out.println("Choose a vertex: ");
op = sc.nextInt();
dfs.printArcs(op);
break;
case "-d":
DisjointPath dp = new DisjointPath(fileOp);
dp.print();
break;
default: System.err.println("Command [1] not found");
System.err.println("Type \" java Graph -h\" to show commands");
return;
}
sc.close();
}
}
}