コード例 #1
0
        public TreeStatistics MVABFSStatistics(long n, INCRCliqueTree tree)
        {
            // convert to SHET data structure for the statistics
            var dict = new Dictionary <int, SHET.TreeNode>();

            foreach (var edge in tree.EdgesList)
            {
                foreach (var node in new int[] { edge.Node1, edge.Node2 })
                {
                    if (!dict.ContainsKey(node))
                    {
                        dict[node] = new SHET.TreeNode(node)
                        {
                            State      = edge.SeperatorWeight == 0 ? SHET.TreeNode.NodeState.NewCC : SHET.TreeNode.NodeState.Valid,
                            CliqueList = tree.Cliques[node].Select(i => (int)i).ToList()
                        };
                    }
                }

                dict[edge.Node1].Adjoint.Add(dict[edge.Node2]);
                dict[edge.Node2].Adjoint.Add(dict[edge.Node1]);
            }

            var shetTree = dict.Values.ToList();

            var tmpSHET = new SHET.SHET();

            return(tmpSHET.SHETBFSStatistics(tree.Edges, shetTree));
        }
コード例 #2
0
        public static INCRCliqueTree GenerateKTree(long n, int k, Random random)
        {
            var node       = new INCRNode(Enumerable.Range(0, k + 1).Select(i => (uint)i));
            var cliqueTree = new INCRCliqueTree()
            {
                MaximalCliques = 1,
                Edges          = k * (k + 1) / 2,
                Cardinalities  = new List <int>()
                {
                    k + 1
                },
                Cliques = new List <INCRNode>()
                {
                    node
                }
            };

            for (int u = 1; u < n - k; u++)
            {
                var i   = random.Next(cliqueTree.MaximalCliques);
                var y   = random.Next(cliqueTree.Cardinalities[i]);
                var sep = cliqueTree.Cliques[i].Where((x, ii) => ii != y);
                // var newSep = new List<ushort>(sep);
                var newNode = new INCRNode(sep);
                newNode.Add((uint)(u + k));

                cliqueTree.Cliques.Add(newNode);
                cliqueTree.Cardinalities.Add(k + 1);
                cliqueTree.MaximalCliques++;
                cliqueTree.Edges += k;
                cliqueTree.EdgesList.Add(new INCREdge(i, cliqueTree.Cliques.Count - 1, null, k));
            }

            return(cliqueTree);
        }
コード例 #3
0
        public List <Stats> RunINCR(int runs, double edgesToAdd)
        {
            var allStats = new List <Stats>();

            for (int nIndex = 0; nIndex < Vertices.Length; nIndex++)
            {
                var n = Vertices[nIndex];
                foreach (var ed in EdgeDensity)
                {
                    var edgesBound = ed * ((n * (n - 1)) / 2L);
                    var k          = Math.Max(1, edgesToAdd * edgesBound);
                    var ktreeK     = 1.0 / 2 * (2 * n - 1 - Math.Sqrt(((2 * n - 1) * (2 * n - 1)) - (8 * edgesBound)));
                    ktreeK = (int)(Math.Floor(ktreeK));
                    var  kEdges  = (n - ktreeK - 1) * ktreeK + (ktreeK * (ktreeK + 1) / 2);
                    long ktreeK1 = (long)ktreeK + 1;
                    var  kEdges1 = (n - ktreeK1 - 1) * ktreeK1 + (ktreeK1 * (ktreeK1 + 1) / 2);

                    var stats = this.InitializeRunStats(n, ed, k, ktreeK, kEdges);
                    allStats.Add(stats);

                    for (int r = 0; r < runs; r++)
                    {
                        Console.WriteLine("------------------ Begin Run --------------------");
                        Console.WriteLine($"n:{n} \t ed:{ed.ToString("F2")} \t edgesBound: {edgesBound}");
                        Console.WriteLine($"k:{k} \t kTree:{ktreeK.ToString("F2")} \t kEdges: {kEdges}({edgesBound - kEdges})");
                        Console.WriteLine($"kTree + 1:{ktreeK1.ToString("F2")} \t kEdges + 1: {kEdges1}({edgesBound - kEdges1})");

                        var random = new Random();

                        INCRCliqueTree tree = null;
                        using (var sw = new Watch(stats.Times["GenerateKTree"]))
                        {
                            tree = INCRCliqueTree.GenerateKTree(n, (int)ktreeK, random);
                        }

                        using (var sw = new Watch(stats.Times["SplitEdgesK"]))
                        {
                            tree.SplitEdgesK((int)edgesBound, n, random, (int)k);
                        }

                        stats.Times["Total"].Add(stats.Times["GenerateKTree"].Last() + stats.Times["SplitEdgesK"].Last());
                        Console.WriteLine($"Generate K-Tree: {stats.Times["GenerateKTree"].Last()} s");
                        Console.WriteLine($"Split Edges K: {stats.Times["SplitEdgesK"].Last()} s");
                        this.CalculateRunStatistics(n, tree, stats);
                        this.PrintRunStatistics(stats);
                        Console.WriteLine("------------------ End Run --------------------");
                        tree = null;
                        GC.Collect();
                    }

                    var runStats = this.MergeStatistics(new List <Stats>()
                    {
                        stats
                    });
                    ExcelReporter.ExcelReporter.CreateSpreadsheetWorkbook($"IncrMem_{n}_{ed}", runStats);
                }
            }
            return(this.MergeStatistics(allStats));
        }
コード例 #4
0
        private void CalculateRunStatistics(long n, INCRCliqueTree tree, Stats stats)
        {
            var maxEdges = (n * (n - 1)) / 2L;

            stats.Edges.Add(tree.Edges);
            stats.Output["EdgeDensity"].Add((double)tree.Edges / maxEdges);

            var proc = System.Diagnostics.Process.GetCurrentProcess();

            stats.Output["Mem"].Add(proc.WorkingSet64 / (1024.0 * 1024.0));

            stats.CliqueTrees.Add(this.MVABFSStatistics(n, tree));
        }