nodes in own .c file
This commit is contained in:
parent
fccf397c64
commit
e836dfc4e2
|
@ -0,0 +1,72 @@
|
|||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
BIN
src/routing4SITA
BIN
src/routing4SITA
Binary file not shown.
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue