156 lines
2.4 KiB
C
156 lines
2.4 KiB
C
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <pthread.h>
|
|
|
|
#include "routing4SITA.h"
|
|
|
|
|
|
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->cost = 0;
|
|
|
|
pthread_create(&startThread, NULL, Search, data);
|
|
|
|
//pthread_join(startThread,NULL);
|
|
|
|
for(;;){
|
|
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
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);
|
|
return NULL;
|
|
}
|
|
|
|
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);
|
|
}
|
|
*/
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|