Hello All!

I have been working on a network design problem and am having a problem in the following part-

What I am trying to do here --
{
for every set of edges (a,b),
{ for all arcs (l,m)
assign length of -- arc [l,m] = edge [a,b][l,m]
shortest_path (num_nodes, arr_nodes, source);
}
----------------------------------------------------------------------------
Part of the Code which does the above looks like this -

for ( node = arr_nodes; node < arr_nodes + num_nodes; node++ )
{
edge_tail = (node - arr_nodes) + min_node;

for ( arc_pointer = node -> first; arc_pointer != (node+1) -> first; arc_pointer++ )
{
edge_head = ((arc_pointer -> head_edge) - arr_nodes) + min_node;

for ( node1 = arr_nodes; node1 < arr_nodes + num_nodes; node1++ )
{
tail_arc = tail1[count1];

for ( arc_pointer1 = node1 -> first; arc_pointer1 != (node1+1) -> first; arc_pointer1++ )
{
head_arc = ((arc_pointer->head_edge)-ndp)+nmin;
printf ( " Tail_Edge = %2ld Head_Edge = %2ld Tail_Arc = %2ld Head_Arc = %2ld Length = %4lf\n", edge_tail, head_in, tail_arc, head_arc, ta->len );
arc_pointer1 -> length = weight2[edge_tail][edge_head][tail_arc][head_arc];
shortest_path (num_nodes, arr_nodes, source);
}
count1++;
}
}
}

As of now it gives segmentation fault while displaying output at the print statement.

Kindly guide me in knowing what is wrong in my coding so that it could give the desired result.

Thanks!

everywhere u are accesing the members of some structure using pointer and there doesn't seem to be any check for NULL statemnt.

everywhere u are accesing the members of some structure using pointer and there doesn't seem to be any check for NULL statemnt.

I actually modified this part a bit--

for ( node1 = arr_nodes_new; node1 < arr_nodes_new + num_nodes; node1++ )
{
tail_arc = (node1 - arr_nodes_new) + min_node;
for ( arc_pointer1 = node1 -> first_new; arc_pointer1 != (node1+1) -> first_new; arc_pointer1++ )
{
head_arc = ((arc_pointer1->head_edge) - arr_nodes_new)+min_node;

printf ( " Tail_Edge = %2ld Head_Edge = %2ld Tail_Arc = %2ld Head_Arc = %2ld Length = %4lf\n", edge_tail, edge_head, tail_arc, head_arc, arc_pointer ->len );

arc_pointer -> length = weight2[edge_tail][edge_head][tail_arc][head_arc];
shortest_path (num_nodes, arr_nodes_new, source);
}

Now it works fine---- but I am having problems in assigning the right weights. I did try the Null condition - that said

if(node -> first == node1-> first_edge)
then do the above part of the code. But it did not give any results.

I am not sure what NULL condition I should check for? Could you please suggest any condition that would be suitable?

Thanks....

what if node==NULL and
U are trying to access node->first i.e. member of an object that doesn't exist.
This will result in seg fault.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.