public void Start()
 {
     _results = new List <ReliabilityResult>();
     foreach (var param in _parameters)
     {
         var routingResult    = _algorithm_router.FindPath(param);
         var bruteForceResult = _brute_router.FindPath(param);
         Console.WriteLine("Algorithm result: ");
         ResultPresenter.PrintPath(routingResult);
         Console.WriteLine("Brute Force result: ");
         ResultPresenter.PrintPath(bruteForceResult);
         var routingReliability    = CalculateReliability(routingResult, param);
         var bruteForceReliability = CalculateReliability(bruteForceResult, param);
         var instanceNumber        = _parameters.IndexOf(param);
         Console.WriteLine($"alg: {routingReliability}");
         Console.WriteLine($"bf:{bruteForceReliability}");
         Console.WriteLine($"in:{instanceNumber}");
         var result = new ReliabilityResult()
         {
             AlgorithmPath    = routingResult,
             BruteForcePath   = bruteForceResult,
             InstanceSize     = param.Instance.V_size,
             InstanceNumber   = instanceNumber,
             AlgorithmResult  = routingReliability,
             BruteForceResult = bruteForceReliability,
         };
         _results.Add(result);
     }
     Common.Common.SaveObject(_results, "ReliabilityResults.json");
 }
        public static ReliabilityResult RunConcurrentReliabilityTest(int numIterations, int degreeParallelism,
                                                                     Func <bool> operation)
        {
            int i;
            var taskList = new Task <ReliabilityResult> [degreeParallelism];

            int subIterations = numIterations / degreeParallelism;

            for (i = 0; i < degreeParallelism; i++)
            {
                var t = new Task <ReliabilityResult>(() => RunReliabilityTest(subIterations, operation));
                taskList[i] = t;
            }

            for (i = 0; i < degreeParallelism; i++)
            {
                taskList[i].Start();
            }

            Task.WaitAll(taskList);

            bool valid  = true;
            int  passed = 0;
            int  failed = 0;

            for (i = 0; i < degreeParallelism; i++)
            {
                valid  &= taskList[i].Result.IsValid;
                passed += taskList[i].Result.Passed;
                failed += taskList[i].Result.Failed;
            }

            var res = new ReliabilityResult
            {
                IsValid = valid,
                Passed  = passed,
                Failed  = failed
            };

            for (i = 0; i < degreeParallelism; i++)
            {
                taskList[i].Dispose();
            }

            return(res);
        }
        public static ReliabilityResult RunReliabilityTest(int numIterations, Func <bool> operation)
        {
            var rv = new ReliabilityResult();

            // Same operation as the functional test, we just
            // do a lot of them.
            for (int i = 0; (i < numIterations); i++)
            {
                if (operation())
                {
                    rv.Passed++;
                }
                else
                {
                    rv.Failed++;
                }
            }

            rv.IsValid = ((rv.Passed + rv.Failed) > 0);
            return(rv);
        }