From 549ed53ffd289acb86f2ce0ba4a0d7834ec757d3 Mon Sep 17 00:00:00 2001 From: Vasilis Michaleas <68393224+BillyMich@users.noreply.github.com> Date: Thu, 30 Nov 2023 16:32:49 +0200 Subject: [PATCH 1/3] Added smaller accurase finder and added bigger test --- Makefile | 4 ++-- include/Graph.h | 4 ++++ main/main.c | 5 +++++ modules/Graph.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 816557f..6a9233e 100644 --- a/Makefile +++ b/Makefile @@ -36,8 +36,8 @@ EXECNEI = neighbours_test EXECMATH = mathFunctions_test # Args for examples -ARGSEUCL = $(DATASETS)/asciiData3.bin 2 50 euclidean -ARGSMAN = $(DATASETS)/asciiData3.bin 2 50 manhattan +ARGSEUCL = $(DATASETS)/asciiData3.bin 2 200 euclidean +ARGSMAN = $(DATASETS)/asciiData3.bin 2 200 manhattan all: $(EXEC) $(EXECG) $(EXECN) $(EXECD) diff --git a/include/Graph.h b/include/Graph.h index 31216ea..3e63d3f 100644 --- a/include/Graph.h +++ b/include/Graph.h @@ -19,9 +19,13 @@ Graph* createGraphFromBinaryFile(String filename, int dimensions); double findAccurationResult(Graph* graph , Graph* graphRightResults); +double findAccurationResultSuperAccurate(Graph* graph , Graph* graphRightResults); + + void freeGraph(Graph* graph); void makeFile(String filename); + void writeGraphToFile(Graph* graph, const char* filename); #endif // GRAPH_H diff --git a/main/main.c b/main/main.c index c79e85b..3aab336 100644 --- a/main/main.c +++ b/main/main.c @@ -36,8 +36,13 @@ int main(int argc, char *argv[]) { double accurationRate =findAccurationResult(graph , graphRightResults); + double accurationSuperRate =findAccurationResultSuperAccurate(graph , graphRightResults); + printf("\n~ Acurate by %f %% ~\n",accurationRate); + printf("\n~ Acurate Supper by %f %% ~\n",accurationSuperRate); + + writeGraphToFile(graph, "Graph.txt"); writeGraphToFile(graphRightResults, "GraphWithBrutal.txt"); diff --git a/modules/Graph.c b/modules/Graph.c index 8632ed2..978face 100644 --- a/modules/Graph.c +++ b/modules/Graph.c @@ -69,8 +69,11 @@ Graph* createGraphFromBinaryFile(String filename, int dimensions) { return graph; } - -double findAccurationResult(Graph* graph , Graph* graphRightResults){ +/// @brief Function to find the accuration result of the KNS algorithm +/// @param graph +/// @param graphRightResults +/// @return +double findAccurationResultSuperAccurate(Graph* graph , Graph* graphRightResults){ Node * tempNodeKNS = graph->nodes; Node * tempNodeRight = graphRightResults->nodes; @@ -98,6 +101,44 @@ double findAccurationResult(Graph* graph , Graph* graphRightResults){ } +/// @brief Function to find the accuration result of the KNS algorithm +/// @param graph +/// @param graphRightResults +/// @return +double findAccurationResult(Graph* graph , Graph* graphRightResults){ + + Node * tempNodeKNS = graph->nodes; + Node * tempNodeRight = graphRightResults->nodes; + double count = 0 ; + double correct = 0; + + while (tempNodeKNS != NULL) + { + + NodeNeighborsLinkedList * tempNodeListKNS = tempNodeKNS->neighbors; + NodeNeighborsLinkedList * tempNodeListRight = tempNodeRight->neighbors; + + while (tempNodeListKNS !=NULL) + { + count++; + while (tempNodeListRight != NULL) + { + if (tempNodeListKNS->node->nodeNameInt == tempNodeListRight->node->nodeNameInt) correct++; + tempNodeListRight = tempNodeListRight->next; + } + + tempNodeListRight = tempNodeRight->neighbors;; + tempNodeListKNS = tempNodeListKNS->next; + } + + tempNodeRight = tempNodeRight->next; + tempNodeKNS = tempNodeKNS->next; + } + + + return (correct / count )* 100; +} + // Function to write the graph data to a file void writeGraphToFile(Graph* graph, const char* filename) { FILE* file = fopen(filename, "w"); From 2abbefa882f55da995b3daa6e4ec0381adc7454d Mon Sep 17 00:00:00 2001 From: Vasilis Michaleas <68393224+BillyMich@users.noreply.github.com> Date: Thu, 30 Nov 2023 17:20:37 +0200 Subject: [PATCH 2/3] Update main makefile --- main/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/Makefile b/main/Makefile index 32f87b2..7caf996 100644 --- a/main/Makefile +++ b/main/Makefile @@ -18,9 +18,9 @@ OBJS = main.o $(MODULES)/Graph.o $(MODULES)/Node.o $(MODULES)/Neighbors.o $(MODU EXEC = program # Args for examples -ARGSEUCL = $(DATASETS)/00001000-4.bin 100 399 euclidean +ARGSEUCL = $(DATASETS)/00001000-4.bin 70 399 euclidean -ARGSMAN = $(DATASETS)/00001000-4.bin 100 399 manhattan +ARGSMAN = $(DATASETS)/00001000-4.bin 70 399 manhattan $(EXEC): $(OBJS) $(CC) $(OBJS) -o $(EXEC) $(LDFLAGS) From b4f25f2789e747f0f6a77c411d8143227933e917 Mon Sep 17 00:00:00 2001 From: Vasilis Michaleas <68393224+BillyMich@users.noreply.github.com> Date: Thu, 30 Nov 2023 18:16:38 +0200 Subject: [PATCH 3/3] Fixed segmetation fault on graph --- main/Makefile | 4 ++-- modules/Graph.c | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/main/Makefile b/main/Makefile index 7caf996..0773f59 100644 --- a/main/Makefile +++ b/main/Makefile @@ -18,9 +18,9 @@ OBJS = main.o $(MODULES)/Graph.o $(MODULES)/Node.o $(MODULES)/Neighbors.o $(MODU EXEC = program # Args for examples -ARGSEUCL = $(DATASETS)/00001000-4.bin 70 399 euclidean +ARGSEUCL = $(DATASETS)/00001000-4.bin 60 399 euclidean -ARGSMAN = $(DATASETS)/00001000-4.bin 70 399 manhattan +ARGSMAN = $(DATASETS)/00001000-4.bin 60 399 manhattan $(EXEC): $(OBJS) $(CC) $(OBJS) -o $(EXEC) $(LDFLAGS) diff --git a/modules/Graph.c b/modules/Graph.c index 978face..a418d88 100644 --- a/modules/Graph.c +++ b/modules/Graph.c @@ -45,10 +45,12 @@ Graph* createGraphFromBinaryFile(String filename, int dimensions) { Node** headNode = &graph->nodes; int flag = 0; // Flag for feof + Dimension* headDimension = NULL; + // Read and process data from the binary file while (!feof(file)) { - Dimension* headDimension = NULL; + headDimension = NULL; for (int i = 0; i < dimensions; i++){ fread(&coordinate, sizeof(double), 1, file); // Read one double at a time @@ -65,6 +67,8 @@ Graph* createGraphFromBinaryFile(String filename, int dimensions) { } } + freeDimensions(headDimension); + fclose(file); return graph; }