weighted graph

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2008
Posts: 4
Reputation: johnkurtz is an unknown quantity at this point 
Solved Threads: 0
johnkurtz johnkurtz is offline Offline
Newbie Poster

weighted graph

 
0
  #1
May 3rd, 2008
Hi all.

Could anybody tell me how can I load to the memory a weighted graph from a file?

Thanks.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: weighted graph

 
0
  #2
May 3rd, 2008
Use a 2D array or a sparse matrix.

How do you plan to use the graph?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 4
Reputation: johnkurtz is an unknown quantity at this point 
Solved Threads: 0
johnkurtz johnkurtz is offline Offline
Newbie Poster

Re: weighted graph

 
0
  #3
May 3rd, 2008
My intention is to describe the weighted graph in a text file and then load it automatically to the memory (using a list) to implement at the end dijkstra's algorithm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: weighted graph

 
0
  #4
May 3rd, 2008
Ah, a 1D list. OK.

If you are at liberty to create your own input file, I suggest you make it something easy to read (programmatically), like:
Pascal and Delphi Syntax (Toggle Plain Text)
  1. 0 12 0 2
  2. 1 24 0 2
  3. 2 13 1
where the first number on the line is the node number, the second is its weight, and any remaining are edges leaving the node. (You don't actually have to list the node number, you could just deduce it from the line number as you read...)

Make yourself a record that represents a node. Then use an array of that record type. All you have to do then is read one line at a time into one node at a time.

Hope this helps.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC