Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » JUNG loading grpah question
JUNG loading grpah question [message #653770] Fri, 11 February 2011 05:24
Eddie Mising name is currently offline Eddie Mising nameFriend
Messages: 6
Registered: February 2011
Junior Member
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(GraphMLReader.java:2 46)
at edu.uci.ics.jung.io.GraphMLReader.load(GraphMLReader.java:19 2)
at hyperGraph.loadGraph(hyperGraph.java:189)
at hyperGraph.main(hyperGraph.java:233)

here is the 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() {
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(); }
}

and the 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?
Previous Topic:Configure Glashfish in Eclipse
Next Topic:Don't get MDT UML2 / UML2tools to run.
Goto Forum:
  


Current Time: Fri Apr 26 19:30:33 GMT 2024

Powered by FUDForum. Page generated in 0.08148 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top