/// <summary> /// Access to arrow by pair /// </summary> public IAdvancedCategoryArrow this[CategoryObjectPair p] { get { return(arrows[p] as IAdvancedCategoryArrow); } }
/// <summary> /// Gets paths /// </summary> /// <param name="v">Root object</param> /// <param name="ob">Current object</param> private void GetPaths(DigraphVertex v, DigraphVertex ob) { CategoryObjectPair pair = new CategoryObjectPair(v.Object as IAdvancedCategoryObject, ob.Object as IAdvancedCategoryObject); IAdvancedCategoryArrow theArrow = this[pair]; foreach (DigraphEdge edge in ob.OutcomingEdges) { DigraphVertex vo = edge.Target; IAdvancedCategoryArrow ar = edge.Object as IAdvancedCategoryArrow; CategoryObjectPair p = new CategoryObjectPair(v.Object as IAdvancedCategoryObject, ar.Target); IAdvancedCategoryArrow newArrow = ar.Compose(category, theArrow); if (arrows.ContainsKey(p)) { IAdvancedCategoryArrow prev = this[p]; IAdvancedCategoryArrow comp = ar.Compose(category, theArrow); if (!prev.Equals(newArrow)) { throw new CategoryException(CategoryException.NonCommutativePath); } continue; } arrows[p] = newArrow; IList <IAdvancedCategoryArrow> s = sources[p.Source as IAdvancedCategoryObject] as IList <IAdvancedCategoryArrow>; s.Add(newArrow); IList <IAdvancedCategoryArrow> t = targets[p.Target as IAdvancedCategoryObject] as IList <IAdvancedCategoryArrow>; t.Add(newArrow); GetPaths(v, vo); } }
/// <summary> /// Constructor /// </summary> /// <param name="graph">Graph</param> /// <param name="category">Category</param> public CategoryDiagram(Digraph graph, ICategory category) { this.graph = graph; this.category = category; for (int i = 0; i < graph.Count; i++) { IAdvancedCategoryObject o = graph[i].Object as IAdvancedCategoryObject; CategoryObjectPair idPair = new CategoryObjectPair(o, o); IAdvancedCategoryArrow id = o.Id; arrows[idPair] = id; objects.Add(o); IList <IAdvancedCategoryArrow> s = new List <IAdvancedCategoryArrow>(); s.Add(id); sources[o] = s; IList <IAdvancedCategoryArrow> t = new List <IAdvancedCategoryArrow>(); t.Add(id); targets[o] = t; } for (int i = 0; i < graph.Count; i++) { DigraphVertex o = graph[i]; GetPaths(o, o); } }
/// <summary> /// Equaulity function /// </summary> /// <param name="o">Object to compare</param> /// <returns>True if o equals this object and false otherwise</returns> public override bool Equals(object o) { CategoryObjectPair p = o as CategoryObjectPair; return((p.source == source) & (p.target == target)); }