Building a Graph with a Custom Vertex and Edge classes, and using the interface? & GraphImport

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Building a Graph with a Custom Vertex and Edge classes, and using the interface? & GraphImport

docker dev
Hi, 

I have been troubled by these issues over the last few days.

I am looking to build the graph outlined in the attached Graphml document. Initially i tried to use GraphMLImporter, this came to no avail i was continually receiving Parsing error my initial enquiry can be seen here:

If anyone can show me how to import my graph that would solve my problem immediately as i wouldn't have to go through the process of building and trying to add my vertices and edges manually. I am at my wits end with this some help on that would be really appreciated. I can send you any data or the documents you need to help.

Failing that i have been trying to build the graph myself as i need to run Dijkstra on the graph, i have created an ArrayList<Node> and ArrayList<Edge> and i am trying to add them to a directed graph, I think i may be missing the vertex interface at some point. Any help and pointers would really help and you might save a man form pulling the rest of his hair out.

public void createWayGraph(Context context) throws IOException {

venueGraphTypeBuilder = GraphTypeBuilder
.directed()
.edgeClass(WayEdge.class)
.vertexClass(WayNode.class)
.weighted(true);
venueGraph = venueGraphTypeBuilder.buildGraph();
for(WayNode wn:wayNodeArrayList){
venueGraph.addVertex(wn);
}
System.out.println("ddddddd "+venueGraph);
for(WayEdge we:wayEdgeArrayList){
venueGraph.addEdge(findSource(we), findDestination(we));
}}
public WayNode findSource(WayEdge we){
WayNode wn = null;
for(WayNode w:wayNodeArrayList){
String wayId = w.getId();
String edgeSource = we.getSource();
if(wayId==edgeSource){
wn=w;
}
}
return wn;
}

public WayNode findDestination(WayEdge we){
WayNode wn = null;
for(WayNode w:wayNodeArrayList){
String wayId = w.getId();
String edgeTarget = we.getTarget();
if(wayId==edgeTarget){
wn=w;
}
}
return wn;
}

I get the error:
Caused by: java.lang.NullPointerException: throw with null exception
        at org.jgrapht.graph.AbstractGraph.assertVertexExist(AbstractGraph.java:129)
        at org.jgrapht.graph.AbstractBaseGraph.addEdge(AbstractBaseGraph.java:214)
        at com.app.WayGraph.WayGraph.createWayGraph(WayGraph.java:65)



I hope someone can help, Importing the graph would be the ideal option as it will be the way i need to work.
Kindest regards,

Phil.


_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users