Example #1
0
        /// <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);
            }
        }
Example #2
0
        /// <summary>
        /// Creates digraph from objects and arrows
        /// </summary>
        /// <param name="objects">Objects</param>
        /// <param name="arrows">Arrows</param>
        /// <returns>The digraph</returns>
        static public Digraph CreateDigraph(IList <IObjectLabel> objects, IList <IArrowLabel> arrows)
        {
            Digraph graph = new Digraph();

            foreach (IArrowLabel label in arrows)
            {
                label.SourceNumber = objects.IndexOf(label.Source);
                label.TargetNumber = objects.IndexOf(label.Target);
            }
            List <DigraphVertex> vertices = new List <DigraphVertex>();

            foreach (IObjectLabel label in objects)
            {
                DigraphVertex v = new DigraphVertex(graph);
                vertices.Add(v);
                v.Object = label;
            }
            foreach (IArrowLabel label in arrows)
            {
                DigraphEdge edge = new DigraphEdge();
                edge.Object = label;
                if (label.SourceNumber is Int32 && label.TargetNumber is Int32)
                {
                    int           sourceNum = (int)label.SourceNumber;
                    DigraphVertex vs        = vertices[sourceNum] as DigraphVertex;
                    edge.Source = vs;
                    int           targetNum = (int)label.TargetNumber;
                    DigraphVertex vt        = vertices[targetNum] as DigraphVertex;
                    edge.Target = vt;
                }
            }
            return(graph);
        }
Example #3
0
 /// <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);
     }
 }