/// <summary>
        /// Compute the partition block size distribution.
        /// </summary>
        /// <param name="graph"></param>
        /// <param name="labels"></param>
        /// <param name="k"></param>
        /// <returns></returns>
        public static Experiment PartitionBlockDistribution <TNode, TLabel>(MultiDirectedGraph <TNode, TLabel> graph)
        {
            var partitioner = new GraphPartitioner <TNode, TLabel>(graph);
            var partitions  = partitioner.MultilevelExactBisimulationReduction();
            int k_max       = partitions.Count - 1;

            var sizes = Utils.Distribution(partitions[k_max].Values).Values.ToArray();

            Array.Sort(sizes);
            Array.Reverse(sizes);

            var experiment = new Experiment(2)
            {
                Labels = new string[] { "Partition block", "Number of nodes" },
                Meta   = new string[] { "Blocks", graph.Name, },
                F      = i =>
                {
                    int index = Convert.ToInt32(i);
                    int size  = sizes[index];

                    return(new double[] { index + 1, size });
                },
            };

            experiment.Run(0, sizes.Length - 1, 1, 1);
            return(experiment);
        }
        /// <summary>
        /// Count the number of partition blocks in a graph.
        /// </summary>
        /// <typeparam name="TNode"></typeparam>
        /// <typeparam name="TLabel"></typeparam>
        /// <param name="graph"></param>
        /// <param name="labels"></param>
        /// <returns></returns>
        public static Experiment BisimulationPartitionSize <TNode, TLabel>(MultiDirectedGraph <TNode, TLabel> graph)
        {
            var partitioner = new GraphPartitioner <TNode, TLabel>(graph);
            var partitions  = partitioner.MultilevelExactBisimulationReduction();

            Experiment experiment = new Experiment(2)
            {
                Labels = new string[] { "k", "Number of blocks" },
                Meta   = new string[] { "Partition-size", graph.Name },
                F      = i =>
                {
                    var k = Convert.ToInt32(i);
                    var partitionCount = partitions[k].Values.Distinct().Count();

                    return(new double[] { k, partitionCount });
                },
            };

            experiment.Run(0, partitions.Count - 1, 1, 1);
            return(experiment);
            // experiment.Save(@"..\..\..\..\Analytics\BisimBlocks-" + graph.Name.ToLower() + ".tsv");
        }
