Results 1 to 4 of 4
  1. #1
    chinolee is offline Member
    Join Date
    Nov 2009
    Posts
    1
    Rep Power
    0

    Default creating a graph from a text file

    Hi everyone. im somewhat new to java programming. i want to know how to make a graph from a text file. i know how to scan in the words. i cannot figure out how to make each word a node, create edges, and find the weight between each edge. thank you for any help!!

  2. #2
    sky
    sky is offline Member
    Join Date
    Nov 2009
    Posts
    96
    Rep Power
    0

    Default

    Hi everyone. im somewhat new to java programming. i want to know how to make a graph from a text file. i know how to scan in the words. i cannot figure out how to make each word a node, create edges, and find the weight between each edge. thank you for any help!!
    This is more a design problem rather than a Java problem. First of all, you already know how nodes are going to be represented in the text file, but how about edges? They can be in the same file, or in a different one (there is many possibilities) but in both cases an edge has to contain at least the two nodes that connects.

    After that, maybe you should think about class structure. It is almost sure that you will want to have a class Node and also a class Edge. Inside the class Node tipical fields could be the tag of the node, the value (if any), etc. In the class Edge, at least you have to store both nodes that are conected by the edge and some weight.

    Finally, there are also many ways to represent a graph. The most tipical ones are the adjacency matrix and the adjacency list. The second one is better as more sparse the graph is.

    Think about those points and If you post more details about the way that the graph is represented in the file I can tell you more.

  3. #3
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    I think if I would do thesame program, I would either:
    * make sure the point in the file is saves as a touple, e.g. (x,y)(x1,y1),(x2,y2)....etc..
    * or I can just save them as numbers next to each other like x1,y1,x2,y2...so every two is a node. I can then use a vector to store them after reading, and draw one from the previous node to the next ...until there are no more.

  4. #4
    Join Date
    Nov 2009
    Posts
    22
    Rep Power
    0

    Default

    thank everyone
    :D I'm from vietnam - I hope you help me :D

Similar Threads

  1. Replies: 8
    Last Post: 11-06-2009, 06:52 AM
  2. Creating&Saving as a different Text file
    By right2001 in forum New To Java
    Replies: 2
    Last Post: 04-07-2009, 07:17 AM
  3. find and replace text from a text file
    By gezzel in forum New To Java
    Replies: 2
    Last Post: 09-19-2008, 04:04 PM
  4. creating a text based game
    By Phobos0001 in forum New To Java
    Replies: 1
    Last Post: 02-12-2008, 04:35 PM
  5. Help Creating A Graph From Inputted Data
    By adlb1300 in forum New To Java
    Replies: 6
    Last Post: 10-28-2007, 04:45 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •