-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcluster.c
More file actions
86 lines (69 loc) · 2.09 KB
/
cluster.c
File metadata and controls
86 lines (69 loc) · 2.09 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
#include <stdlib.h>
#include <stdio.h>
#include "input.h"
#include "MatrixAndVectorOps.h"
#include "modularity.h"
#include "Algorithms.h"
#include "List.h"
#include <time.h>
int main(int argc, char* argv[])
{
/*-----------------------------------declarations-----------------------------------*/
char *inFilePath, *outFilePath;
FILE* outFile;
int code; /* this integer allows us to catch errors (0 - success, 1- error) */
int length, degreesSum, i, amountOfGroups, groupSize;
int* degreesArray;
int** matrix;
list** oList;
list* curr;
clock_t start, end;
double cpu_time_used;
start = clock();
amountOfGroups = 0;
/*-----------------------------------code-----------------------------------*/
if (argc != 3){
printf("ERROR - not enough values to main.");
return 1;
}
inFilePath = argv[1];
outFilePath = argv[2];
code = getInputMatrix(inFilePath,&length,°reesSum,°reesArray,&matrix);
if (code == 1){
return 1;
}
cpu_time_used = ((double) (clock() - start)) / CLOCKS_PER_SEC;
printf("getInputMatrix : %f seconds\n",cpu_time_used);
code = Algorithem3(&oList, matrix,length,degreesSum,degreesArray);
end = clock();
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
printf("54 : The program took %f seconds\n",cpu_time_used);
outFile = fopen(outFilePath, "wb");
for (i = 0; i < length; ++i) {
if(oList[i] != NULL)
{
amountOfGroups++;
}
}
fwrite(&amountOfGroups, sizeof(int),1,outFile);
printf("%d\n",amountOfGroups);
for (i = 0; i < amountOfGroups; ++i) {
curr = oList[i];
groupSize = ListSize(curr);
fwrite(&groupSize, sizeof(int),1,outFile);
printf("Group %d, Size %d\n",i,groupSize);
printList(curr);
while (curr)
{
fwrite((&curr->val), sizeof(int),1,outFile);
curr = curr->next;
}
}
free(degreesArray);
freeIntMatrix(matrix,length);
for (i = 0; i < length; ++i) {
freeList(oList[i]);
}
free(oList);
return EXIT_SUCCESS;
}