Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compare algorithm #31

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
45 changes: 43 additions & 2 deletions modules/Graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Loading