Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

Create a Graph structure

Thread view: 
sanoBabu - 18 Oct 2005 09:07 GMT
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
Roedy Green - 18 Oct 2005 09:23 GMT
>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.

Signature

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.