From 21de63b2da4569422e9f9b9d62adc6f3a0ba2798 Mon Sep 17 00:00:00 2001
From: Boris Stefanovic <owldev@bluewin.ch>
Date: Wed, 1 Jun 2022 11:05:06 +0200
Subject: [PATCH] ADD: cluster

---
 src/cluster.c | 14 ++++++++++++++
 src/cluster.h | 21 +++++++++++++++++++++
 src/kmeans.c  |  6 ++++++
 src/kmeans.h  | 12 ++++++++++++
 src/main.c    | 15 +++++----------
 5 files changed, 58 insertions(+), 10 deletions(-)
 create mode 100644 src/cluster.c
 create mode 100644 src/cluster.h
 create mode 100644 src/kmeans.c
 create mode 100644 src/kmeans.h

diff --git a/src/cluster.c b/src/cluster.c
new file mode 100644
index 0000000..fe560c3
--- /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 0000000..be463ef
--- /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 0000000..21a9232
--- /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 0000000..100ef80
--- /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 aa0ddfd..60dc781 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
-- 
GitLab