Hey guys and girls,
Somewhat stuck on this program. Im building an Adjacency Matrix and I cant seem to figure out how to create my buildGraph method. The whole program won't fit here so I have attached the netbeans project folder.
Here is essentially what needs work:
public void buildGraph() { // v.getIncidentEdges(); // w.getIncidentEdges(); for (int x = 1; x <10; x++){ for (int y = 1; y<10; y++){ /* * This needs help for sure. Im trying to check the Vertex to the * left, and the vertex above, and if they arent null, then create * and edge with them. * Moving through a 10x10 grid of Vertices creating edges between * them. * * if (Vertices != null && Vertices != null){ */ try {g.addEdge(v, w);}catch (NullPointerException npe) {} } } }
Here is the addEdge method:
public Edge addEdge(Vertex v,Vertex w) { Edge e = new Edge(v, w); v.addIncidentEdge(e); w.addIncidentEdge(e); e.getDestVertex(); e.getOriginVertex(); Edges.add(e); return e; }
Here is the addVertex method:
public Vertex addVertex(Cell c){ Coordinate z = c.getCoordinate(); int x = z.getX(); int y = z.getY(); Vertex v = new Vertex(c); try {Vertices.add(v);}catch (NullPointerException npe) {} System.out.println("("+ x + "," + y + ")" ); return v; }
Here is how I'm adding the vertices, essentially everytime it creates a new cell, it adds a vertex there, except when we add an Agent cell, for later when moving through the Matrix it wont be possible to walk into the agents:
if ((coordinate).equals(generator.getNeo())){ cell = new Cell(CellType.Neo,coordinate); System.out.println(CellType.Neo + " Vertex"); g.addVertex(cell); } else if(coordinate.equals(generator.getMorpheus())){ cell = new Cell(CellType.Morpheus,coordinate); System.out.println(CellType.Morpheus + " Vertex"); g.addVertex(cell); } else if(coordinate.equals(generator.getPhoneBooth())){ cell = new Cell(CellType.PhoneBooth,coordinate); System.out.println(CellType.PhoneBooth + " Vertex"); g.addVertex(cell); } else if (generator.getAgents().contains(coordinate)){ cell = new Cell(CellType.Agent,coordinate); System.out.println(CellType.Agent); System.out.println(coordinate); } else { cell = new Cell(CellType.Blank,coordinate); System.out.println(CellType.Blank + " Vertex"); g.addVertex(cell); }
Again, the code in its entirety is attached. There are multiple classes and didnt exactly want to post every last peice of code here.
Thanks in advance for the help