Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Dijkstra'a algorithm

Status
Not open for further replies.

pdp1231

Newbie level 3
Joined
Jan 9, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,307
Hi all,

I am new to digital design and in my class we have been assigned with a project to design an accelerator for Dijkstra's algorithm. As a first step we have to make any high level language program for the algorithm. I am trying to write one in C but am stuck with declaration of structures. Please have a look at my code and help me resolve the errors.

#include<stdio.h>


/*Total number of nodes*/
#define N 5

/*Defining an array for the address index of graph.dat*/
double add_index[N][2];

/*Adjacent list of the graph.dat file. An array of structure has been defined here. There will be structure for each node.
Each node will store the vertex number in the vertex of the structure, no of daughter vertices(known vertices) in the no_dvertex, and will have the vertex
number of the daughter vertices and the edge weights in the array d_info*/
struct node_info
{
unsigned int vertex;
unsigned int no_dvertex;
unsigned int d_info[7][2];
}node[N];



void dijkstra(unsigned int a, unsigned int b)
{
int i,j=1;
unsigned int weight;
weight=0;
unsigned int temp_weight;
unsigned int v_path[5];
unsigned int temp_vertex;
temp_vertex=a;
while(temp_vertex!=b)
{
temp_weight=node[temp_vertex].d_info[1][2];

for(i=2;i<=node[temp_vertex].no_dvertex;i++)
{
if(temp_weight>=node[temp_vertex].d_info[2])
{
temp_weight=node[temp_vertex].d_info[2];
temp_vertex=i;
}
}
weight=weight+temp_weight;
v_path[j]= temp_vertex;
j++;
}
}


void main()
{
struct node_info node[1]={1,2,{2,10},{4,5},{25,25},{25,25},{25,25},{25,25},{25,25}};
struct node_info node[2]={2,2,{3,1},{4,2},{25,25},{25,25},{25,25},{25,25},{25,25}};
struct node_info node[3]={3,1,{5,4},{25,25},{25,25},{25,25},{25,25},{25,25},{25,25}};
struct node_info node[4]={4,3,{2,3},{3,9},{5,2},{25,25},{25,25},{25,25},{25,25}};
struct node_info node[5]={5,2,{1,7},{3,6},{25,25},{25,25},{25,25},{25,25},{25,25}};
unsigned int a=1,b=2;
dijkstra(a,b);

}


The error that I am getting is with the initialization of struct node_info.
trial1.c:57: error: conflicting types for ânodeâ

Please help me fix this code.

Thanks in advance.
 

I too have tried using 'unsigned' variable types in an effort to save memory. I soon decided not to trust it. The reason, is that I was prone to forget they were unsigned, when I introduced them into calculations with signed integers. I forget if there were error messages or what. But things happened that made it seem unreliable to go with unsigned variables.

Anyway I decided that if a single-byte variable turned out having a higher value than +127, then I was better off upgrading it to a 2-byte integer variable, signed.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top