Skip to content

Commit

Permalink
Merge pull request #34 from BillyMich/FixCompareAlgorithm
Browse files Browse the repository at this point in the history
Added smaller accurase finder and added bigger test and fixed small issue in create graph
  • Loading branch information
BillyMich authored Nov 30, 2023
2 parents d6e9cfa + b4f25f2 commit 778dbc1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions include/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions main/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 60 399 euclidean

ARGSMAN = $(DATASETS)/00001000-4.bin 100 399 manhattan
ARGSMAN = $(DATASETS)/00001000-4.bin 60 399 manhattan

$(EXEC): $(OBJS)
$(CC) $(OBJS) -o $(EXEC) $(LDFLAGS)
Expand Down
5 changes: 5 additions & 0 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
51 changes: 48 additions & 3 deletions modules/Graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -65,12 +67,17 @@ Graph* createGraphFromBinaryFile(String filename, int dimensions) {
}
}

freeDimensions(headDimension);

fclose(file);
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;
Expand Down Expand Up @@ -98,6 +105,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");
Expand Down

0 comments on commit 778dbc1

Please sign in to comment.