예제 #1
0
        /// <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;
            }
        }
예제 #2
0
        /// <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);
        }