コード例 #1
0
ファイル: PTesterCommandLine.cs プロジェクト: up1/P
        public static void Main(string[] args)
        {
            var options = ParseCommandLine(args);

            if (options == null)
            {
                Environment.Exit((int)TestResult.InvalidParameters);
            }

            var       asm = Assembly.LoadFrom(options.inputFileName);
            StateImpl s   = (StateImpl)asm.CreateInstance("P.Program.Application",
                                                          false,
                                                          BindingFlags.CreateInstance,
                                                          null,
                                                          new object[] { true },
                                                          null,
                                                          new object[] { });

            if (s == null)
            {
                throw new ArgumentException("Invalid assembly");
            }
            int numOfSchedules  = 0;
            int numOfSteps      = 0;
            var randomScheduler = new Random(1);

            while (numOfSchedules < 100)
            {
                var currImpl = (StateImpl)s.Clone();
                Console.WriteLine("-----------------------------------------------------");
                Console.WriteLine("New Schedule:");
                Console.WriteLine("-----------------------------------------------------");
                numOfSteps = 0;
                while (numOfSteps < 1000)
                {
                    if (currImpl.EnabledMachines.Count == 0)
                    {
                        break;
                    }

                    var num        = currImpl.EnabledMachines.Count;
                    var choosenext = randomScheduler.Next(0, num);
                    currImpl.EnabledMachines[choosenext].PrtRunStateMachine();
                    if (currImpl.Exception != null)
                    {
                        if (currImpl.Exception is PrtAssumeFailureException)
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Exception hit during execution: {0}", currImpl.Exception.ToString());
                            Environment.Exit(-1);
                        }
                    }
                    numOfSteps++;
                }
                numOfSchedules++;
            }
        }
コード例 #2
0
        /// <summary>
        /// For convergence detection:
        /// c -> cp
        /// |    |
        /// |    |
        /// a -> ap, bp = alpha(cp) (MUST: bp in A)
        ///
        /// Dump cp to file if cp's abstract state is a competitor
        /// </summary>
        /// <param name="c"> a concrete state</param>
        /// <param name="cp">the successor of c, cp means c'</param>
        static void CheckPredHash(StateImpl c, StateImpl cp)
        {
            /// build the abstract state a of c
            var a = (StateImpl)c.Clone();

            a.AbstractMe();
            /// only perfom actions when a == predecessor?
            if (a.GetHashCode() == StateImpl.predHash)
            {
                var bp = (StateImpl)cp.Clone();
                bp.AbstractMe();

                var bp_hash = bp.GetHashCode();
                if (competitors.Add(bp_hash))
                {
                    var bp_SW = new StreamWriter("reached" + (competitors.Count - 1).ToString() + ".txt");
                    bp_SW.WriteLine(bp.ToPrettyString());
                    bp_SW.Close();
                }
            }
        }
