Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Create a Graph structure

Reply
Thread Tools

Create a Graph structure

 
 
sanoBabu
Guest
Posts: n/a
 
      10-18-2005
Hi all

My Java code tries to read a text file of the form -
"Source_node Dest_node distance" and then based on the distance between
those nodes, try to find the minimal spanning tree.

I've already created a class called Node which has source_node and
dest_node and simple accessor/mutator methods.

I've also created an Edge class which represents the distance between
the 2 nodes. Edge has one constructor -
public Edge(Node d, double cost);

I've also created a class called Graph which basically has no
constructor and has the following methods-

public void addEdge(String s,String d,double weight);
public Node getNode(String nodeName);
private Map aNodeMap = new HashMap(); //Maps string to Node

To proceed for the solution, I read the file -> parse contents -> then
I add the "source destination weight" to the graph object using -
g.addEdge(source,dest,weight);

Honestly I don't know how I can tackle the solution after that.
After adding the edges, do I just run the minimal spanning tree
algorithm (g.prim()) on the Graph or do I have to do something more?

ThAnks.
SanoBabu

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      10-18-2005
On 18 Oct 2005 01:07:54 -0700, "sanoBabu" <(E-Mail Removed)> wrote
or quoted :

>
>Honestly I don't know how I can tackle the solution after that.
>After adding the edges, do I just run the minimal spanning tree
>algorithm (g.prim()) on the Graph or do I have to do something more?


A few thoughts.

I would think an edge would have two nodes, source and dest.

It depends on how your algorithm works, but you may need to build a
structure of nodes with references linking them rather than a separate
list of edges. It was not clear if you did that.

The key is to understand your algorithm. It presumes a certain
representation. You have to provide that.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Boost Graph Library to create very large graph Almoni C++ 0 01-17-2010 05:13 AM
[Boost.Graph] graph.vertices property creates new objects George Sakkis Python 1 01-29-2007 11:09 PM
Help with initialization of graph (Boost Graph Library) Jef Driesen C++ 3 01-24-2006 01:44 PM
Missing Graph.h and (Graph.lib) woes - any help Dr Ann Huxtable C Programming 6 12-21-2004 11:15 AM
GD::Graph: "mixed" graph doesn't recognize "area" graph type Emilio Mayorga Perl Misc 6 10-08-2003 02:14 AM



Advertisments