private bool TryPutVerticle(PointF p)
        {
            if (PointFColidesWithPolygons(p))
            {
                return(false);
            }

            if (Verticles.Count == 0)
            {
                Verticles.Add(p);
                return(true);
            }

            foreach (PointF PointF in Verticles)                                  //Chcecking another verticles
            {
                if (Math.Abs(PointF.X - p.X) < 8 && Math.Abs(PointF.Y - p.Y) < 8) //Verticle colides with Point
                {
                    if (PointF == Verticles[0])
                    {
                        CompletePolygon();
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            Verticles.Add(p);
            return(true);
        }
 public GraphVertex <T> FindVertex(T value)
 {
     if (Verticles.ContainsKey(value))
     {
         return(Verticles[value]);
     }
     return(null);
 }
 public IEnumerable <T> Edges(T vertex)
 {
     if (!Verticles.ContainsKey(vertex))
     {
         throw new ArgumentException("Vertex is not in this graph.");
     }
     return(Verticles[vertex].Edges.Select(x => x.Value));
 }
示例#4
0
 /// <summary>
 /// Returns the vertex with a given value.
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public WeightedDiGraphVertex <T, TW> FindVertex(T value)
 {
     if (Verticles.ContainsKey(value))
     {
         return(Verticles[value]);
     }
     return(null);
 }
示例#5
0
 public IEnumerable <Tuple <T, TW> > InEdges(T vertex)
 {
     if (!Verticles.ContainsKey(vertex))
     {
         throw new ArgumentException("Vertex is not in this graph.");
     }
     return(Verticles[vertex].InEdges.Select(x => new Tuple <T, TW>(x.Key.Value, x.Value)));
 }
 /// <summary>
 /// Do we have an edge between the given source and destination?
 /// Time complexity: O/1
 /// </summary>
 /// <param name="source"></param>
 /// <param name="destination"></param>
 /// <returns></returns>
 public bool HasEdge(T source, T destination)
 {
     if (!Verticles.ContainsKey(source) || !Verticles.ContainsKey(destination))
     {
         throw new ArgumentException("Source or Destination is not in this graph.");
     }
     return(Verticles[source].Edges.Contains(Verticles[destination]) &&
            Verticles[destination].Edges.Contains(Verticles[source]));
 }
示例#7
0
 public bool HasNegativeCycle()
 {
     BellmanFord(Verticles.First().Id);
     foreach (Edge e in Edges)
     {
         if (e.To.Dist > e.From.Dist + e.Weight)
         {
             return(true);
         }
     }
     return(false);
 }
        /// <summary>
        /// Add a new vertex to graph.
        /// Time complexity: O/1
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public GraphVertex <T> AddVertex(T value)
        {
            if (value == null)
            {
                throw new ArgumentNullException();
            }

            var newVertex = new GraphVertex <T>(value);

            Verticles.Add(value, newVertex);

            return(newVertex);
        }
示例#9
0
        /// <summary>
        /// Add a new vertex to this graph
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public WeightedDiGraphVertex <T, TW> AddVertex(T value)
        {
            if (value == null)
            {
                throw new ArgumentException();
            }

            var newVertex = new WeightedDiGraphVertex <T, TW>(value);

            Verticles.Add(value, newVertex);

            return(newVertex);
        }
        /// <summary>
        /// Remove an existing vertex from this graph.
        /// Time complexity: O(V) where V is the number of verticles.
        /// </summary>
        /// <param name="vertex"></param>
        /// <returns></returns>
        public void RemoveVertex(T vertex)
        {
            if (vertex == null)
            {
                throw new ArgumentNullException();
            }

            if (!Verticles.ContainsKey(vertex))
            {
                throw new Exception("Vertex is not in this graph.");
            }

            foreach (var v in Verticles[vertex].Edges)
            {
                v.Edges.Remove(Verticles[vertex]);
            }
            Verticles.Remove(vertex);
        }
        /// <summary>
        /// Add an edge from source to destination vertex.
        /// Time complexity: O/1.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        public void AddEdge(T source, T destination)
        {
            if (source == null || destination == null)
            {
                throw new ArgumentException();
            }

            if (!Verticles.ContainsKey(source) || !Verticles.ContainsKey(destination))
            {
                throw new Exception("Source or Destination Vertex not in this graph.");
            }

            if (!Verticles[source].OutEdges.Contains(Verticles[destination]) || Verticles[destination].InEdges.Contains(Verticles[source]))
            {
                throw new Exception("Edge already exists");
            }
            Verticles[source].OutEdges.Add(Verticles[destination]);
            Verticles[destination].InEdges.Add(Verticles[source]);
        }
        /// <summary>
        /// Remove an edge from this graph.
        /// </summary>
        /// <param name="scource"></param>
        /// <param name="destination"></param>
        public void RemoveEdge(T source, T destination)
        {
            if (source == null | destination == null)
            {
                throw new ArgumentException();
            }

            if (!Verticles.ContainsKey(source) || !Verticles.ContainsKey(destination))
            {
                throw new Exception("Source or destination Vertex is not in this graph.");
            }

            if (!Verticles[source].Edges.Contains(Verticles[destination]) ||
                !Verticles[destination].Edges.Contains(Verticles[source]))
            {
                throw new Exception("Edge does not exist");
            }
            Verticles[source].Edges.Remove(Verticles[destination]);
            Verticles[destination].Edges.Remove(Verticles[source]);
        }
示例#13
0
        /// <summary>
        /// Remove the given vertex.
        /// Time complexity: O(V) where V is the number of verticles.
        /// </summary>
        public void RemoveVertex(T value)
        {
            if (value == null)
            {
                throw new ArgumentNullException();
            }

            if (!Verticles.ContainsKey(value))
            {
                throw new Exception("Vetex is not in this  graph.");
            }

            foreach (var vertex in Verticles[value].InEdges)
            {
                vertex.Key.OutEdges.Remove(Verticles[value]);
            }

            foreach (var vertex in Verticles[value].OutEdges)
            {
                vertex.Key.InEdges.Remove(Verticles[value]);
            }
            Verticles.Remove(value);
        }
 public IEnumerator <T> GetEnumerator()
 {
     return(Verticles.Select(x => x.Key).GetEnumerator());
 }
示例#15
0
 IEnumerator IEnumerable.GetEnumerator()
 {
     return(Verticles.Select(x => x.Key).GetEnumerator());
 }
 /// <summary>
 /// Returns the vertex object with given value
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public DiGraphVertex <T> FindVertex(T value)
 {
     return(Verticles.ContainsKey(value) ? Verticles[value] : null);
 }