diff --git a/src/cluster.c b/src/cluster.c new file mode 100644 index 0000000000000000000000000000000000000000..fe560c37ba9b752a0b2cb47ab562fc28659c37b1 --- /dev/null +++ b/src/cluster.c @@ -0,0 +1,14 @@ +// +// by Boris Stefanovic on 01/06/22 +// + +#include "cluster.h" +#include "vector.h" + + +cluster_point_int_t* cluster_point_int_create(vector_int_t* vector) { + cluster_point_int_t* elem = malloc(sizeof(cluster_point_int_t)); + if (NULL == elem) return NULL; + elem->vector = vector; + elem->cluster = NULL; +} diff --git a/src/cluster.h b/src/cluster.h new file mode 100644 index 0000000000000000000000000000000000000000..be463ef4b070dbc1f448576bb830491fe47138cb --- /dev/null +++ b/src/cluster.h @@ -0,0 +1,21 @@ +// +// by Boris Stefanovic on 01/06/22 +// + +#ifndef PROG_KMEANS_CLUSTER_H +#define PROG_KMEANS_CLUSTER_H + +#include "vector.h" + + +typedef vector_int_t cluster_int_t; // a cluster may be represented by its center + +typedef struct cluster_point_int { + vector_int_t* vector; + cluster_int_t* cluster; // justified by "many-to-one" relationship and several passes over all points +} cluster_point_int_t; + +cluster_point_int_t* cluster_point_int_create(vector_int_t* vector); + + +#endif //PROG_KMEANS_CLUSTER_H diff --git a/src/kmeans.c b/src/kmeans.c new file mode 100644 index 0000000000000000000000000000000000000000..21a9232b0252b49b559872850bae5867ed9118a8 --- /dev/null +++ b/src/kmeans.c @@ -0,0 +1,6 @@ +// +// by Boris Stefanovic on 01/06/22 +// + +#include "kmeans.h" +#include "cluster.h" diff --git a/src/kmeans.h b/src/kmeans.h new file mode 100644 index 0000000000000000000000000000000000000000..100ef805a35e1d85154c99eee9a413e1e0f4bd35 --- /dev/null +++ b/src/kmeans.h @@ -0,0 +1,12 @@ +// +// by Boris Stefanovic on 01/06/22 +// + +#ifndef PROG_KMEANS_KMEANS_H +#define PROG_KMEANS_KMEANS_H + + +// + + +#endif //PROG_KMEANS_KMEANS_H diff --git a/src/main.c b/src/main.c index aa0ddfdc49e27e0a33067bf30942e3fe1a2b25da..60dc781341d6417d22b06c9a0c7298a779d2950c 100644 --- a/src/main.c +++ b/src/main.c @@ -58,10 +58,11 @@ ll_vint_t* get_vector_list(FILE* ifile, const size_t dim) { while (getline(&line, &len, ifile) != -1) { if (len != 0) { vector_int_t* vector = line_to_vector_int(line, dim); - //TODO + ll_vint_append(list, vector); free(line); } } + return list; } @@ -89,15 +90,9 @@ int main(int argc, char** argv) { printf("NUMBER OF CLUSTERS MUST BE STRICTLY POSITIVE !\n"); return EXIT_FAILURE; } - char* line = NULL; - size_t len = 0; - while (getline(&line, &len, ifile) != -1) { - if (len != 0) { - vector_int_t* vector = line_to_vector_int(line, dim); - //TODO - free(line); - } - } + ll_vint_t* list = get_vector_list(ifile, dim); + // ALGORITHM + // TODO // WRITE FILE* ofile = opath != NULL ? fopen(opath, "w") : stdout; // TODO