Пример #1
0
        /// <summary>
        /// Compute missing edges on an incomplete MTG at a given scale.
        /// </summary>
        /// <param name="tree"></param>
        /// <param name="scale"></param>
        /// <param name="edgeTypeProperty"></param>
        /// <returns> Returns true. </returns>
        bool ComputeMissingEdges(mtg tree, int scale, Dictionary <int, dynamic> edgeTypeProperty = null)
        {
            List <int> roots = tree.Roots(scale);

            foreach (int vid in roots)
            {
                List <int> components = tree.Components(vid);
                if (components == null || components == new List <int>()
                {
                })
                {
                    Console.WriteLine("Error ! Missing component for vertex " + vid);
                    continue;
                }
                else
                {
                    int componentId = components[0];

                    if (tree.Parent(componentId) == null)
                    {
                        continue;
                    }

                    int?parentId = tree.Complex((int)tree.Parent(componentId));

                    if (parentId == null)
                    {
                        Console.WriteLine("Error ! Missing parent for vertex" + vid);
                        continue;
                    }

                    if (edgeTypeProperty != null)
                    {
                        try
                        {
                            string edgeType = edgeTypeProperty[componentId];
                            tree.AddChild((int)parentId, new Dictionary <string, dynamic>()
                            {
                                { "Edge_Type", edgeType }
                            }, vid);
                        }
                        catch (KeyNotFoundException)
                        {
                            tree.AddChild((int)parentId, vid);
                        }
                    }
                    else
                    {
                        tree.AddChild((int)parentId, vid);
                    }
                }
            }
            return(true);
        }