/** * Removes an edge from the graph * @param e Edge to remove * @return true if edge was removed, false if it wasn't */ public Boolean removeEdge(DjikGraphEdge e) { // if the edge doesn't exist in the graph we can't remove it. if (!edges.Contains(e)) { return(false); } // it does exist. make sure the vertices delete each other as neighbors and remove. e.disconnectNeighbors(); edges.Remove(e); return(true); }
/** * get the weight of the edge to a neighbor. * @param target The neighboring vertex * @return the weight of the edge between this vertex and the neighboring vertex. or 0 otherwise. */ public int getEdgeWeighToNeighbor(Vertex target) { if (!neighbors.ContainsKey(target)) { return(0); } else { DjikGraphEdge e = (DjikGraphEdge)neighbors[target]; return(e.getWeight()); } }
/** * Add a new weighted edge to the graph * @param firstVertexName The first vertex this edge connects * @param secondVertexName The second vertex this edge connects * @param weight the weight of the edge * @return true if edge was added, false otherwise */ public Boolean addWeightedEdge(String firstVertexName, String secondVertexName, int weight) { // if the vertices don't exist in graph, can't connect them. if (!vertices.ContainsKey(firstVertexName) || !vertices.ContainsKey(secondVertexName)) { return(false); } // also, don't allow self-loops... if (firstVertexName.Equals(secondVertexName)) { return(false); } // otherwise we are in the clear. connect the vertices via a new edge and return true. DjikGraphEdge e = new DjikGraphEdge(vertices[firstVertexName] as Vertex, vertices[secondVertexName] as Vertex, weight); edges.Add(e); return(true); }
/** * Adds a neighbor * @param v Neighboring vertex to add * @param e The edge connecting the vertices * @return true if succeeded connecting. false otherwise. */ public void addNeighbor(Vertex v, DjikGraphEdge e) { neighbors.Add(v, e); }