public void RemoveEdge(VertexCore vertexFirst, VertexCore vertexSecond) { if (vertexFirst != null && vertexSecond != null) { Edges.Remove(vertexFirst.RemoveEdge(vertexSecond)); } }
public void RemoveVertex(VertexCore vertex) { var list = vertex.AdjacentVertices.ToList(); foreach (var item in list) { Edges.Remove(item.RemoveEdge(vertex)); } Vertices.Remove(vertex); }
private VertexCore AddVertexIfNotExist(int id) { var vertex = Vertices.Where(x => x.Id == id).FirstOrDefault(); if (vertex == null) { vertex = new VertexCore(id); Vertices.Add(vertex); } return(vertex); }
public VertexCore AddVertex() { int id; if (Vertices.Count == 0) { id = 1; } else { id = Vertices.Select(x => x.Id).Max() + 1; } var vertex = new VertexCore(id); Vertices.Add(vertex); return(vertex); }
public bool ConnectVertex(VertexCore vertexFirst, VertexCore vertexSecond) { if (vertexFirst == null || vertexSecond == null) { return(false); } if (!Vertices.Contains(vertexFirst)) { Vertices.Add(vertexFirst); } if (!Vertices.Contains(vertexSecond)) { Vertices.Add(vertexSecond); } Edges.Add(vertexFirst.AddEdge(vertexSecond)); return(true); }
public EdgeCore(VertexCore first, VertexCore second) { this.First = first; this.Second = second; }
private static IEnumerable <CycleCore> FindAllCycles(List <VertexCore> alreadyVisited, VertexCore a) { foreach (EdgeCore e in a.Edges) { if (alreadyVisited.Contains(e.Second)) { yield return(new CycleCore(e)); } else { List <VertexCore> newSet = new List <VertexCore>(alreadyVisited); newSet.Add(e.Second); foreach (CycleCore c in FindAllCycles(newSet, e.Second)) { c.Build(e); yield return(c); } } } }