/// <summary>
        /// Инициализирует новый экземпляр класса <see cref="HammockFinder.HammockTree"/>
        /// </summary>
        public HammockTree()
        {
            Identifier = -1;
            Start = -1;
            End = -1;

            Size = 0;

            Parent = null;

            Childs = new HashSet<HammockTree>();
            Siblings = new HashSet<HammockTree>();
        }
        /// <summary>
        ///  Строит дерево гамаков по данному графу
        /// </summary>
        /// <returns>Возвращает указатель на корень дерева</returns>
        /// <param name="gi">Граф</param>
        public static HammockTree CreateHammockTree(GraphInfo gi)
        {
            var root = new HammockTree();

            foreach (var node in gi.ListOfHammocks)
                if (node.Size > root.Size)
                    root = node;

            root.FindChildren(gi);

            return root;
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HammockFinder.GraphInfo"/> class.
        /// </summary>
        public GraphInfo()
        {
            Gr = new Graph();

            Include = new SortedSet<int>();
            ListOfHammocks = new List<HammockTree>();
            HammocksAtVertex = new List<SortedSet<int>>();
            HammocksStartedAtVertex = new List<SortedSet<int>>();

            Root = new HammockTree();

            Vertices = new List<Figure>();
            Indexes = new SortedDictionary<Figure, int>(new Comparator());
        }
        /// <summary>
        ///  Находит гамак, начинающийся в данной вершине максимального размера меньше заданного.
        ///  Это есть ребенок данного гамака
        /// </summary>
        /// <returns>Гамак</returns>
        /// <param name="gi">Граф</param>
        /// <param name="v">Номер вершины</param>
        /// <param name="size">Размер текущего гамака</param>
        protected virtual HammockTree GetChildren(GraphInfo gi, int v, int size)
        {
            var ans = new HammockTree();

            foreach (var node in gi.HammocksStartedAtVertex[v])
                if (gi.ListOfHammocks[node].Size > ans.Size &&
                    gi.ListOfHammocks[node].Size < size)
                    ans = gi.ListOfHammocks[node];

            return ans;
        }
Example #5
0
        /// <summary>
        /// Всем вершинам гамака устанваливает принадлежность данному гамаку.
        /// </summary>
        /// <returns>Количество вершин в гамаке</returns>
        /// <param name="hammock">Гамак</param>
        int AddHammockToVertices(HammockTree hammock)
        {
            var q = new Queue<int>();
            int count = 0;

            q.Enqueue(hammock.Start);

            while (q.Count > 0)
            {
                int cur = q.Dequeue();

                if (HammocksAtVertex[cur].Contains(hammock.Identifier))
                    continue;

                count++;
                HammocksAtVertex[cur].Add(hammock.Identifier);

                if (cur == hammock.End)
                    continue;

                foreach (int next in Gr[cur])
                    if (!HammocksStartedAtVertex[next].Contains(hammock.Identifier))
                        q.Enqueue(next);
            }

            return count;
        }