Exemplo n.º 1
0
        /// <summary>
        /// Generate the counter example for LTL model checking, including 2 parts: prefix, and period.
        /// [ REFS: '', DEREFS: automataBDD.transitionBDD, this.prefix, this.period ]
        /// </summary>
        /// <param name="automataBDD"></param>
        /// <param name="encoder"></param>
        /// <returns></returns>
        public void GetMCResult(AutomataBDD automataBDD, BDDEncoder encoder)
        {
            VerificationOutput.CounterExampleTrace.Add(InitialStep);

            if (VerificationOutput.VerificationResult == VerificationResultType.INVALID && VerificationOutput.GenerateCounterExample)
            {
                VerificationOutput.LoopIndex = this.prefix.Count + 1;

                List <CUDDNode>       traces       = new List <CUDDNode>();
                ExpressionBDDEncoding initEncoding = automataBDD.initExpression.TranslateBoolExpToBDD(encoder.model);
                traces.Add(CUDD.Function.Or(initEncoding.GuardDDs));
                traces.AddRange(this.prefix);
                traces.AddRange(this.period);

                Valuation currentValuation = this.InitialStep.GlobalEnv;
                Valuation lastValuation;
                for (int i = 1; i < traces.Count; i++)
                {
                    //Get event information

                    CUDD.Ref(traces[i], traces[i - 1]);
                    CUDDNode transitionTemp = CUDD.Function.And(traces[i - 1], encoder.model.SwapRowColVars(traces[i]));

                    CUDD.Ref(automataBDD.transitionBDD);
                    CUDDNode transWithEventInfo = CUDD.Function.And(transitionTemp, automataBDD.transitionBDD);

                    transWithEventInfo = CUDD.Abstract.ThereExists(transWithEventInfo, encoder.model.AllRowVarsExceptSingleCopy);
                    transWithEventInfo = CUDD.RestrictToFirst(transWithEventInfo, encoder.model.AllColVars);

                    lastValuation    = currentValuation;
                    currentValuation = encoder.GetValuationFromBDD(transWithEventInfo, this.InitialStep.GlobalEnv);

                    string eventName = encoder.GetEventChannelName(lastValuation, currentValuation, transWithEventInfo);

                    VerificationOutput.CounterExampleTrace.Add(new ConfigurationBDD(eventName, currentValuation));

                    //
                    CUDD.Deref(transWithEventInfo);
                }

                //
                CUDD.Deref(traces);
            }

            CUDD.Deref(automataBDD.transitionBDD);

            VerificationOutput.ActualMemoryUsage = CUDD.ReadMemoryInUse();
            VerificationOutput.numberOfBoolVars  = encoder.model.NumberOfBoolVars;

            encoder.model.Close();
        }
Exemplo n.º 2
0
 private void Interpret(Planning.HighLevelProgramExecution.Program program)
 {
     if (!Final(program))
     {
         do
         {
             //Console.WriteLine(program.GetType());
             string message = ReceiveMessage();
             Console.WriteLine("Receive message: {0}", message);
             if (message == "observation")
             {
                 string observationName = ReceiveMessage();
                 Console.WriteLine("Receive observation: {0}", observationName);
                 Observation observation = _observationDict[observationName];
                 _mentalAttitude.Update(observation);
                 int memory = CUDD.ReadMemoryInUse();
                 Console.WriteLine("Used memory: {0}MB", memory >> 20);
             }
             else
             {
                 //Console.WriteLine(program);
                 program = Trans(program);
                 int memory = CUDD.ReadMemoryInUse();
                 Console.WriteLine("Used memory: {0}MB", memory >> 20);
                 if (!Final(program))
                 {
                     SendMessage("remain");
                 }
                 else
                 {
                     SendMessage("quit");
                     break;
                 }
             }
         } while (true);
     }
 }