Beispiel #1
0
        /// <summary>
        /// Adds a new weighted edge.
        /// </summary>
        public virtual void Add(WeightedEdge <T> edge)
        {
            if (!EdgeMap.Contains(edge.From))
            {
                EdgeMap.Add(edge.From, new HashSet <WeightedEdge <T> >());
            }
            EdgeMap[edge.From].Add(edge);

            if (!EdgeMap.Contains(edge.To))
            {
                EdgeMap.Add(edge.To, new HashSet <WeightedEdge <T> >());
            }
            EdgeMap[edge.To].Add(new WeightedEdge <T>(edge.To, edge.From, -edge.Weight));
        }
Beispiel #2
0
        private bool?AreAdjacentEdges(Object ob1, Object ob2)
        {
            //then they are both of WeightedEdge type
            WeightedEdge e1 = (WeightedEdge)ob1;
            WeightedEdge e2 = (WeightedEdge)ob2;

            e1.Src--;
            e1.Dest--;
            e2.Src--;
            e2.Dest--;
            //if edges exists in graph
            if (GraphHasEdge(e1) && GraphHasEdge(e2))
            {
                return(e1.IsIncident(e2.Src) || e1.IsIncident(e2.Dest));
            }

            return(null);
        }
Beispiel #3
0
 public void RemoveEdge(WeightedEdge edge)
 {
     this.Edges.Remove(edge);
 }
Beispiel #4
0
 /// <summary>
 /// Adds a new weighted edge.
 /// </summary>
 public override void Add(WeightedEdge <T> edge)
 {
     Add(edge.From, edge.To, edge.Weight);
 }
Beispiel #5
0
 public bool Equals(WeightedEdge <T> other)
 {
     return(From.CompareTo(other.From) == 0 && To.CompareTo(other.To) == 0 && Math.Abs(Weight - other.Weight) < 1e-6);
 }
Beispiel #6
0
 public int CompareTo(WeightedEdge <T> other)
 {
     return(Weight.CompareTo(other.Weight));
 }
Beispiel #7
0
 private bool GraphHasEdge(WeightedEdge edge)
 {
     return(AdjacencyList[edge.Src].Exists(e => e.Dest == edge.Dest));
 }