コード例 #3
0
ファイル: PTesterCommandLine.cs プロジェクト: cristicmf/P
        public static void Main(string[] args)
        {
            var options = ParseCommandLine(args);

            if (options == null)
            {
                Environment.Exit((int)TestResult.InvalidParameters);
            }

            if (options.UsePSharp && options.isRefinement)
            {
                Console.WriteLine("Error: Refinement checking isn't yet supported with /psharp flag");
                Environment.Exit((int)TestResult.InvalidParameters);
            }

            if (options.isRefinement)
            {
                var refinementCheck = new RefinementChecking(options);
                if (options.LHSModel == null)
                {
                    refinementCheck.RunCheckerRHS();
                }
                else
                {
                    refinementCheck.RunCheckerLHS();
                }
                return;
            }

            var       asm = Assembly.LoadFrom(options.inputFileName);
            StateImpl s   = (StateImpl)asm.CreateInstance("P.Program.Application",
                                                          false,
                                                          BindingFlags.CreateInstance,
                                                          null,
                                                          new object[] { true },
                                                          null,
                                                          new object[] { });

            if (s == null)
            {
                throw new ArgumentException("Invalid assembly");
            }

            if (options.UsePSharp)
            {
                RunPSharpTester(s);
                return;
            }

            int maxNumOfSchedules = 10000;
            int maxDepth          = 5000;
            int numOfSchedules    = 0;
            int numOfSteps        = 0;
            var randomScheduler   = new Random(DateTime.Now.Millisecond);

            while (numOfSchedules < maxNumOfSchedules)
            {
                var currImpl = (StateImpl)s.Clone();
                if (numOfSchedules % 10 == 0)
                {
                    Console.WriteLine("-----------------------------------------------------");
                    Console.WriteLine("Total Schedules Explored: {0}", numOfSchedules);
                    Console.WriteLine("-----------------------------------------------------");
                }
                numOfSteps = 0;
                while (numOfSteps < maxDepth)
                {
                    if (currImpl.EnabledMachines.Count == 0)
                    {
                        break;
                    }

                    var num        = currImpl.EnabledMachines.Count;
                    var choosenext = randomScheduler.Next(0, num);
                    currImpl.EnabledMachines[choosenext].PrtRunStateMachine();
                    if (currImpl.Exception != null)
                    {
                        if (currImpl.Exception is PrtAssumeFailureException)
                        {
                            break;
                        }
                        else if (currImpl.Exception is PrtException)
                        {
                            Console.WriteLine(currImpl.errorTrace.ToString());
                            Console.WriteLine("ERROR: {0}", currImpl.Exception.Message);
                            Environment.Exit(-1);
                        }
                        else
                        {
                            Console.WriteLine(currImpl.errorTrace.ToString());
                            Console.WriteLine("[Internal Exception]: Please report to the P Team");
                            Console.WriteLine(currImpl.Exception.ToString());
                            Environment.Exit(-1);
                        }
                    }

                    numOfSteps++;

                    //print the execution if verbose
                    if (options.verbose)
                    {
                        Console.WriteLine("-----------------------------------------------------");
                        Console.WriteLine("Execution {0}", numOfSchedules);
                        Console.WriteLine(currImpl.errorTrace.ToString());
                    }
                }
                numOfSchedules++;
            }
        }
