diff --git a/src/nodes.c b/src/nodes.c new file mode 100644 index 0000000..7df28ca --- /dev/null +++ b/src/nodes.c @@ -0,0 +1,72 @@ +#include +#include "routing4SITA.h" + +NODE_t* getStartNode() { + + static NODE_t* start; + static NODE_t* g; + static NODE_t* f; + static NODE_t* e; + static NODE_t* d; + static NODE_t* c; + static NODE_t* b; + static NODE_t* a; + static NODE_t* end; + + start = (NODE_t*) malloc(sizeof(NODE_t)); + a = (NODE_t*) malloc(sizeof(NODE_t)); + b = (NODE_t*) malloc(sizeof(NODE_t)); + c = (NODE_t*) malloc(sizeof(NODE_t)); + d = (NODE_t*) malloc(sizeof(NODE_t)); + e = (NODE_t*) malloc(sizeof(NODE_t)); + f = (NODE_t*) malloc(sizeof(NODE_t)); + g = (NODE_t*) malloc(sizeof(NODE_t)); + end = (NODE_t*) malloc(sizeof(NODE_t)); + + end->id = 8; + end->nodescount = 0; + + g->id = 7; + g->nodescount = 0; + + f->id = 6; + f->nodescount = 1; + f->nodesnext[0] = end; + f->nodescost[0] = 7; + + e->id = 5; + e->nodescount = 0; + + d->id = 4; + d->nodescount = 0; + + c->id = 3; + c->nodescount = 1; + c->nodesnext[0] = end; + c->nodescost[0] = 3; + + b->id = 2; + b->nodescount = 3; + b->nodesnext[0] = e; + b->nodescost[0] = 11; + b->nodesnext[1] = f; + b->nodescost[1] = 42; + b->nodesnext[2] = g; + b->nodescost[2] = 8; + + a->id = 1; + a->nodescount = 2; + a->nodesnext[0] = c; + a->nodescost[0] = 15; + a->nodesnext[1] = d; + a->nodescost[1] = 27; + + start->id = 0; + start->nodescount = 2; + start->nodesnext[0] = a; + start->nodescost[0] = 72; + start->nodesnext[1] = b; + start->nodescost[1] = 32; + + return start; +} diff --git a/src/routing4SITA b/src/routing4SITA index 2207e95..cb3de3d 100755 Binary files a/src/routing4SITA and b/src/routing4SITA differ diff --git a/src/routing4SITA.c b/src/routing4SITA.c index 9f8e14d..f736a66 100644 --- a/src/routing4SITA.c +++ b/src/routing4SITA.c @@ -1,4 +1,3 @@ - #include #include #include @@ -10,131 +9,51 @@ void *Search(void* arguments); int main() { printf("hello world!\n"); - - NODE_t end; - end.id = 8; - end.nodescount = 0; - NODE_t g; - g.id = 7; - g.nodescount = 0; - - NODE_t f; - f.id = 6; - f.nodescount = 1; - f.nodesnext[0] = &end; - f.nodescost[0] = 7; - - NODE_t e; - e.id = 5; - e.nodescount = 0; - - NODE_t d; - d.id = 4; - d.nodescount = 0; - - NODE_t c; - c.id = 3; - c.nodescount = 1; - c.nodesnext[0] = &end; - c.nodescost[0] = 3; - - NODE_t b; - b.id = 2; - b.nodescount = 3; - b.nodesnext[0] = &e; - b.nodescost[0] = 11; - b.nodesnext[1] = &f; - b.nodescost[1] = 42; - b.nodesnext[2] = &g; - b.nodescost[2] = 8; - - NODE_t a; - a.id = 1; - a.nodescount = 2; - a.nodesnext[0] = &c; - a.nodescost[0] = 15; - a.nodesnext[1] = &d; - a.nodescost[1] = 27; - - NODE_t start; - start.id = 0; - start.nodescount = 2; - start.nodesnext[0] = &a; - start.nodescost[0] = 72; - start.nodesnext[1] = &b; - start.nodescost[1] = 32; - - - pthread_t startThread; - THREAD_DATA_t* data; - data = (THREAD_DATA_t*) malloc(sizeof(THREAD_DATA_t)); - - data->node = &start; + data->node = getStartNode(); data->cost = 0; - + pthread_create(&startThread, NULL, Search, data); - - //pthread_join(startThread,NULL); - - for(;;){ - + + for(;;) { + } - + return 0; } -void *Search(void* arguments){ - - +void *Search(void* arguments) { + THREAD_DATA_t *data = (THREAD_DATA_t*) arguments; - - printf("Number: %i\n", data->node->id); printf("Cost to this node: %i\n", data->cost); - - if(data->node->id == 8){ - printf("End found! Cost: %i\ns", data->cost); + + if(data->node->id == 8) { + printf("End found! Cost: %i\n", data->cost); return NULL; } - - if(data->node->nodescount == 0){ + + if(data->node->nodescount == 0) { printf("No next nodes\n"); return NULL; } - + pthread_t threads[data->node->nodescount]; - for(int i = 0; i < data->node->nodescount; i++){ - - THREAD_DATA_t* nextdata; - - nextdata = (THREAD_DATA_t*) malloc(sizeof(THREAD_DATA_t)); - - nextdata->node = (data->node->nodesnext[i]); - - nextdata->cost = data->node->nodescost[i] + data->cost; - - //nextdata->cost = 42; - - pthread_create(&threads[i], NULL, Search, nextdata); - - } - - /* for(int i = 0; i < data->node->nodescount; i++) { - pthread_join(threads[i],NULL); + THREAD_DATA_t* nextdata; + nextdata = (THREAD_DATA_t*) malloc(sizeof(THREAD_DATA_t)); + nextdata->node = (data->node->nodesnext[i]); + nextdata->cost = data->node->nodescost[i] + data->cost; + pthread_create(&threads[i], NULL, Search, nextdata); } - */ - - + return NULL; - } diff --git a/src/routing4SITA.h b/src/routing4SITA.h index eca658c..338dd04 100644 --- a/src/routing4SITA.h +++ b/src/routing4SITA.h @@ -1,18 +1,18 @@ #ifndef ROUTING4SITA_H -#define ROUTING4SITA_H - +#define ROUTING4SITA_H #define MAX_CHILDREN 3 - typedef struct node NODE_t; typedef struct threadData THREAD_DATA_t; +extern NODE_t* getStartNode(); + struct node { - int id; - int nodescount; - NODE_t* nodesnext[MAX_CHILDREN]; - int nodescost[MAX_CHILDREN]; + int id; + int nodescount; + NODE_t* nodesnext[MAX_CHILDREN]; + int nodescost[MAX_CHILDREN]; }; @@ -21,18 +21,4 @@ struct threadData { int cost; }; - - - - - - - - - - - - - - #endif /* ROUTING4SITA_H */