-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.c
executable file
·200 lines (184 loc) · 6.59 KB
/
search.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#include "mainLSH.h"
#include "mainCube.h"
#define FILTERING_E 0.1
void printOptions(){
printf("_________________Options____________________\n\n");
printf("1. /repeat <new_query_file> <output file> <algorithm> <metric>\n\n");
printf("2. /exit\n\n");
printf("_____________________________________\n\n");
}
char *distanceMetric;
int main(int argc, char *argv[]) {
char str[200];
char inputFile[100];
int inputflag=0;
char queryFile[100];
int queryflag=0;
char outputFile[100];
char algorithm[100];
char metric[100];
int m=10;
double delta=1;
int outputflag=0;
int l=5;
int k_LSH = 4;
int new_dimension = 14;
int probes=2;
int distanceTrueOff = 0;
for(int i = 1 ; i < argc ; i++){
strcpy(str,argv[i]);
if(strcmp(str,"-i")==0 && (argc > i+1)){
inputflag++;
strcpy(inputFile,argv[i+1]);
printf("Given input File : %s\n", inputFile);
}
else if(strcmp(str,"-q")==0 && (argc > i+1)){
queryflag++;
strcpy(queryFile,argv[i+1]);
printf("Given query File : %s\n", queryFile);
}
else if(strcmp(str,"-k")==0 && (argc > i+1)){
k_LSH=atoi(argv[i+1]);
new_dimension = k_LSH;
printf("k : %d\n", k_LSH);
}
else if(strcmp(str,"-L")==0 && (argc > i+1)){
l=atoi(argv[i+1]);
printf("L : %d\n", l);
}
else if(strcmp(str,"-o")==0 && (argc > i+1)){
outputflag++;
strcpy(outputFile,argv[i+1]);
printf("Given output File : %s\n", outputFile);
}
else if(strcmp(str,"-algorithm")==0 && (argc > i+1)){
strcpy(algorithm,argv[i+1]);
printf("Given algorithm : %s\n", algorithm);
}
else if(strcmp(str,"-metric")==0 && (argc > i+1)){
strcpy(metric,argv[i+1]);
printf("Given metric: %s\n", metric);
}
else if(strcmp(str,"-delta")==0 && (argc > i+1)){
delta=atof(argv[i+1]);
printf("Delta: %f\n", delta);
}
else if(strcmp(str,"-probes")==0 && (argc > i+1)){
probes=atoi(argv[i+1]);
printf("probes : %d\n", probes);
}
else if(strcmp(str,"-M")==0 && (argc > i+1)){
m=atoi(argv[i+1]);
printf("M : %d\n", m);
}
else if(strcmp(str,"-distanceTrueOff")==0){
distanceTrueOff=1;
printf("distanceTrueOff : Enabled\n");
}
}
if(!inputflag){
printf(">Input file name: ");
fflush(stdin); // clear stdin buffer
if (fgets(str, sizeof(char)*200, stdin) == NULL) { // read a command
perror("Error reading string with fgets\n");
exit(1);
}
strcpy(inputFile,str);
printf("Given input File : %s\n", inputFile);
}
if(!queryflag){
printf(">Query file name: ");
fflush(stdin); // clear stdin buffer
if (fgets(str, sizeof(char)*200, stdin) == NULL) { // read a command
perror("Error reading string with fgets\n");
exit(1);
}
strcpy(queryFile,str);
printf("Given query File : %s\n", queryFile);
}
if(!outputflag){
printf(">Output file name: ");
fflush(stdin); // clear stdin buffer
if (fgets(str, sizeof(char)*200, stdin) == NULL) { // read a command
perror("Error reading string with fgets\n");
exit(1);
}
strcpy(outputFile,str);
printf("Given output File : %s\n", outputFile);
}
srand(time(NULL));
char command[100];
int repeat=1;
while(1){
if(repeat){
if(strcmp(algorithm,"LSH")==0){ // if LSH was given as algorithm
distanceMetric=malloc(sizeof(char)*(strlen("l2")+1)); // set distance metric to l2
strcpy(distanceMetric,"l2");
fprintf(stdout,"Algorithm: LSH\n");
vectorTimeSeriesLSH(inputFile,queryFile,k_LSH,l,outputFile,distanceTrueOff); // call the correspoding function of LSH/lsh.c file
}
else if(strcmp(algorithm,"Hypercube")==0){ // if Hypercube was given as algorithm
distanceMetric=malloc(sizeof(char)*(strlen("l2")+1)); // set distance metric to l2
strcpy(distanceMetric,"l2");
fprintf(stdout,"Algorithm: LSH\n");
vectorTimeSeriesHypecube(inputFile,queryFile,new_dimension,m,probes,outputFile,distanceTrueOff); // call the correspoding function of LSH/lsh.c file
}
else if(strcmp(algorithm,"Frechet")==0){ // if Frechet was given as algorithm
if(strcmp(metric,"discrete")==0){ // if Frechet was given as algorithm and Discrete as metric
distanceMetric=malloc(sizeof(char)*(strlen("discreteFrechet")+1)); // set distance metric to discrete frechet
strcpy(distanceMetric,"discreteFrechet");
fprintf(stdout,"Algorithm: Frechet Discrece\n");
vectorTimeSeriesLSHFrechetDiscrete(inputFile,queryFile,k_LSH,l,outputFile,delta,distanceTrueOff); // call the correspoding function of LSH/lsh.c file
}
else if(strcmp(metric,"continuous")==0){ // if Frechet was given as algorithm and Continuous as metric
distanceMetric=malloc(sizeof(char)*(strlen("continuousFrechet")+1)); // set distance metric to continuous frechet
strcpy(distanceMetric,"continuousFrechet");
fprintf(stdout,"Algorithm: Frechet Continuous\n");
vectorTimeSeriesLSHFrechetContinuous(inputFile,queryFile,k_LSH,outputFile,delta,FILTERING_E,distanceTrueOff); // call the correspoding function of LSH/lsh.c file
}
else{
printf("WRONG METRIC, %s\n",metric);
}
}
else{
printf("%s\n",algorithm);
printf("INVALID Algorithm NAME!\n");
exit(EXIT_FAILURE);
}
free(distanceMetric);
}
repeat=0;
printOptions(); // just printing the commands options for the user
printf("\n");
printf(">Enter a command: ");
fflush(stdin); // clear stdin buffer
if (fgets(str, sizeof(char)*200, stdin) == NULL) { // read a command
perror("Error reading string with fgets\n");
exit(1);
}
else if(strstr(str, "/repeat") != NULL) {
repeat=1;
sscanf(str,"%s %s %s %s %s\n",command,queryFile,outputFile,algorithm,metric);
printf("query File: %s\n",queryFile);
printf("output File: %s\n",outputFile);
printf("algorithm: %s\n",algorithm);
printf("metric: %s\n",metric);
continue;
}
else if(strcmp(str,"/exit\n")==0){
break;
}
else{
printf("\n\n --- Wrong command ! Please, try again. --- \n\n");
printOptions(); // just printing the commands options for the user
continue;
}
}
return 0;
}