コード例 #4
0
        /// <summary>
        /// --PL: Queue-unbounded exploration, in DFS mode
        /// </summary>
        /// <param name="queueAbstraction">Abstracting queue or not, default is not (set param as false)</param>
        public static void Dfs(bool queueAbstraction = false)
        {
            /// currently, we only implemented the exploration based on state hashing
            if (!useStateHashing)
            {
                throw new NotImplementedException();
            }

            Console.WriteLine("Using "
                              + (PrtEventBuffer.k == 0 ? "unbounded queue" : "queue bound of " + PrtEventBuffer.k.ToString()));
            /// Throw away states obtained from last rounds as all of them are static variables
            concretesInHash.Clear();
            abstractsInHash.Clear();
            abstractSuccsInHash.Clear();

#if DEBUG
            int max_queue_size = 0;
            int max_stack_size = 0;
#endif
            /// --PL: dump states & transitions to files
            StreamWriter concretesFile     = null;
            StreamWriter abstractsFile     = null;
            StreamWriter abstractSuccsFile = null;
            StreamWriter transitionsFile   = null;
            if (fileDump)
            {
                /// add "0" for name formating
                var suffix = (PrtEventBuffer.k < 10 ? "0" : "") + PrtEventBuffer.k.ToString();
                concretesFile = new StreamWriter(Constants.dumpFileConcretePrefix
                                                 + suffix
                                                 + Constants.dumpFileExtension);
                abstractsFile = new StreamWriter(Constants.dumpFileAbstractPrefix
                                                 + suffix
                                                 + Constants.dumpFileExtension);
                abstractSuccsFile = new StreamWriter(Constants.dumpFileAbstractSuccPrefix
                                                     + suffix
                                                     + Constants.dumpFileExtension);
                transitionsFile = new StreamWriter(Constants.dumpFileTransitionPrefix
                                                   + suffix
                                                   + Constants.dumpFileExtension);
            }

            Debug.Assert(start != null);
            var startClone = (StateImpl)start.Clone(); // we need a fresh clone in each iteration (k) of Dfs

            /// worklist, implemented using stack
            var worklist = new Stack <BacktrackingState>();
            // TODO: the following piece of code is duplicate. Need to refine it.
            worklist.Push(new BacktrackingState(startClone));
            var startHash = startClone.GetHashCode();
            concretesInHash.Add(startHash);
            if (fileDump)
            {
                concretesFile.Write(startClone.ToPrettyString());
                concretesFile.WriteLine(Constants.consoleSeparator);
                transitionsFile.WriteLine(startHash);
            }

            if (queueAbstraction)
            {
                var startAbstract = (StateImpl)start.Clone();
                startAbstract.AbstractMe(); // abstract queue

                abstractsInHash.Add(startAbstract.GetHashCode());
                /// compute abstract succs right way
                startAbstract.CollectAbstractSuccessors(abstractSuccsInHash, abstractSuccsFile);
                if (fileDump)
                {
                    abstractsFile.Write(startAbstract.ToPrettyString());
                    abstractsFile.WriteLine(Constants.consoleSeparator);
                }
            }

            /// the main loop of DFS
            while (worklist.Count != 0) /// if worklist is not empty
            {
#if false                               // code for investigating memory usage
                if (worklist.Count == 5000)
                {
                    Console.WriteLine("Stack depth of 5000 reached");

                    GC.Collect();
                    var mem1 = GC.GetTotalMemory(true) / (1024.0 * 1024.0);
                    Console.WriteLine("Current memory usage = {0} MB", mem1.ToString("F2"));

                    // lets clone
                    var stackarr = worklist.ToArray();
                    var newStack = new List <StateImpl>();
                    for (int i = 0; i < stackarr.Length; i++)
                    {
                        newStack.Add((StateImpl)stackarr[i].State.Clone());
                    }

                    GC.Collect();
                    var mem2 = GC.GetTotalMemory(true) / (1024.0 * 1024.0);

                    Console.WriteLine("Memory usage after cloning the stack = {0} MB", mem2.ToString("F2"));
                    Console.WriteLine("Average usage per state = {0} MB", (mem2 - mem1) / 5000.0);

                    Environment.Exit(0);
                }
#endif
                /// -PL: pop a state from worklist, and operate on it
                var curr = worklist.Pop();
                if (curr.CurrIndex >= curr.State.EnabledMachines.Count) // if "done" with curr
                {
                    continue;
                }

                /// Get a successor by executing the enabled machine pointed to by currIndex.
                /// Also, advance currIndex and/or choiceIndex and push curr state back to worklist
                /// TODO: try BFS
                BacktrackingState succ = Execute(curr);
                worklist.Push(curr); // CurrIndex of curr has been updated

                // if we are in competitor finding mode
                if (StateImpl.mode == StateImpl.ExploreMode.Competitor)
                {
                    CheckPredHash(curr.State, succ.State);
                }

                /// check for failure before adding new state: may fail due
                /// to failed assume, in which case we don't want to add
                if (!succ.State.CheckFailure(succ.depth))
                {
                    // update concrete state hashset
                    var succHash = succ.State.GetHashCode();
                    if (!concretesInHash.Add(succHash)) // -- PL: if successor has been explored
                    {
                        continue;
                    }
                    if (!succ.State.CheckConcreteStateInvariant())
                    {
                        throw new QuTLException("QuTL formula fails in concete model checking!");
                    }
                    worklist.Push(succ);
#if DEBUG
                    max_stack_size = Math.Max(max_stack_size, worklist.Count);
#endif

                    if (fileDump)
                    {
                        concretesFile.Write(succ.State.ToPrettyString()); // + " = " + succHash.ToPrettyString());
                        concretesFile.WriteLine(Constants.consoleSeparator);
                        transitionsFile.WriteLine("{0} -> {1}", curr.State.GetHashCode(), succHash);
                    }

                    if (queueAbstraction)
                    {
                        var succAbs = (StateImpl)succ.State.Clone();
                        succAbs.AbstractMe();
                        var succAbsHash = succAbs.GetHashCode();

                        #if false
                        #region dirty code, debugging============================
                        var currAbs = (StateImpl)curr.State.Clone();
                        currAbs.AbstractMe();
                        if (currAbs.GetHashCode() == -105414283)
                        {
                            Console.WriteLine("%%%%%%%%%%%%%%%%%%% = beginning ========");
                            Console.WriteLine(curr.State.ToPrettyString());
                            Console.WriteLine();
                            Console.WriteLine(currAbs.ToPrettyString());
                            Console.WriteLine(succ.State.ToPrettyString());
                            Console.WriteLine("%%%%%%%%%%%%%%%%%%% = " + succAbsHash);
                            Console.WriteLine(succAbs.ToPrettyString());
                            Console.WriteLine("Abstract Successors............");
                        }
                        #endregion
#endif
                        if (abstractsInHash.Add(succAbsHash)) /// --PL: if the abstract of current state has NOT been explored
                        {
                            succAbs.CollectAbstractSuccessors(abstractSuccsInHash, abstractSuccsFile);
                            if (fileDump)
                            {
                                abstractsFile.Write(succAbs.ToPrettyString());
                                abstractsFile.WriteLine(Constants.consoleSeparator);
                            }
                        }

#if false
                        if (currAbs.GetHashCode() == -417525807)
                        {
                            Environment.Exit(0);
                        }
#endif
                    }
#if DEBUG
                    // status and diagnostics
                    if (concretesInHash.Count % 1000 == 0)
                    {
                        Console.WriteLine("-------------- Number of concrete states visited so far   = {0}", concretesInHash.Count);
                        if (queueAbstraction)
                        {
                            Console.WriteLine("-------------- Number of abstract states found so far     = {0}", abstractsInHash.Count);
                            Console.WriteLine("-------------- Number of abstract successors found so far = {0}{1}", abstractSuccsInHash.Count, StateImpl.invariant ? " (only those satisfying all static invariants)" : "");
                        }
                        Console.WriteLine("-------------- Maximum queue size encountered so far      = {0}", max_queue_size);
                        Console.WriteLine("-------------- Maximum stack size encountered so far      = {0}", max_stack_size);
                        Console.WriteLine();
                    }

                    // update maximum encountered queue size
                    foreach (PrtImplMachine m in succ.State.ImplMachines)
                    {
                        max_queue_size = Math.Max(max_queue_size, m.eventQueue.Size());
                    }
#endif
                }
            } // end of while loop

            Console.WriteLine("");
            Console.WriteLine("Number of concrete states visited     = {0}", concretesInHash.Count);
            if (queueAbstraction)
            {
                Console.WriteLine("Number of abstract states encountered = {0}", abstractsInHash.Count);
                Console.WriteLine("Number of abstract successors found   = {0}{1}", abstractSuccsInHash.Count, StateImpl.invariant ? " (only those satisfying all static invariants)" : "");
            }

#if DEBUG
            Console.WriteLine("Maximum queue size  encountered       = {0}", max_queue_size);
            Console.WriteLine("Maximum stack size  encountered       = {0}", max_stack_size);
#endif
            Console.WriteLine();

            if (fileDump)
            {
                /// flush streams before close them
                concretesFile.Flush();
                abstractsFile.Flush();
                abstractSuccsFile.Flush();
                transitionsFile.Flush();
                /// close streams
                concretesFile.Close();
                abstractsFile.Close();
                abstractSuccsFile.Close();
                transitionsFile.Close();
            }
        }
