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

SearchStateSpace() protected method

protected SearchStateSpace ( object obj ) : void
obj object
return void
        protected override void SearchStateSpace(object obj)
        {
            int myThreadId = (int)obj;
            while (!GlobalFrontierSet.IsCompleted())
            {
                FrontierNode fNode = GlobalFrontierSet.GetNextFrontier();
                if (fNode == null)
                {
                    //Taking item from the global frontier failed
                    Contract.Assert(GlobalFrontierSet.IsCompleted());
                    continue;
                }
                TraversalInfo startState = fNode.GetTraversalInfo(StartStateStateImpl, myThreadId);

                //Check if we need to explore the current frontier state
                if (!MustExplore(startState) && !ZingerConfiguration.DoDelayBounding)
                {
                    continue;
                }

                if (ZingerConfiguration.zBoundedSearch.checkIfIterativeCutOffReached(fNode.Bounds))
                {
                    GlobalFrontierSet.Add(startState);
                    continue;
                }

                //create search stack
                Stack<TraversalInfo> LocalSearchStack = new Stack<TraversalInfo>();
                LocalSearchStack.Push(startState);

                //dp local bounded dfs using the local search stack
                while (LocalSearchStack.Count() > 0)
                {
                    //check if cancellation token is triggered
                    if (CancelTokenZingExplorer.IsCancellationRequested)
                    {
                        return;
                    }

                    //start exploring the top of stack
                    TraversalInfo currentState = LocalSearchStack.Peek();

                    //update the maximum depth
                    ZingerStats.MaxDepth = Math.Max(ZingerStats.MaxDepth, currentState.CurrentDepth);
                    //Check if the DFS Stack Overflow has occured.
                    if (currentState.CurrentDepth > ZingerConfiguration.BoundDFSStackLength)
                    {
                        //BUG FOUND
                        //update the safety traces
                        SafetyErrors.Add(currentState.GenerateNonCompactTrace());
                        // return value
                        this.lastErrorFound = ZingerResult.DFSStackOverFlowError;

                        throw new ZingerDFSStackOverFlow();
                    }

                    //Add current state to frontier if the bound is greater than the cutoff and we have fingerprinted the state (its not a single successor state)
                    if (ZingerConfiguration.zBoundedSearch.checkIfIterativeCutOffReached(currentState.zBounds) && currentState.IsFingerPrinted)
                    {
                        GlobalFrontierSet.Add(currentState);
                        //since current state is add to the frontier; pop it
                        LocalSearchStack.Pop();

                        continue;
                    }

                    // OK. Current state is not at the frontier cutoff so lets explore further
                    TraversalInfo nextState = currentState.GetNextSuccessor();

                    //All successors explored already
                    if (nextState == null)
                    {
                        //since all successors explored pop the stack
                        LocalSearchStack.Pop();
                        continue;
                    }

                    //Check if its a terminal state
                    TerminalState terminalState = nextState as TerminalState;
                    if (terminalState != null)
                    {
                        if (terminalState.IsErroneousTI)
                        {
                            lock (SafetyErrors)
                            {
                                //BUG FOUND
                                //update the safety traces
                                SafetyErrors.Add(nextState.GenerateNonCompactTrace());
                                // return value
                                this.lastErrorFound = nextState.ErrorCode;
                            }

                            //find all errors ??
                            if (ZingerConfiguration.StopOnError)
                            {
                                //Stop all tasks
                                CancelTokenZingExplorer.Cancel(true);
                                throw nextState.Exception;
                            }
                        }

                        //else continue
                        continue;
                    }

                    if (MustExplore(nextState) && !SearchStackContains(LocalSearchStack, nextState))
                    {
                        LocalSearchStack.Push(nextState);
                        continue;
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }