/// <summary> /// Adding edge to graph, if it still doesn't exist in graph. And adding vertexes FROM and TO if they still doesn't exist in graph. /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="weight"></param> public void AddEdge(Edge edge) { //TODO: check coming data to class MYGRAPH. if (!Edges.Contains(edge)) { Edges.Add(edge); } AddVertex(edge.From); AddVertex(edge.To); MaxLength += edge.Weight; AllShortestWays = HelpGetAllShortestWays(); }
/// <summary> /// Returns all shortest ways in graph. /// </summary> /// <returns></returns> private AllShortestWaysInGraph HelpGetAllShortestWays() { var allWays = new AllShortestWaysInGraph(CountVertexes); for (int i = 0; i < CountVertexes; i++) { for (int j = 0; j < CountVertexes; j++) { if (i != j) { allWays.AddWay(HelpGetWay(Vertexes[i], Vertexes[j]), i, j); } } } return(allWays); }
/// <summary> /// Constructor with parameter [List of edges]. /// </summary> /// <param name="edges"></param> public MyGraphClass(List <Edge> edges) { Vertexes = new List <Vertex>(); Edges = new List <Edge>(); MaxLength = 0; foreach (var edge in edges) { if (!Edges.Contains(edge)) { Edges.Add(edge); } AddVertex(edge.From); AddVertex(edge.To); MaxLength += edge.Weight; } AllShortestWays = HelpGetAllShortestWays(); }