コード例 #5
0
        public static void DebugHashAndClone(StateImpl s, CommandLineOptions options)
        {
            int maxNumOfSchedules = 10000;
            int maxDepth          = 5000;
            int numOfSchedules    = 0;
            int numOfSteps        = 0;
            var randomScheduler   = new Random(0); // DateTime.Now.Millisecond);

            while (numOfSchedules < maxNumOfSchedules)
            {
                var currImpl = (StateImpl)s.Clone();
                if (numOfSchedules % 1000 == 0)
                {
                    Console.WriteLine("-----------------------------------------------------");
                    Console.WriteLine("Total Schedules Explored: {0}", numOfSchedules);
                    Console.WriteLine("-----------------------------------------------------");
                }
                numOfSteps = 0;
                while (numOfSteps < maxDepth)
                {
                    StateImpl clone = null;

                    clone = (StateImpl)currImpl.Clone();
                    if (clone.GetHashCode() != currImpl.GetHashCode())
                    {
                        currImpl.DbgCompare(clone);
                        Debug.Assert(false);
                    }

                    Console.WriteLine("-----------------");
                    Console.WriteLine(currImpl.errorTrace.ToString());
                    Console.WriteLine("-----------------");
                    Console.WriteLine(clone.errorTrace.ToString());
                    Console.WriteLine("-----------------");

                    if (currImpl.EnabledMachines.Count == 0)
                    {
                        break;
                    }

                    var num        = currImpl.EnabledMachines.Count;
                    var choosenext = randomScheduler.Next(0, num);

                    int seed = 0;

                    seed = randomScheduler.Next();
                    var choices = new Random(seed);

                    currImpl.UserBooleanChoice = delegate()
                    {
                        return(choices.Next(2) == 0);
                    };

                    currImpl.EnabledMachines[choosenext].PrtRunStateMachine();

                    choices = new Random(seed);
                    clone.UserBooleanChoice = delegate()
                    {
                        return(choices.Next(2) == 0);
                    };

                    clone.EnabledMachines[choosenext].PrtRunStateMachine();
                    if (clone.GetHashCode() != currImpl.GetHashCode())
                    {
                        Console.WriteLine("numOfSchedules: {0}", numOfSchedules);
                        Console.WriteLine("numSteps: {0}", numOfSteps);
                        Console.WriteLine("-----------------");
                        Console.WriteLine(currImpl.errorTrace.ToString());
                        Console.WriteLine("-----------------");
                        Console.WriteLine(clone.errorTrace.ToString());
                        Console.WriteLine("-----------------");

                        currImpl.DbgCompare(clone);
                        System.Diagnostics.Debug.Assert(false);
                    }


                    if (currImpl.Exception != null)
                    {
                        if (currImpl.Exception is PrtAssumeFailureException)
                        {
                            break;
                        }
                        else if (currImpl.Exception is PrtException)
                        {
                            Console.WriteLine(currImpl.errorTrace.ToString());
                            Console.WriteLine("ERROR: {0}", currImpl.Exception.Message);
                            Environment.Exit(-1);
                        }
                        else
                        {
                            Console.WriteLine(currImpl.errorTrace.ToString());
                            Console.WriteLine("[Internal Exception]: Please report to the P Team");
                            Console.WriteLine(currImpl.Exception.ToString());
                            Environment.Exit(-1);
                        }
                    }

                    numOfSteps++;

                    //print the execution if verbose
                    if (options.verbose)
                    {
                        Console.WriteLine("-----------------------------------------------------");
                        Console.WriteLine("Execution {0}", numOfSchedules);
                        Console.WriteLine(currImpl.errorTrace.ToString());
                    }
                }
                numOfSchedules++;
            }
        }
