/// <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> /// Gets arrow from colim /// </summary> /// <param name="arrows">Arrows from objects</param> /// <returns>Arrow from colim</returns> public IAdvancedCategoryArrow GetArrowFromColim(IList <IAdvancedCategoryArrow> arrows) { Dictionary <ICategoryObject, ICategoryArrow> dictionary = new Dictionary <ICategoryObject, ICategoryArrow>(); IAdvancedCategoryObject target = null; foreach (IAdvancedCategoryArrow arrow in arrows) { if (target == null) { target = arrow.Target as IAdvancedCategoryObject; } if (target != arrow.Target) { throw new CategoryException(CategoryException.DifferentTargets, new IAdvancedCategoryObject[] { target, arrow.Target as IAdvancedCategoryObject }); } if (!objects.Contains(arrow.Source as IAdvancedCategoryObject)) { throw new CategoryException(ObjectOutOfDiagram, arrow.Source); } if (dictionary.ContainsKey(arrow.Source)) { throw new CategoryException(ExtraArrow, arrow); } dictionary[arrow.Source] = arrow; } foreach (object o in objects) { if (!dictionary.ContainsKey(o as ICategoryObject)) { throw new CategoryException(ArrowsShortage, o); } } foreach (CategoryObjectPair pair in Keys) { IAdvancedCategoryArrow ar = this[pair]; IAdvancedCategoryArrow first = dictionary[pair.Target] as IAdvancedCategoryArrow; IAdvancedCategoryArrow second = dictionary[pair.Source] as IAdvancedCategoryArrow; IAdvancedCategoryArrow composition = first.Compose(category, ar); if (!composition.Equals(second)) { throw new CategoryException(CategoryException.NonCommutativePath, ar); } } Dictionary <int, IAdvancedCategoryArrow> sortedTable = new Dictionary <int, IAdvancedCategoryArrow>(); foreach (IAdvancedCategoryArrow ar in arrows) { int i = objects.IndexOf(ar.Source as IAdvancedCategoryObject); sortedTable[i] = ar; } IList <IAdvancedCategoryArrow> sortedArrows = new List <IAdvancedCategoryArrow>(); for (int i = 0; i < sortedTable.Count; i++) { sortedArrows.Add(sortedTable[i]); } IDirectSumCategory sumCategory = category as IDirectSumCategory; IAdvancedCategoryArrow arrowFromSum = sumCategory.GetArrowFromDirectSum(target, colimIdArrow.Target as IAdvancedCategoryObject, sortedArrows); ICoequalizerCategory coequalizerCategory = category as ICoequalizerCategory; IAdvancedCategoryArrow res = coequalizerCategory.GetArrowFromCoequalizer(colimArrow, arrowFromSum, colimIdArrow, colimFuncArrow); return(res); }
/// <summary> /// Gets arrow to lim /// </summary> /// <param name="arrows">Arrows to objects</param> /// <returns>The arrow to lim</returns> public IAdvancedCategoryArrow GetArrowToLim(List <IAdvancedCategoryArrow> arrows) { Dictionary <ICategoryObject, ICategoryArrow> dictionary = new Dictionary <ICategoryObject, ICategoryArrow>(); IAdvancedCategoryObject source = null; foreach (IAdvancedCategoryArrow arrow in arrows) { if (source == null) { source = arrow.Source as IAdvancedCategoryObject; } if (source != arrow.Source) { throw new CategoryException(CategoryException.DifferentSources, new IAdvancedCategoryObject[] { source, arrow.Source as IAdvancedCategoryObject }); } if (!objects.Contains(arrow.Target as IAdvancedCategoryObject)) { throw new CategoryException(ObjectOutOfDiagram, arrow.Target); } if (dictionary.ContainsKey(arrow.Target)) { throw new CategoryException(ExtraArrow, arrow); } dictionary[arrow.Target] = arrow; } foreach (object o in objects) { if (!dictionary.ContainsKey(o as ICategoryObject)) { throw new CategoryException(ArrowsShortage, o); } } foreach (CategoryObjectPair pair in Keys) { IAdvancedCategoryArrow ar = this[pair]; IAdvancedCategoryArrow first = dictionary[pair.Source] as IAdvancedCategoryArrow; IAdvancedCategoryArrow second = dictionary[pair.Target] as IAdvancedCategoryArrow; IAdvancedCategoryArrow composition = ar.Compose(category, first); if (!composition.Equals(second)) { throw new CategoryException(CategoryException.NonCommutativePath, ar); } } Dictionary <int, IAdvancedCategoryArrow> sortedTable = new Dictionary <int, IAdvancedCategoryArrow>(); foreach (IAdvancedCategoryArrow ar in arrows) { int i = objects.IndexOf(ar.Target as IAdvancedCategoryObject); sortedTable[i] = ar; } IList <IAdvancedCategoryArrow> sortedArrows = new List <IAdvancedCategoryArrow>(); for (int i = 0; i < sortedTable.Count; i++) { sortedArrows.Add(sortedTable[i]); } IDirectProductCategory productCategory = category as IDirectProductCategory; IAdvancedCategoryArrow arrowToProduct = productCategory.GetArrowToDirectProduct(source, limIdArrow.Source as IAdvancedCategoryObject, sortedArrows); IEqualizerCategory equalizerCategory = category as IEqualizerCategory; IAdvancedCategoryArrow res = equalizerCategory.GetArrowToEqualizer(limArrow, arrowToProduct, limIdArrow, limFuncArrow); return(res); }