-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
executable file
·146 lines (132 loc) · 4.63 KB
/
main.c
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <stdio.h>
#include "PPI.h"
// char * ifs=" \t\n";
int main(int argc, char ** argv) {
if(argc<=2){ printf("usage: ./PPI [options] [filename]\n");return -1;}
char *path = argv[argc-1];
FILE * fp;
fp = fopen(path,"r");
struct Net net;
starNet net2;
//获得网络
int opt;
int option_index=0;
char * string="FD::S::R:d::s::B::";
static struct option long_options[] = {
{"Floyd",no_argument, NULL, 'F'},
{"Dijkstra",optional_argument, NULL, 'D' },
{"SPFA",optional_argument, NULL, 'S'},
{"Dijheap", optional_argument, NULL, 'd'},
{"starSPFA",optional_argument, NULL, 's'},
{"Bellman",optional_argument, NULL, 'B'},
};
while((opt=getopt_long(argc, argv, string, long_options, &option_index))!=-1){
if(opt == 'F') {
net = create_net(fp);
rewind(fp);
printf("Floyd\nSee the shortest path for all-pair in Floyd.txt:\n\n");
Floyd(net);
}
else if(opt == 'D'){
net = create_net(fp);
rewind(fp);
if(optarg == NULL){
printf("Dijkstra\nSee the shortest path for %s in Dijkstra.txt\n\n",net.protein[0]);
Dijkstra(net,0);
}
else {
int vs;
vs = search(optarg, net.protein, net.number);
if (vs == -1) {
printf("Protein Not Found!\n");
continue;
}
else {
printf("Dijkstra\n See the shortest path for %s in Dijkstra.txt\n\n", optarg);
Dijkstra(net, vs);
}
}
}
else if(opt == 'S'){
net = create_net(fp);
rewind(fp);
if(optarg == NULL){
printf("SPFA\nSee the shortest path for %s in SPFA.txt\n\n",net.protein[0]);
SPFA(net,0);
}
else{
int vs;
vs = search(optarg,net.protein,net.number);
if(vs==-1) {printf("Protein Not Found!\n"); continue;}
else {
printf("SPFA\n See the shortest path for %s in SPFA.txt\n\n",optarg);
SPFA(net,vs);
}
}
}
else if(opt=='R'){
int is_find = -1;
net = create_net(fp);
rewind(fp);
if(strstr(optarg,"/")!=NULL){
is_find=Dijkstra_end(net, optarg);
}
if(is_find==0){
printf("Dijkstra\n See the shortest path in Dijkstra_end.txt\n\n");
}
}
else if(opt == 'd'){
net2 = create_starnet_hash(fp);
if(optarg == NULL){
printf("Dijheap\nSee the shortest path for %s in dij_heap.txt\n\n",net2.protein[0]);
dij_heap(net2,0);
}
else {
int vs;
vs = search(optarg, net2.protein, net2.Vernum);
if (vs == -1) {
printf("Protein Not Found!\n");
continue;
}
else {
printf("Dijheap\n See the shortest path for %s in dij_heap.txt\n\n", optarg);
dij_heap(net2, vs);
}
}
}
else if(opt == 's'){
net2 = create_starnet_hash(fp);
if(optarg == NULL){
printf("starSPFA\nSee the shortest path for %s in star_SPFA.txt\n\n",net2.protein[0]);
star_SPFA(net2, 0);
}
else{
int vs;
vs = search(optarg,net2.protein,net2.Vernum);
if(vs==-1) {printf("Protein Not Found!\n"); continue;}
else {
printf("starSPFA\n See the shortest path for %s in star_SPFA.txt\n\n",optarg);
star_SPFA(net2, vs);
}
}
}
else if(opt == 'B'){
net = create_net(fp);
rewind(fp);
if(optarg == NULL){
printf("Bellman_ford\nSee the shortest path for %s in Bellman_ford.txt\n\n",net.protein[0]);
Bellman_ford(net, 0);
}
else{
int vs;
vs = search(optarg,net.protein,net.number);
if(vs==-1) {printf("Protein Not Found!\n"); continue;}
else {
printf("Bellman_ford\n See the shortest path for %s in Bellman_ford.txt\n\n",optarg);
Bellman_ford(net, vs);
}
}
}
}
return 0;
}