コード例 #6
0
        public static void Explore(StateImpl s, CommandLineOptions options)
        {
            int maxNumOfSchedules = 10000;
            int maxDepth          = 5000;
            int numOfSchedules    = 0;
            int numOfSteps        = 0;
            var randomScheduler   = new Random(0); // DateTime.Now.Millisecond);

            max_queue_size = 0;

            while (numOfSchedules < maxNumOfSchedules)
            {
                var currImpl = (StateImpl)s.Clone();
                if (numOfSchedules % 1000 == 0)
                {
                    Console.WriteLine("-----------------------------------------------------");
                    Console.WriteLine("Total Schedules Explored: {0}", numOfSchedules);
                    Console.WriteLine("-----------------------------------------------------");
                }
                numOfSteps = 0;
                while (numOfSteps < maxDepth)
                {
                    var num = currImpl.EnabledMachines.Count;

                    if (num == 0)
                    {
                        break;
                    }

                    var choosenext = randomScheduler.Next(0, num);

                    currImpl.EnabledMachines[choosenext].PrtRunStateMachine();

#if DEBUG
                    // update maximum encountered queue size
                    foreach (PrtImplMachine m in currImpl.ImplMachines)
                    {
                        max_queue_size = Math.Max(max_queue_size, m.eventQueue.Size());
                    }
#endif

                    if (currImpl.Exception != null)
                    {
                        if (currImpl.Exception is PrtAssumeFailureException)
                        {
                            break;
                        }
                        else if (currImpl.Exception is PrtException)
                        {
                            Console.WriteLine(currImpl.errorTrace.ToString());
                            Console.WriteLine("ERROR: {0}", currImpl.Exception.Message);
                            Environment.Exit(-1);
                        }
                        else
                        {
                            Console.WriteLine(currImpl.errorTrace.ToString());
                            Console.WriteLine("[Internal Exception]: Please report to the P Team");
                            Console.WriteLine(currImpl.Exception.ToString());
                            Environment.Exit(-1);
                        }
                    }

                    numOfSteps++;

                    //print the execution if verbose
                    if (options.verbose)
                    {
                        Console.WriteLine("-----------------------------------------------------");
                        Console.WriteLine("Execution {0}", numOfSchedules);
                        Console.WriteLine(currImpl.errorTrace.ToString());
                    }
                }
                numOfSchedules++;
            }

            Console.WriteLine("");
            Console.WriteLine("Maximum queue size observed during this random test: {0}", max_queue_size);
        }
