Create a Graph structure

Discussion in 'Java' started by sanoBabu, Oct 18, 2005.

  1. sanoBabu

    sanoBabu Guest

    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
    sanoBabu, Oct 18, 2005
    #1
    1. Advertising

  2. sanoBabu

    Roedy Green Guest

    On 18 Oct 2005 01:07:54 -0700, "sanoBabu" <> 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.
    Roedy Green, Oct 18, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Sakkis
    Replies:
    1
    Views:
    434
    Szabolcs Nagy
    Jan 29, 2007
  2. Dr Ann Huxtable

    Missing Graph.h and (Graph.lib) woes - any help

    Dr Ann Huxtable, Dec 21, 2004, in forum: C Programming
    Replies:
    6
    Views:
    626
    Dr Ann Huxtable
    Dec 21, 2004
  3. Jef Driesen
    Replies:
    3
    Views:
    2,526
    mlimber
    Jan 24, 2006
  4. Almoni
    Replies:
    0
    Views:
    3,083
    Almoni
    Jan 17, 2010
  5. Emilio Mayorga
    Replies:
    6
    Views:
    313
    Martien Verbruggen
    Oct 8, 2003
Loading...

Share This Page