예제 #1
0
 public void RemoveEdge(VertexCore vertexFirst, VertexCore vertexSecond)
 {
     if (vertexFirst != null && vertexSecond != null)
     {
         Edges.Remove(vertexFirst.RemoveEdge(vertexSecond));
     }
 }
예제 #2
0
        public void RemoveVertex(VertexCore vertex)
        {
            var list = vertex.AdjacentVertices.ToList();

            foreach (var item in list)
            {
                Edges.Remove(item.RemoveEdge(vertex));
            }
            Vertices.Remove(vertex);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
파일: EdgeCore.cs 프로젝트: s10724/GizZad1
 public EdgeCore(VertexCore first, VertexCore second)
 {
     this.First  = first;
     this.Second = second;
 }
예제 #7
0
 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);
             }
         }
     }
 }