コード例 #7
0
ファイル: FrontierTree.cs プロジェクト: ZingModelChecker/Zing
 public TraversalInfo GetTraversalInfo(StateImpl InitialState, int threadId)
 {
     TraversalInfo retTraversalInfo = GetTraversalInfoForTrace(TheTrace, threadId, (StateImpl)InitialState.Clone(threadId));
     retTraversalInfo.zBounds = Bounds;
     if (ZingerConfiguration.DoDelayBounding)
     {
         retTraversalInfo.ZingDBSchedState = schedulerState;
     }
     else if (ZingerConfiguration.DoPreemptionBounding)
     {
         retTraversalInfo.preemptionBounding = preemptionBounding.Clone();
     }
     retTraversalInfo.IsFingerPrinted = true;
     return retTraversalInfo;
 }
コード例 #8
0
ファイル: FrontierTree.cs プロジェクト: ZingModelChecker/Zing
        /// <summary>
        /// Executes the model checker from the model initial state to the state represented by the given trace.
        /// Sets the initial state for algorithms not using reduction.
        /// </summary>
        /// <param name="trace">The trace that the model checker follows to set the initial TraversalInfo state. Can be null.</param>
        /// <returns>The transition depth of the resultant state.</returns>
        private TraversalInfo GetTraversalInfoForTrace(Trace trace, int threadId, StateImpl iState)
        {
            TraversalInfo ti = new ExecutionState((StateImpl)iState.Clone(threadId), null, null);
            int Step = 0;
            if (trace != null)
            {
                #region Trace Count greater than zero

                if (trace.Count > 0)
                {
                    while (Step < trace.Count)
                    {
                        if (ZingerConfiguration.CompactTraces && ti.HasMultipleSuccessors)
                        {
                            ti = ti.GetSuccessorNForReplay((int)trace[Step++].Selection, false);
                        }
                        else if (ZingerConfiguration.CompactTraces)
                        {
                            while (!ti.HasMultipleSuccessors && ZingerConfiguration.CompactTraces)
                            {
                                int n = 0;
                                if (ti.stateType.Equals(TraversalInfo.StateType.ExecutionState))
                                {
                                    int i = 0;
                                    while (i < ti.NumProcesses)
                                    {
                                        if (ti.ProcessInfo[i].Status.Equals(ProcessStatus.Runnable))
                                        {
                                            n = i;
                                            break;
                                        }
                                        i++;
                                    }
                                }
                                ti = ti.GetSuccessorNForReplay(n, false);
                            }
                        }
                        else
                        {
                            ti = ti.GetSuccessorNForReplay((int)trace[Step++].Selection, false);
                        }
                    }
                }

                #endregion Trace Count greater than zero

                #region Traversing the tail

                while (!ti.HasMultipleSuccessors && ZingerConfiguration.CompactTraces)
                {
                    int n = 0;
                    if (ti.stateType.Equals(TraversalInfo.StateType.ExecutionState))
                    {
                        int i = 0;
                        while (i < ti.NumProcesses)
                        {
                            if (ti.ProcessInfo[i].Status.Equals(ProcessStatus.Runnable))
                            {
                                n = i;
                                break;
                            }
                            i++;
                        }
                    }
                    ti = ti.GetSuccessorNForReplay(n, false);
                }

                #endregion Traversing the tail
            }
            return ti;
        }
