Ejemplo n.º 1
0
        private static void ShrinkGraph()
        {
            Console.WriteLine("Building");
            var graph = BuildGraph(DictionaryPath);

            Console.WriteLine("Converting");
            var nodes = ConvertToNewNodes(graph);

            Console.WriteLine("Converted");

            var round = 0;

            for (var coarse = 1; coarse < 10; coarse++)
            {
                int lastCost;
                var newCost = nodes.Count(x => !x.Removed);
                Console.WriteLine($"Coarsen: {coarse}");
                do
                {
                    var edgeCount = nodes.Sum(x => x.Children.Count);
                    Console.WriteLine($"Round: {round:D5} Count: {newCost:D6} Edges: {edgeCount:D6}");
                    round++;
                    UpDog(nodes, coarse);
                    lastCost = newCost;
                    newCost  = nodes.Count(x => !x.Removed);
                } while (newCost != lastCost);
            }

            NewNode.WriteD3JsonFormat(nodes, @"C:\Users\JPelleri\source\repos\portent\portent.Benchmark\graph2.json");
        }
Ejemplo n.º 2
0
        private static NewNode[] ConvertToNewNodes(CompressedSparseRowGraph graph)
        {
            var nodes = new NewNode[graph.FirstChildEdgeIndex.Length - 1];

            for (var i = 0; i < nodes.Length; i++)
            {
                nodes[i] = new NewNode(i);
            }

            for (var i = 1; i <= nodes.Length; i++)
            {
                var first  = graph.FirstChildEdgeIndex[i - 1];
                var last   = graph.FirstChildEdgeIndex[i];
                var parent = nodes[i - 1];
                for (var j = first; j < last; j++)
                {
                    var index = graph.EdgeToNodeIndex[j];
                    var child = nodes[Math.Abs(index)];

                    /*if (index < 0)
                     * {
                     *  child.Terminal = true;
                     * }*/

                    parent.Children.Add(child);
                    child.Parents.Add(parent);
                }
            }

            return(nodes);
        }
Ejemplo n.º 3
0
        public void MergeChild(NewNode child)
        {
            Children.Remove(child);
            foreach (var grandchild in child.Children)
            {
                grandchild.Parents.Remove(child);
                if (Children.Add(grandchild))
                {
                    grandchild.Parents.Add(this);
                }
            }

            child.Parents.Remove(this);
            if (child.Parents.Count == 0)
            {
                child.Removed = true;
                child.Children.Clear();
            }
        }