Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: JUNG loading grpah question

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JUNG loading grpah question

    i get this error when i try to load the graph from the text file

    java.io.IOException: specified 'source' attribute "A" does not match any node ID
    at edu.uci.ics.jung.io.GraphMLReader.parse(GraphMLRea der.java:246)
    at edu.uci.ics.jung.io.GraphMLReader.load(GraphMLRead er.java:192)
    at hyperGraph.loadGraph(hyperGraph.java:189)
    at hyperGraph.main(hyperGraph.java:233)

    here is my loading graph code
    class VertexM {
            String name = "";
     
     
            public VertexM() {
            }
     
            public VertexM(String name) {
                    this.name = name;
            }
     
            public String toString() { 
                    return name; 
            }
     
            public boolean equals(Object obj) {
                    if (obj == this) {
                            return true;
                    }
     
                    if (obj == null) {
                            return false;
                    }
                    VertexM other = (VertexM) obj;
     
                    boolean a = this.getName().equals(other.getName());
                    return a;
            }
     
            public void setName(String name) {
                    this.name = name;
            }
     
            public String getName() {
                    return name;
            }
     
            public int getCount() {
                    return 1;
            }
     
            public int hashCode() {
                    return name.hashCode();
            }
    }
     
    class EdgeM {
            float count;
            String id = "";
     
            public EdgeM() {
                    this.count = 0;
            }
     
            public EdgeM(String d, String v1, String v2) {
                    this.id = v1 + v2;
                    this.count = Integer.parseInt(d);
            }
     
            public String toString() { // Always good for debugging
                    return id;
            }
     
            public void addCount() {
                    count++;
            }
     
            public void setId(String id) {
                    this.id = id;
            }
     
            public float getCount() {
                    return count;
            }
     
            public boolean equals(Object obj) {
                    if (obj == this) {
                            return true;
                    }
    )
                    if (obj == null) {
                            return false;
                    }
                    EdgeM other = (EdgeM) obj;
     
                    boolean a = this.toString().equals(other.toString());
                    return a;
            }
     
            @Override
            public int hashCode() {
                    int result = Math.round(count) * 37 + id.hashCode();
                    return result;
            }
    }
     
     
    public static UndirectedSparseGraph<VertexM, EdgeM> loadGraph(Reader reader) {
                    class EdgeMFactory implements Factory<EdgeM> {
     
                            @Override
                            public EdgeM create() {
                                    return new EdgeM();
                            }
     
                    }
     
                    class VertexMFactory implements Factory<VertexM> {
                            public VertexM create() {
                                    return new VertexM();
                            }
     
                    }
                    GraphMLReader<UndirectedSparseGraph<VertexM, EdgeM>, VertexM, EdgeM> graphReader =
    null;
                    try {
                            graphReader = new GraphMLReader<UndirectedSparseGraph<VertexM, EdgeM>, VertexM,
    EdgeM>(
                                            new VertexMFactory(), new EdgeMFactory());
                    } catch (ParserConfigurationException e1) {
                            e1.printStackTrace();
                    } catch (SAXException e1) {
                            e1.printStackTrace();
                    }
     
                    UndirectedSparseGraph<VertexM, EdgeM> fixGraph = new
    UndirectedSparseGraph<VertexM, EdgeM>();
                    try {
                            graphReader.load(reader, fixGraph);
                            Map<String, GraphMLMetadata<VertexM>> nodeMetaData = graphReader
                                            .getVertexMetadata();
     
                            for (VertexM node : fixGraph.getVertices()) {
                                    String nodeName = ((String)
    (nodeMetaData.get("NodeName").transformer.transform(node)));
                                    System.out.println("NODE" + nodeName);
     
                                    node.setName(nodeName);
                            }
     
                    } catch (IOException e) {
                            e.printStackTrace();
                    }
     
                    return fixGraph;
            }
     
            /**
             * @param args
             * @throws SAXException
             * @throws ParserConfigurationException
             */
            public static void main(String[] args) {
     
                      try { FileReader in = new FileReader(
                      "C:\\Program Files\\Eclipse for FYP\\output\\test.txt"); 
                      Hypergraph<VertexM, EdgeM> hg = loadGraph(in);
                      System.out.println(hg.getVertices()); } catch
                      (ArrayIndexOutOfBoundsException e) {
     
                      System.out.println("Usage: java ReadFile filename\n");
     
                      } catch (IOException e) { e.printStackTrace(); }
    }

    my save file is
    <?xml version="1.0" encoding="UTF-8"?>
    <graphml xmlns="http://graphml.graphdrawing.org/xmlns/graphml"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns/graphml">
    <key id="NodeName" for="node">
    <desc>File Name</desc>
    <default></default>
    </key>
    <key id="EdgeName" for="edge">
    <desc>Edge Visit Name</desc>
    <default></default>
    </key>
    <key id="EdgeCount" for="edge">
    <desc>Edge Visit Count</desc>
    <default></default>
    </key>
    <graph edgedefault="undirected">
    <node id="A">
    <data key="NodeName">A</data>
    </node>
    <node id="B">
    <data key="NodeName">B</data>
    </node>
    <node id="C">
    <data key="NodeName">C</data>
    </node>
    <edge source="A" target="C">
    <data key="EdgeName">AC</data>
    <data key="EdgeCount">3.0</data>
    </edge>
    <edge source="A" target="B">
    <data key="EdgeName">AB</data>
    <data key="EdgeCount">2.0</data>
    </edge>
    </graph>
    </graphml>
    is there any problem for my code?
    Last edited by copeg; February 14th, 2011 at 09:58 AM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: JUNG loading grpah question

    Cross posted at JUNG Loading graph question. While cross posting is not against the rules of this forum, we ask posters to be forthright in revealing other locations the same question was asked. For reasons why, see The problems with crossposting

Similar Threads

  1. JUNG 2.0 Zoom-Function
    By humpty-hump in forum Member Introductions
    Replies: 1
    Last Post: January 22nd, 2011, 11:22 AM
  2. Loading array
    By joshft91 in forum Collections and Generics
    Replies: 3
    Last Post: January 19th, 2011, 11:30 AM
  3. Loading Images and Edit it
    By shadihrr in forum Java Theory & Questions
    Replies: 1
    Last Post: March 25th, 2010, 08:39 PM
  4. Loading in images
    By eXcellion in forum Java Theory & Questions
    Replies: 3
    Last Post: January 17th, 2010, 12:13 PM
  5. Replies: 3
    Last Post: April 14th, 2009, 08:35 AM