Exemple #1
0
        public IModel Encode()
        {
            //get variable info from ModulesFile
            varList = new VariableList(modules);

            //Collect all sync label of all modules
            synchs = modules.GetAllSynchs().ToList();

            AddVars();

            //Create Expression Encoder, use the same copy of varList, variableEncoding
            expressionEncoder = new ExpressionToBDD(varList, variableEncoding);

            EncodeSystemDef(modules.systemDef);

            // get rid of any nondet dd variables not needed
            if (modules.modelType == ModelType.MDP)
            {
                CUDDNode tmp = CUDD.GetSupport(trans);
                tmp = CUDD.Abstract.ThereExists(tmp, allRowVars);
                tmp = CUDD.Abstract.ThereExists(tmp, allColVars);

                CUDDVars ddv = new CUDDVars();
                while (!tmp.Equals(CUDD.ONE))
                {
                    ddv.AddVar(CUDD.Var(tmp.GetIndex()));
                    tmp = tmp.GetThen();
                }
                CUDD.Deref(tmp);
                allNondetVars.Deref();
                allNondetVars = ddv;
            }

            init = GetInitState();

            //
            CUDD.Deref(moduleRangeDDs, moduleIdentities, colVarRanges, syncVars, choiceVars);
            CUDD.Deref(moduleRowVars, moduleColVars, rowVars, colVars, new List <CUDDVars>()
            {
                globalRowVars, globalColVars, allSynchVars, allChoiceVars
            });

            IModel result;

            if (modules.modelType == ModelType.DTMC)
            {
                //
                allNondetVars.Deref();

                result = new ProbModel(trans, init, stateRewards, transRewards, allRowVars, allColVars, varList, allRowVarRanges,
                                       varIdentities, variableEncoding);
            }
            else
            {
                result = new NonDetModel(trans, init, stateRewards, transRewards, allRowVars, allColVars, allNondetVars,
                                         varList, allRowVarRanges, varIdentities, variableEncoding);
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// return colomn variables used in the dd
        /// [ REFS: '', DEREFS: '' ]
        /// </summary>
        public List <int> GetColSupportedVars(CUDDNode dd)
        {
            List <int> result = new List <int>();
            //Get changed variables
            CUDDNode supportedVariable = CUDD.GetSupport(dd);

            for (int k = 0; k < this.colVars.Count; k++)
            {
                CUDD.Ref(supportedVariable);
                CUDDNode temp = CUDD.Abstract.ThereExists(supportedVariable, this.colVars[k]);

                if (!supportedVariable.Equals(temp))
                {
                    result.Add(k);
                }
                CUDD.Deref(temp);
            }
            CUDD.Deref(supportedVariable);

            return(result);
        }