hey AntP...(I was actually trying to reach u) as u had helped me with my last LL code.
Now I am passing all my simulated code to a LL (with which u had helped with ) but have problems as i have mentioned ahead...
my code is
Code:
int ***Sim_edges( float ***array1){ // Simulation of Edges (but only for those that have nodes)
int i,j,k;
int ***array2;
double prob;
const gsl_rng_type * TT;
gsl_rng * r;
gsl_rng_env_setup(); // GSL environment Setup
TT = gsl_rng_default;
r = gsl_rng_alloc (TT);
array2 = (int ***)malloc(sizeof(int **) * iter);
for (i = 0 ; i < iter; i++) {
array2[i] = (int **)malloc(sizeof(int *) * nodes);
for (j = 0; j < nodes; j++) {
array2[i][j] = (int *)malloc(sizeof(int) * nodes);
}
}
for (i=0; i<iter; i++){
for (j=0; j<nodes; j++){
for (k=0; k<nodes; k++){
array2[i][j][k]=0;
prob = array1[i][j][k];
array2[i][j][k] = gsl_ran_bernoulli(r, prob); // calling GSL Library
//printf("%d\t",array2[i][k][j]); // storing the simulated edge values
}
// printf("\n");
}
// printf("\n");
}
for (i=0; i<iter; i++){
for (j=0; j<nodes; j++){
for (k=0; k<nodes; k++){
array2[i][k][j] = array2[i][j][k]; // to make is adjacency matrix
printf("%d\t",array2[i][k][j]); // storing the simulated edge values
}
printf("\n");
}
printf("\n");
}
return array2; this array had to be passed to the LL for BFS run
}
struct Edge
{
int terminal;
struct Edge *next;
};
struct Vertex
{
int visit;
int vertex_no;
char info;
int path_length;
struct Edge *Edge_Ptr;
};
struct Q
{
int info;
struct Q *next;
};
void Table(int , int ***array2, struct Vertex vert[size]);
struct Edge *Insert_Vertex (int , struct Edge *);
void BFS ( int , struct Vertex vert [size]);
struct Q *Insert_Queue(int vertex_no, struct Q *first); // Insert vertex in the queue (if any conncection found)
struct Q *Delete_Queue(int *vertex_no, struct Q *first);// Delete vertex if it has been visited
/* Insert vertex into connectivity list */
struct Edge * Insert_Vertex (int vertex_no, struct Edge
*first) {
struct Edge *new1, *current;
new1 = (struct Edge *) malloc(sizeof(struct Edge));
new1->terminal = vertex_no;
new1->next = NULL;
if (!first)
return (new1);
for (current = first; current->next; current = current->next);
current->next = new1;
return (first);
}
/* Insert vertices into queue */
struct Q * Insert_Queue(int vertex_no, struct Q *first)
{
struct Q *new1, *current; // getting the
new1 =(struct Q *) malloc(sizeof(struct Q));
new1->info = vertex_no;
new1->next = NULL;
if (!first)
return (new1);
for (current = first; current->next; current = current->next);
current->next = new1;
return (first);
}
struct Q * Delete_Queue(int *vertex_no, struct Q *first)
{
struct Q *previous;
if (!first)
return (NULL);
*vertex_no = first->info;
previous = first;
first = first->next;
free(previous);
return (first);
}
/* Initializing entries */
void Table(int vertex_num, int ***array2,struct Vertex vert[size])
{
int i, j,k;
for (i = 0; i < vertex_num; i++)
{
vert [i].visit = F;
vert [i].vertex_no = i+1;
vert [i].info = 'A'+ i;
vert [i].path_length = 0;
vert [i].Edge_Ptr = NULL;
}
for(i= 0; i <iter; i++)
for (j =0; j < vertex_num ;j++)
for (k =0; k < vertex_num ; k++)
if (array2[i][j][k] > 0 )
vert [j].Edge_Ptr = Insert_Vertex (k, vert [j].Edge_Ptr);
}
/* Computing path length */
void BFS ( int index, struct Vertex vert [size])
{
struct Q *queue = NULL;
struct Edge *Link;
vert [index].visit = T;
queue = Insert_Queue(index, queue);
while(queue)
{
queue = Delete_Queue(&index, queue);
for ( Link = vert [index].Edge_Ptr; Link; Link = Link->next)
{
if (vert [Link->terminal].visit == F)
{
vert[Link->terminal].visit = T;
vert[Link->terminal].path_length=vert[index].path_length+1;
queue = Insert_Queue(Link->terminal, queue);
}
}
}
}
int main(argc,argv)
int argc;
char *argv[];
{
float **mat;
float ***array1;
int ***array2;
int index =5;
int i;
int option = 2;
nodes = NODES();
edges = EDGES();
mat = MAT(edges, nodes);
array1 =Sim_nodes(mat);
array2 =Sim_edges(array1);
struct Vertex vert [size];
struct Edge *List;
Table(nodes, array2, vert);
printf("\n Input the source node %d :",index);
BFS (index, vert);
printf("\n Input the target node %d:" ,option+1);
if(vert[option].path_length > 0)
printf("\nConnected.\n");
else
printf("\nNot connected.\n");
free (pR1), (pR2),(pC1),(pC2),(pC3),(pC4);
return 0;
}
I dont know If i have to make chanes in the BFS function or I am passing the array in some wrong way