Пример #1
0
        public override bool AddEdge(T v1, T v2, K weight)
        {
            if (v1 is null)
            {
                throw new ArgumentNullException(nameof(v1));
            }

            if (v2 is null)
            {
                throw new ArgumentNullException(nameof(v2));
            }

            if (weight is null)
            {
                throw new ArgumentNullException(nameof(weight));
            }

            if (!VertexSet.Contains(v1) || !VertexSet.Contains(v2))
            {
                return(false);
            }

            IPairValue <T> pair = new PairValueI <T>(v1, v2);

            if (EdgeSet.Contains(pair))
            {
                return(false);
            }

            EdgeSet.Add(pair);
            Weights[pair] = weight;
            return(true);
        }
Пример #2
0
 public void AddEdge(Edge edge)
 {
     if (VertexSet.Contains(edge.StartVertex) && VertexSet.Contains(edge.EndVertex))
     {
         EdgeSet.Add(edge);
     }
     else
     {
         throw new ArgumentException("Could not find one or both of the specified vertices in the edge set.");
     }
 }
Пример #3
0
 public void AddEdge(Vertex beginningVertex, Vertex endingVertex, Movement movement)
 {
     if (VertexSet.Contains(beginningVertex) && VertexSet.Contains(endingVertex))
     {
         Edge edge = new Edge(beginningVertex, endingVertex, movement);
         EdgeSet.Add(edge);
     }
     else
     {
         throw new ArgumentException("Could not find one or both of the specified vertices in the edge set.");
     }
 }
Пример #4
0
 public override int Degree(TV vertex)
 {
     if (vertex == null)
     {
         throw new ArgumentNullException();
     }
     if (!VertexSet.Contains(vertex))
     {
         throw new ArgumentException();
     }
     return(InDegree(vertex) + OutDegree(vertex));
 }
Пример #5
0
 public override bool AreAdjacent(TV v1, TV v2)
 {
     if (v1 == null || v2 == null)
     {
         throw new ArgumentNullException();
     }
     if (!VertexSet.Contains(v1) || !VertexSet.Contains(v2))
     {
         throw new ArgumentException();
     }
     return(EdgeSet.Contains(new PairValue <TV>(v1, v2)));
 }
Пример #6
0
        public override KeyValuePair <T, K> GetVertexPair(T v1Key)
        {
            if (v1Key == null)
            {
                throw new ArgumentNullException();
            }

            var vertex = VertexSet.FirstOrDefault(x => x.Key.Equals(v1Key));

            if (!VertexSet.Contains(vertex))
            {
                throw new ArgumentException();
            }

            return(vertex);
        }
 public override IEnumerable <T> AdjacentVertex(T vertex)
 {
     if (vertex == null)
     {
         throw new ArgumentNullException();
     }
     if (!VertexSet.Contains(vertex))
     {
         throw new ArgumentException();
     }
     foreach (IPairValue <T> p in EdgeSet)
     {
         if (p.GetFirst().Equals(vertex))
         {
             yield return(p.GetSecond());
         }
     }
 }
Пример #8
0
        public override bool AreAdjacent(T v1, T v2)
        {
            if (v1 is null)
            {
                throw new ArgumentNullException(nameof(v1));
            }

            if (v2 is null)
            {
                throw new ArgumentNullException(nameof(v2));
            }

            if (!VertexSet.Contains(v1) || !VertexSet.Contains(v2))
            {
                throw new ArgumentException();
            }

            return(EdgeSet.Contains(new PairValueI <T>(v1, v2)));
        }
Пример #9
0
        public override bool AddEdge(TV v1, TV v2, TK weigth)
        {
            if (v1 == null || v2 == null || weigth == null)
            {
                throw new ArgumentNullException();
            }
            if (!VertexSet.Contains(v1) || !VertexSet.Contains(v2))
            {
                return(false);
            }
            IPairValue <TV> pair = new PairValue <TV>(v1, v2);

            if (EdgeSet.Contains(pair))
            {
                return(false);
            }
            EdgeSet.Add(pair);
            Weigths[pair] = weigth;
            return(true);
        }
Пример #10
0
        public override int InDegree(TV vertex)
        {
            if (vertex == null)
            {
                throw new ArgumentNullException();
            }
            if (!VertexSet.Contains(vertex))
            {
                throw new ArgumentException();
            }
            int counter = 0;

            foreach (var pair in EdgeSet)
            {
                if (pair.GetSecond().Equals(vertex))
                {
                    counter++;
                }
            }
            return(counter);
        }
        public override int Degree(T vertex)
        {
            if (vertex == null)
            {
                throw new ArgumentNullException();
            }
            if (!VertexSet.Contains(vertex))
            {
                throw new ArgumentException();
            }
            int counter = 0;

            foreach (IPairValue <T> pair in EdgeSet)
            {
                if (pair.GetFirst().Equals(vertex))
                {
                    counter++;
                }
            }
            return(counter);
        }
Пример #12
0
        public override bool AddEdge(KeyValuePair <T, K> v1, KeyValuePair <T, K> v2, K weight)
        {
            if (v1.Key == null || v2.Key == null || weight == null)
            {
                throw new ArgumentNullException();
            }
            if (!VertexSet.Contains(v1) || !VertexSet.Contains(v2))
            {
                return(false);
            }
            IPairValue <T> pair = new PairValue <T>(v1.Key, v2.Key);

            if (EdgeSet.Contains(pair))
            {
                return(false);
            }

            EdgeSet.Add(pair);
            Weights[pair] = weight;
            return(true);
        }