/// <summary> /// Gets colimit /// </summary> /// <param name="category">The category</param> /// <param name="arrows">Diagram arrows</param> /// <param name="coequalizer">Coequalizer</param> /// <param name="objectArrows">Arrows to colimit</param> /// <param name="productArrows">Sum arrows</param> /// <returns>The colimit</returns> public static IAdvancedCategoryObject GetColim(ICategory category, IList <IAdvancedCategoryArrow> arrows, ref IAdvancedCategoryArrow coequalizer, ref IList <IAdvancedCategoryArrow> objectArrows, ref IList <IAdvancedCategoryArrow> productArrows) { IList <IAdvancedCategoryObject> objects = new List <IAdvancedCategoryObject>(); IList <IAdvancedCategoryObject> sources = new List <IAdvancedCategoryObject>(); IDirectSumCategory direct = category as IDirectSumCategory; ICoequalizerCategory coequ = category as ICoequalizerCategory; foreach (IAdvancedCategoryArrow arrow in arrows) { if (!objects.Contains(arrow.Source as IAdvancedCategoryObject)) { objects.Add(arrow.Source as IAdvancedCategoryObject); } if (!objects.Contains(arrow.Target as IAdvancedCategoryObject)) { objects.Add(arrow.Source as IAdvancedCategoryObject); } sources.Add(arrow.Source as IAdvancedCategoryObject); } IList <IAdvancedCategoryArrow> productSourceArrows = new List <IAdvancedCategoryArrow>(); productArrows = new List <IAdvancedCategoryArrow>(); IAdvancedCategoryObject product = direct.GetDirectSum(objects, productArrows); IAdvancedCategoryObject productSource = direct.GetDirectSum(sources, productSourceArrows); IList <IAdvancedCategoryArrow> coequList = new List <IAdvancedCategoryArrow>(); IList <IAdvancedCategoryArrow> arrList = new List <IAdvancedCategoryArrow>(); foreach (IAdvancedCategoryArrow arr in productArrows) { IAdvancedCategoryObject target = arr.Target as IAdvancedCategoryObject; foreach (IAdvancedCategoryObject t in sources) { if (t == target) { arrList.Add(arr); } } } IAdvancedCategoryArrow first = direct.GetArrowFromDirectSum(product, productSource, arrList); foreach (IAdvancedCategoryArrow arr in arrows) { int num = objects.IndexOf(arr.Target as IAdvancedCategoryObject); IAdvancedCategoryArrow pr = productArrows[num] as IAdvancedCategoryArrow; IAdvancedCategoryArrow eq = pr.Compose(category, arr); coequList.Add(eq); } IAdvancedCategoryArrow second = direct.GetArrowFromDirectSum(product, productSource, coequList); coequalizer = coequ.GetCoequalizer(first, second); objectArrows = new List <IAdvancedCategoryArrow>(); foreach (IAdvancedCategoryArrow arrow in productArrows) { IAdvancedCategoryArrow arr = coequalizer.Compose(category, arrow); objectArrows.Add(arr); } return(coequalizer.Target as IAdvancedCategoryObject); }
/// <summary> /// Creates limit /// </summary> private void CreateColim() { if (!(category is IDirectSumCategory)) { throw new CategoryException(CategoryException.DirectSumNotSupported); } if (!(category is IEqualizerCategory)) { throw new CategoryException(CategoryException.CoequalizerNotSupported); } IDirectSumCategory sumCategory = category as IDirectSumCategory; IList <IAdvancedCategoryArrow> firstArrows = new List <IAdvancedCategoryArrow>(); IAdvancedCategoryObject firstSum = sumCategory.GetDirectSum(objects, firstArrows); IList <IAdvancedCategoryObject> beginObjects = new List <IAdvancedCategoryObject>(); foreach (CategoryObjectPair o in arrows.Keys) { IAdvancedCategoryArrow a = arrows[o]; beginObjects.Add(a.Source as IAdvancedCategoryObject); } IList <IAdvancedCategoryArrow> secondArrows = new List <IAdvancedCategoryArrow>(); IAdvancedCategoryObject secondSum = sumCategory.GetDirectSum(beginObjects, secondArrows); colimIdArrows = new List <IAdvancedCategoryArrow>(); foreach (IAdvancedCategoryArrow sar in secondArrows) { IAdvancedCategoryObject s = sar.Source as IAdvancedCategoryObject; foreach (IAdvancedCategoryArrow proj in firstArrows) { if (proj.Source == s) { colimIdArrows.Add(proj); break; } } } colimIdArrow = sumCategory.GetArrowFromDirectSum(firstSum, secondSum, colimIdArrows); colimFuncArrows = new List <IAdvancedCategoryArrow>(); foreach (CategoryObjectPair o in arrows.Keys) { IAdvancedCategoryArrow sar = this[o]; foreach (IAdvancedCategoryArrow proj in firstArrows) { if (proj.Source == sar.Target) { IAdvancedCategoryArrow ar = proj.Compose(category, sar); colimFuncArrows.Add(ar); break; } } } colimFuncArrow = sumCategory.GetArrowFromDirectSum(firstSum, secondSum, colimFuncArrows); ICoequalizerCategory coequalizerCategory = category as ICoequalizerCategory; colimArrow = coequalizerCategory.GetCoequalizer(colimIdArrow, colimFuncArrow); colim = colimArrow.Target as IAdvancedCategoryObject; colimArrows = new Dictionary <IAdvancedCategoryObject, IAdvancedCategoryArrow>(); foreach (IAdvancedCategoryArrow proj in firstArrows) { IAdvancedCategoryObject s = proj.Source as IAdvancedCategoryObject; IAdvancedCategoryArrow ar = colimArrow.Compose(category, proj); colimArrows[s] = ar; } }