コード例 #1
0
ファイル: CategoryDiagram.cs プロジェクト: Erroman/universal
        /// <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);
            }
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
ファイル: DigraphPath.cs プロジェクト: Erroman/universal
        /// <summary>
        /// Gets arrow of this path
        /// </summary>
        /// <param name="category">Arrow category</param>
        /// <returns>The arrow</returns>
        public ICategoryArrow GetArrow(ICategory category)
        {
            int n = Count;
            IAdvancedCategoryArrow arrow = this[n - 1].Object as IAdvancedCategoryArrow;

            for (int i = n - 2; i >= 0; i++)
            {
                IAdvancedCategoryArrow a = this[i].Object as IAdvancedCategoryArrow;
                arrow = a.Compose(category, arrow);
            }
            return(arrow);
        }
コード例 #4
0
ファイル: CategoryDiagram.cs プロジェクト: Erroman/universal
        /// <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;
            }
        }
コード例 #5
0
ファイル: CategoryDiagram.cs プロジェクト: Erroman/universal
        /// <summary>
        /// Creates limit
        /// </summary>
        private void CreateLim()
        {
            if (!(category is IDirectProductCategory))
            {
                throw new CategoryException(CategoryException.DirectProductNotSupported);
            }
            if (!(category is IEqualizerCategory))
            {
                throw new CategoryException(CategoryException.EqualizerNotSupported);
            }
            IDirectProductCategory          productCategory = category as IDirectProductCategory;
            IList <IAdvancedCategoryArrow>  firstArrows     = new List <IAdvancedCategoryArrow>();
            IAdvancedCategoryObject         firstProduct    = productCategory.GetDirectProduct(objects, firstArrows);
            IList <IAdvancedCategoryObject> endObjects      = new List <IAdvancedCategoryObject>();

            foreach (CategoryObjectPair o in arrows.Keys)
            {
                IAdvancedCategoryArrow a = arrows[o] as IAdvancedCategoryArrow;
                endObjects.Add(a.Target as IAdvancedCategoryObject);
            }
            IList <IAdvancedCategoryArrow> secondArrows  = new List <IAdvancedCategoryArrow>();
            IAdvancedCategoryObject        secondProduct = productCategory.GetDirectProduct(endObjects, secondArrows);

            limIdArrows = new List <IAdvancedCategoryArrow>();
            foreach (IAdvancedCategoryArrow tar in secondArrows)
            {
                IAdvancedCategoryObject t = tar.Target as IAdvancedCategoryObject;
                foreach (IAdvancedCategoryArrow proj in firstArrows)
                {
                    if (proj.Target == t)
                    {
                        limIdArrows.Add(proj);
                        break;
                    }
                }
            }
            limIdArrow    = productCategory.GetArrowToDirectProduct(firstProduct, secondProduct, limIdArrows);
            limFuncArrows = new List <IAdvancedCategoryArrow>();
            foreach (CategoryObjectPair o in arrows.Keys)
            {
                IAdvancedCategoryArrow tar = this[o];
                foreach (IAdvancedCategoryArrow proj in firstArrows)
                {
                    if (proj.Target == tar.Source)
                    {
                        IAdvancedCategoryArrow ar = tar.Compose(category, proj);
                        limFuncArrows.Add(ar);
                        break;
                    }
                }
            }
            limFuncArrow = productCategory.GetArrowToDirectProduct(firstProduct, secondProduct, limFuncArrows);
            IEqualizerCategory equalizerCategory = category as IEqualizerCategory;

            limArrow  = equalizerCategory.GetEqualizer(limIdArrow, limFuncArrow);
            lim       = limArrow.Source as IAdvancedCategoryObject;
            limArrows = new Dictionary <IAdvancedCategoryObject, IAdvancedCategoryArrow>();
            foreach (IAdvancedCategoryArrow proj in firstArrows)
            {
                IAdvancedCategoryObject t  = proj.Target as IAdvancedCategoryObject;
                IAdvancedCategoryArrow  ar = proj.Compose(category, limArrow);
                limArrows[t] = ar;
            }
        }
コード例 #6
0
ファイル: CategoryDiagram.cs プロジェクト: Erroman/universal
        /// <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);
        }
コード例 #7
0
ファイル: CategoryDiagram.cs プロジェクト: Erroman/universal
        /// <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);
        }