public PhonesActivityWindowManger(int numOfNodes, int amsVectorLength, HashFunctionTable[] hashFunctionTable, PhonesActivityDataParser dataParser, Lazy <WindowedStatistics> window, GeographicalDistributing distributingMethod)
 {
     NumOfNodes         = numOfNodes;
     AmsVectorLength    = amsVectorLength;
     HashFunctionTable  = hashFunctionTable;
     DataParser         = dataParser;
     Window             = window;
     DistributingMethod = distributingMethod;
 }
        public static void RunMilanoPhoneActivity(Random rnd, int numOfNodes, int window,
                                                  ApproximationType approximation, int width,
                                                  int height, GeographicalDistributing distributingMethod,
                                                  string phoneActivityDir, string resultDir)
        {
            var vectorLength         = width * height;
            var hashFunction         = FourwiseIndepandantFunction.Init(rnd);
            var hashFunctionsTable   = HashFunctionTable.Init(numOfNodes, vectorLength, hashFunction);
            var secondMomentFunction = new SecondMoment(width, height);
            var resultPath           =
                PathBuilder.Create(resultDir, "AMS_F2")
                .AddProperty("Dataset", "MilanoPhoneActivity")
                .AddProperty("Nodes", numOfNodes.ToString())
                .AddProperty("VectorLength", vectorLength.ToString())
                .AddProperty("Width", width.ToString())
                .AddProperty("Height", height.ToString())
                .AddProperty("Window", window.ToString())
                .AddProperty("Distributing", distributingMethod.Name)
                .AddProperty("Approximation", approximation.AsString())
                .ToPath("csv");

            using (var resultCsvFile = AutoFlushedTextFile.Create(resultPath, AccumaltedResult.Header(numOfNodes) + ",F2"))
            {
                var phonesActivityDataParser   = PhonesActivityDataParser.Create(phoneActivityDir);
                var phonesActivityWindowManger = PhonesActivityWindowManger.Init(window, numOfNodes, vectorLength, hashFunctionsTable, phonesActivityDataParser, distributingMethod);
                var initVectors = phonesActivityWindowManger.GetCurrentVectors();
                var multiRunner = MultiRunner.InitAll(initVectors, numOfNodes, vectorLength, approximation, secondMomentFunction.MonitoredFunction);
                while (phonesActivityWindowManger.TakeStep())
                {
                    var shouldEnd     = new StrongBox <bool>(false);
                    var changeVectors = phonesActivityWindowManger.GetChangeVector();
                    // var sumVector = Vector.SumVector(phonesActivityWindowManger.Window.Value.CurrentNodesCountVectors());
                    //var f2Value = sumVector.IndexedValues.Values.Sum(x => x * x);
                    multiRunner.Run(changeVectors, rnd, false)
                    //    .SideEffect(a => shouldEnd.Value = shouldEnd.Value || (a.MonitoringScheme is MonitoringScheme.Oracle && a.NumberOfFullSyncs > 0))
                    .Select(r => r.AsCsvString())            //+ "," + f2Value)
                    .ForEach(resultCsvFile.WriteLine);
                    //if (shouldEnd.Value)
                    //  break;
                }
            }
        }
        public static PhonesActivityWindowManger Init(int window, int numOfNodes, int amsVectorLength, HashFunctionTable[] hashFunctionTable, PhonesActivityDataParser phonesActivityDataParser, GeographicalDistributing distributingMethod)
        {
            StrongBox <PhonesActivityWindowManger> phonesActivityWindowManager = new StrongBox <PhonesActivityWindowManger>(null);
            var lazyWindow = new Lazy <WindowedStatistics>(() => WindowedStatistics.Init(ArrayUtils.Init(window, _ => phonesActivityWindowManager.Value.GetNextAmsVectors())));

            phonesActivityWindowManager.Value = new PhonesActivityWindowManger(numOfNodes, amsVectorLength, hashFunctionTable, phonesActivityDataParser, lazyWindow, distributingMethod);
            return(phonesActivityWindowManager.Value);
        }