コード例 #9
0
        public void RunCheckerRHS()
        {
            var       asm          = Assembly.LoadFrom(RHSModel);
            StateImpl rhsStateImpl = (StateImpl)asm.CreateInstance("P.Program.Application",
                                                                   false,
                                                                   BindingFlags.CreateInstance,
                                                                   null,
                                                                   new object[] { true },
                                                                   null,
                                                                   new object[] { });

            if (rhsStateImpl == null)
            {
                throw new ArgumentException("Invalid RHS assembly");
            }

            int numOfSchedules  = 0;
            int numOfSteps      = 0;
            var randomScheduler = new Random(DateTime.Now.Millisecond);

            while (numOfSchedules < maxRHSSchedules)
            {
                var currImpl = (StateImpl)rhsStateImpl.Clone();
                if (numOfSchedules % 10 == 0)
                {
                    Console.WriteLine("-----------------------------------------------------");
                    Console.WriteLine("Total Schedules Explored: {0}", numOfSchedules);
                    Console.WriteLine("-----------------------------------------------------");
                }
                numOfSteps = 0;
                while (true)
                {
                    if (numOfSteps >= maxLengthOfExecution)
                    {
                        Console.WriteLine("There is an execution in RHS of length more than {0}", maxLengthOfExecution);
                        return;
                    }

                    if (currImpl.EnabledMachines.Count == 0)
                    {
                        //execution terminated, add the trace to set of traces
                        AddTrace(currImpl.currentVisibleTrace);
                        break;
                    }

                    var num        = currImpl.EnabledMachines.Count;
                    var choosenext = randomScheduler.Next(0, num);
                    currImpl.EnabledMachines[choosenext].PrtRunStateMachine();
                    if (currImpl.Exception != null)
                    {
                        if (currImpl.Exception is PrtAssumeFailureException)
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Exception hit during execution: {0}", currImpl.Exception.ToString());
                            Environment.Exit(-1);
                        }
                    }
                    numOfSteps++;
                }
                numOfSchedules++;
            }

            Console.WriteLine("Loaded all traces of RHS");
            Console.WriteLine("Total Traces: {0}", allTracesRHS.Count);


            Stream          writeStream = File.Open("alltraces", FileMode.Create);
            BinaryFormatter bFormat     = new BinaryFormatter();

            bFormat.Serialize(writeStream, allTracesRHS);
            Console.WriteLine("Traces cached successfully");
        }