Beispiel #3
0
        /// <summary>
        /// Entry point.
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            //*
            Dummy.Fix();
            return;

            //*/

            /*
             * AllPerformanceExperiments();
             * return;
             * //*/

            //*
            AllAnalyticsExperiments("Petrinet_no_labels");
            return;

            //*/

            // Ask for graph file
            string path    = Input("Please enter the path to the graph file", string.Copy);
            string outPath = Path.GetDirectoryName(path) + @"\..\Results";

            // Load graph and labels
            var graph = GraphLoader.LoadGraphML(path, int.Parse, int.Parse);

            /*
             * var partitioner = new GraphPartitioner<int, int>(graph);
             * var distributedPartitioner = new DistributedGraphPartitioner<int, int>(1, graph);
             * //*/

            /*
             * var estim = GraphGenerator.ReducedGraph(graph, distributedPartitioner.ExactBisimulationReduction);
             * var exact = GraphGenerator.ReducedGraph(graph, partitioner.EstimateBisimulationReduction);
             * //*/

            //*
            // GraphConverter.SaveToGraphML(estim, Path.GetDirectoryName(path) + @"\" + graph.Name + "_estim.xml");
            // GraphConverter.SaveToGraphML(exact, Path.GetDirectoryName(path) + @"\" + graph.Name + "_exact.xml");
            // GraphConverter.SaveToGraphML(coarse, Path.GetDirectoryName(path) + @"\" + graph.Name + "_coarse.xml");
            //*/

            // Samplers
            var samplers = new Func <double, MultiDirectedGraph <int, int> >[]
            {
                //* Normal samplers
                p => graph.Induce(graph.RN((int)(p * graph.NumNodes))),
                p => graph.Induce(graph.RE((int)(p * graph.NumEdges))),
                // p => graph.Induce(graph.LowDegreeFirst((int)(p * graph.NumNodes))),
                // p => graph.Induce(graph.GreedyLabels((int)(p * graph.NumNodes))),
                p => graph.Induce(graph.DistinctLabelsSB((int)(p * graph.NumNodes))),
                p => graph.Induce(graph.QueuedSampler <int, int, FifoQueue <int> >((int)(p * graph.NumNodes))),
                // p => graph.Induce(graph.QueuedSampler<int, int, LifoQueue<int>>((int)(p * graph.NumNodes))),
                // p => graph.Induce(graph.QueuedSampler<int, int, AiroQueue<int>>((int)(p * graph.NumNodes))),
                p => graph.Induce(graph.RandomWalkTeleport((int)(p * graph.NumNodes), 0.1)),
                //*/

                /* Approximation samplers
                 * p => estim.Induce(estim.RN((int)(p * graph.NumNodes))),
                 * p => estim.Induce(estim.RE((int)(p * graph.NumEdges))),
                 * // p => estim.Induce(estim.LowDegreeFirst((int)(p * graph.NumNodes))),
                 * // p => estim.Induce(estim.GreedyLabels((int)(p * graph.NumNodes))),
                 * p => estim.Induce(estim.DistinctLabelsSB((int)(p * graph.NumNodes))),
                 * p => estim.Induce(estim.QueuedSampler<int, int, FifoQueue<int>>((int)(p * graph.NumNodes))),
                 * // p => estim.Induce(estim.QueuedSampler<int, int, LifoQueue<int>>((int)(p * graph.NumNodes))),
                 * // p => estim.Induce(estim.QueuedSampler<int, int, AiroQueue<int>>((int)(p * graph.NumNodes))),
                 * p => estim.Induce(estim.RandomWalkTeleport((int)(p * graph.NumNodes), 0.1)),
                 * //*/
            };

            // Sampler names
            var samplerNames = new string[]
            {
                "RN",
                "RE",
                // "LDF",
                // "GL",
                "DLSB",
                "BFS",
                // "DFS",
                // "RFS",
                "RWT",
            };
            //*/

            //* Run many bisimulation experiments in batch
            var partitioner = new GraphPartitioner <int, int>(graph);
            var k_max       = partitioner.MultilevelExactBisimulationReduction().Count - 1;

            for (int k = 0; k <= k_max; k++)
            {
                for (int i = 0; i < samplers.Length; i++)
                {
                    var sampler     = samplers[i];
                    var samplerName = samplerNames[i];

                    // var experiment = Experiments.StandardBisimulationMetrics(graph, samplerName, sampler, k);
                    // Experiment.SaveSVG(outPath + @"\" + string.Join("_", experiment.Meta) + ".svg", experiment.Plot(0.0, 1.0));
                    // experiment.SaveTSV(outPath + @"\" + string.Join("_", experiment.Meta) + ".tsv");

                    var experiment = Experiments.WeightedBisimulationMetrics(graph, samplerName, sampler, k);
                    Experiment.SaveSVG(outPath + @"\" + string.Join("_", experiment.Meta) + ".svg", experiment.Plot(0.0, 1.0));
                    experiment.SaveTSV(outPath + @"\" + string.Join("_", experiment.Meta) + ".tsv");

                    Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] k=" + k + " sampler=" + samplerName);
                }
                ;
            }
            //*/

            /*
             * // var experiment = Analytics.ReachabilityProbabilityMassFunction(graph);
             * // var experiment = Experiments.BisimulationPartitionBlockCounts(graph, labels);
             * // var experiment = Experiments.FindKMax(graph, labels);
             * // var experiment = Experiments.TreeGeneratorPartitionSize(1, 20);
             * PlotForm plotForm = new PlotForm();
             * plotForm.Display(experiment.Plot(double.NaN, double.NaN));
             * plotForm.ShowDialog();
             * //*/

            /* Get k
             * int k = Input("Please enter a value for k in k-bisimulation", int.Parse);
             * //*/

            /*
             * var experiment = Experiments.DistanceProbabilityMassFunction(graph);
             * Experiment.SaveSVG(outPath + @"\" + string.Join("_", experiment.Meta) + ".svg", experiment.Plot(0, double.NaN));
             * experiment.SaveTSV(outPath + @"\" + string.Join("_", experiment.Meta) + ".tsv");
             * //*/

            /* Run bisimulation experiment
             * var experiment = Experiments.StandardBisimulationMetrics(graph, labels, () => GraphSampler.Funny(graph, labels));
             * Experiment.SaveSVG(outPath + @"\" + string.Join("_", experiment.Meta) + ".svg", experiment.Plot(0.0, 1.0));
             * experiment.SaveTSV(outPath + @"\" + string.Join("_", experiment.Meta) + ".tsv");
             * //*/

            /*
             * var experiment = Experiments.BisimulationPartitionSize(graph, labels);
             * // var experiment = Experiments.PartitionBlockDistribution(graph, labels);
             * Experiment.SaveSVG(outPath + @"\" + string.Join("_", experiment.Meta) + ".svg", experiment.Plot(double.NaN, double.NaN));
             * experiment.SaveTSV(outPath + @"\" + string.Join("_", experiment.Meta) + ".tsv");
             * //*/

            /*
             * PlotForm plotForm = new PlotForm();
             * plotForm.Display(experiment.Plot(0, double.NaN));
             * plotForm.ShowDialog();
             * //*/
        }