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