Microsoft.Zing.ZingExplorerStateLessSearch.IterativeSearchStateSpace C# (CSharp) Method

IterativeSearchStateSpace() protected method

protected IterativeSearchStateSpace ( ) : ZingerResult
return ZingerResult
        protected override ZingerResult IterativeSearchStateSpace()
        {
            //outer loop to search the state space Iteratively
            do
            {
                //Increment the iterative bound
                ZingerConfiguration.zBoundedSearch.IncrementIterativeBound();

                //call the frontier reset function
                GlobalFrontierSet.StartOfIterationReset();

                try
                {
                    searchWorkers = new Task[ZingerConfiguration.DegreeOfParallelism];
                    //create parallel search threads
                    for (int i = 0; i < ZingerConfiguration.DegreeOfParallelism; i++)
                    {
                        searchWorkers[i] = Task.Factory.StartNew(SearchStateSpace, i);
                        System.Threading.Thread.Sleep(10);
                    }

                    // Wait for all readers to Finish
                    GlobalFrontierSet.WaitForAllReaders(CancelTokenZingExplorer.Token);
                    // Wait for all search workers to Finish
                    Task.WaitAll(searchWorkers);
                    // Wait for all writer to Finish
                    GlobalFrontierSet.WaitForAllWriters(CancelTokenZingExplorer.Token);
                    //For Debug
                    //GLobalFrontierSet.PrintAll();
                }
                catch (AggregateException ex)
                {
                    foreach (var inner in ex.InnerExceptions)
                    {
                        if ((inner is ZingException))
                        {
                            return lastErrorFound;
                        }
                        else
                        {
                            ZingerUtilities.PrintErrorMessage("Unknown Exception in Zing:");
                            ZingerUtilities.PrintErrorMessage(inner.ToString());
                            return ZingerResult.ZingRuntimeError;
                        }
                    }
                }

                ZingerStats.NumOfFrontiers = GlobalFrontierSet.Count();
                ZingerStats.PrintPeriodicStats();
            }
            while (GlobalFrontierSet.Count() > 0 && !ZingerConfiguration.zBoundedSearch.checkIfFinalCutOffReached());

            return ZingerResult.Success;
        }