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

            foreach (var edge in tree.EdgesList)
            {
                foreach (var node in new int[] { edge.Node1, edge.Node2 })
                {
                    if (!dict.ContainsKey(node))
                    {
                        dict[node] = new TreeNode(node)
                        {
                            State      = edge.SeperatorWeight == 0 ? NodeState.NewCC : NodeState.Valid,
                            CliqueList = tree.Cliques[node].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();

            return(tmpSHET.SHETBFSStatistics(tree.Edges, shetTree));
        }
Exemple #2
0
        private void CalculateRunStatistics(long n, MVACliqueTree tree, Stats stats)
        {
            var maxEdges = (n * (n - 1)) / 2;

            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));
        }
        public static MVACliqueTree ExpandCliques(long n, Random random)
        {
            var cliqueTree = new MVACliqueTree()
            {
                Cliques = new List <MVANode>()
                {
                    new MVANode()
                },
                Cardinalities = new List <int>()
                {
                    1
                },
                MaximalCliques = 1
            };

            for (int u = 0; u < n; u++)
            {
                var i = random.Next(cliqueTree.MaximalCliques);
                var t = random.Next(1, cliqueTree.Cardinalities[i] + 1);
                if (t == cliqueTree.Cardinalities[i])
                {
                    // expand old
                    cliqueTree.Cliques[i].Add(u);
                    cliqueTree.Cardinalities[i]++;
                }
                else
                {
                    var seperator = RandomSample <int>(cliqueTree.Cliques[i], t, random);
                    var newNode   = new MVANode()
                    {
                        u
                    };
                    newNode.UnionWith(seperator);
                    cliqueTree.Cliques.Add(newNode);
                    cliqueTree.MaximalCliques++;
                    cliqueTree.Cardinalities.Add(t + 1);
                    cliqueTree.EdgesList.Add(new MVAEdge(i, cliqueTree.MaximalCliques - 1, new HashSet <int>(seperator), t));
                }

                cliqueTree.Edges += t;
            }

            return(cliqueTree);
        }
Exemple #4
0
        public List <Stats> RunMVA(int runs)
        {
            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 stats      = this.InitializeRunStats(n, ed);
                    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}");

                        var random = new Random();

                        MVACliqueTree tree = null;
                        using (var sw = new Watch(stats.Times["ExpandCliques"]))
                        {
                            tree = MVACliqueTree.ExpandCliques(n, random);
                        }
                        using (var sw = new Watch(stats.Times["MergeCliques"]))
                        {
                            tree.MergeCliques((long)edgesBound, random);
                        }

                        stats.Times["Total"].Add(stats.Times["ExpandCliques"].Last() + stats.Times["MergeCliques"].Last());
                        Console.WriteLine($"Expand Cliques: {stats.Times["ExpandCliques"].Last()} s");
                        Console.WriteLine($"Merge Cliques: {stats.Times["MergeCliques"].Last()} s");
                        this.CalculateRunStatistics(n, tree, stats);
                        this.PrintRunStatistics(stats);
                        Console.WriteLine("------------------ End Run --------------------");
                    }
                }
            }

            return(this.MergeStatistics(allStats));
        }