-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster.c
238 lines (180 loc) · 7.03 KB
/
cluster.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//
// cluster.c
//
// Christina-Theano Kylafi
// AM: 1115201200077
#include "cluster.h"
int clustering_recommendation(struct cluster* clusters[], struct multipoints* MpointsList, char* outputfile, int metric, int init, int assign, int update, int dimension_of_coords, long long totalpoints_in, int clusters_from_recom)
{
//rand seed for later
struct timeval time;
gettimeofday(&time,NULL);
srand((time.tv_sec * 1000) + (time.tv_usec / 1000));
// char inputfile[40];
// memset((void*)inputfile, 0, 40*sizeof(char));
// int inputflag = 0;
// char configfile[40];
// memset((void*)configfile, 0, 40*sizeof(char));
// int configflag = 0;
// char outputfile[40];
// memset((void*)outputfile, 0, 40*sizeof(char));
// int outputflag = 0;
//int metric = -9; //1 for euclidean, 2 for cosine
int clusters_num = clusters_from_recom;
int hfuns_num = hfuns_num_def;
int hashtables_num = hashtables_num_def;
int complete_print = 0; //if user wants to print all the items of clusters to the outputfile
//init values!!!!
//read_config_file(&clusters_num, &hfuns_num, &hashtables_num, configfile);
// int check_pars = 0;
// if((check_pars = init_params(argc, argv, &inputflag, inputfile, &configflag, configfile, &outputflag, outputfile, &metric, &clusters_num, &hfuns_num, &hashtables_num, &complete_print))==-99)
// {
// print_msg_centre_line("CLUSTERIN' OUT!!");
// printf("\n\n");
// return -999;
// }
//printf("\nComplete_print : %d\n", complete_print );
if(print_msgs_on == 1)
print_welcome_msg();
// int init = -9;
// int assign = -9;
// int update = -9;
// int answer = 1;
// //answer = choose_algos(&init, &assign, &update); //user input on algorithms - y/n - if y: choose each one
// if (!answer) //will try all algorithms
// {
// print_msg_centre("Starting the process...");
// print_msg_centre_line("12 combinations will be tried out");
// // print_msg_centre_line("will be tried out");
// }
// else if(answer == -99)
// {
// print_msg_centre_line("CLUSTERIN' OUT!!");
// printf("\n\n");
// return -999;
// }
// else
// {
if(print_msgs_on == 1)
print_msg_centre("Clusterin: Starting the process...");
// printf("\n");
// }
//printf("\n\n");
//struct multipoints* MpointsList = NULL;
int dimension = dimension_of_coords;
//printf("\nDimension: %d", dimension);
//MpointsList = multiPointList_init(dimension);
//point_num_type totalpoints_in = 0;
//save_points(MpointsList, inputfile, &totalpoints_in, dimension ); //save points of input dataset
//printList(MpointsList);
//struct cluster* clusters[1]; //the structure of clusters
//clusters[0] = malloc( clusters_num * get_size_cluster());
//clusters_init(clusters_num, clusters);
FILE* temp = NULL;
temp = fopen(outputfile, "w+");
fclose(temp);
struct results* temp_res = NULL;
//int dimension_of_coords = d;
//if (answer > 0) //user's choice
//{
temp_res = users_choice(MpointsList, clusters, init, assign, update, outputfile, totalpoints_in, clusters_num, hfuns_num, hashtables_num, metric, complete_print, dimension_of_coords);
free(temp_res); //results in case of user's choice don't have a meaning so i free it immediately
//}
// else if(!answer) //12 combinations - when the user doesn't choose a certain combination
// {
// all_combinations(MpointsList, clusters, outputfile, clusters_num, totalpoints_in, hfuns_num, hashtables_num, metric, complete_print, dimension_of_coords);
// }
//deletes - free memory
//delete_all(MpointsList, clusters, clusters_num);
if(print_msgs_on == 1)
print_msg_centre_line(" CLUSTERin' OUT ! ");
//printf("\n\n");
return 999;
}
int clustering(struct cluster* clusters[], char* inputfile, char* configfile, char* outputfile, int metric, int init, int assign, int update, int dimension_of_coords)
{
//rand seed for later
struct timeval time;
gettimeofday(&time,NULL);
srand((time.tv_sec * 1000) + (time.tv_usec / 1000));
// char inputfile[40];
// memset((void*)inputfile, 0, 40*sizeof(char));
// int inputflag = 0;
// char configfile[40];
// memset((void*)configfile, 0, 40*sizeof(char));
// int configflag = 0;
// char outputfile[40];
// memset((void*)outputfile, 0, 40*sizeof(char));
// int outputflag = 0;
//int metric = -9; //1 for euclidean, 2 for cosine
int clusters_num = clusters_for_representatives;
int hfuns_num = hfuns_num_def;
int hashtables_num = hashtables_num_def;
int complete_print = 0; //if user wants to print all the items of clusters to the outputfile
//init values!!!!
//read_config_file(&clusters_num, &hfuns_num, &hashtables_num, configfile);
// int check_pars = 0;
// if((check_pars = init_params(argc, argv, &inputflag, inputfile, &configflag, configfile, &outputflag, outputfile, &metric, &clusters_num, &hfuns_num, &hashtables_num, &complete_print))==-99)
// {
// print_msg_centre_line("CLUSTERIN' OUT!!");
// printf("\n\n");
// return -999;
// }
//printf("\nComplete_print : %d\n", complete_print );
if(print_msgs_on == 1)
print_welcome_msg();
// int init = -9;
// int assign = -9;
// int update = -9;
// int answer = 1;
// //answer = choose_algos(&init, &assign, &update); //user input on algorithms - y/n - if y: choose each one
// if (!answer) //will try all algorithms
// {
// print_msg_centre("Starting the process...");
// print_msg_centre_line("12 combinations will be tried out");
// // print_msg_centre_line("will be tried out");
// }
// else if(answer == -99)
// {
// print_msg_centre_line("CLUSTERIN' OUT!!");
// printf("\n\n");
// return -999;
// }
// else
// {
if(print_msgs_on == 1)
print_msg_centre("Clusterin: Starting the process...");
// printf("\n");
// }
printf("\n\n");
struct multipoints* MpointsList = NULL;
int dimension = dimension_of_coords;
//printf("\nDimension: %d", dimension);
MpointsList = multiPointList_init(dimension);
point_num_type totalpoints_in = 0;
save_points(MpointsList, inputfile, &totalpoints_in, dimension ); //save points of input dataset
//printList(MpointsList);
//struct cluster* clusters[1]; //the structure of clusters
//clusters[0] = malloc( clusters_num * get_size_cluster());
clusters_init(clusters_num, clusters);
FILE* temp = NULL;
temp = fopen(outputfile, "w+");
fclose(temp);
struct results* temp_res = NULL;
//int dimension_of_coords = d;
//if (answer > 0) //user's choice
//{
temp_res = users_choice(MpointsList, clusters, init, assign, update, outputfile, totalpoints_in, clusters_num, hfuns_num, hashtables_num, metric, complete_print, dimension_of_coords);
free(temp_res); //results in case of user's choice don't have a meaning so i free it immediately
//}
// else if(!answer) //12 combinations - when the user doesn't choose a certain combination
// {
// all_combinations(MpointsList, clusters, outputfile, clusters_num, totalpoints_in, hfuns_num, hashtables_num, metric, complete_print, dimension_of_coords);
// }
//deletes - free memory
//delete_all(MpointsList, clusters, clusters_num);
if(print_msgs_on == 1)
print_msg_centre_line(" CLUSTERin' OUT ! ");
printf("\n\n");
return 999;
}