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); }
public override void Close() { CUDD.Deref(nondetMask); allNondetVars.Deref(); base.Close(); }
public virtual void Close() { allRowVars.Deref(); allColVars.Deref(); CUDD.Deref(allRowVarRanges, trans, start, trans01, reach); CUDD.Deref(varIdentities, varEncodings, stateRewards, transRewards); CUDD.CloseDownCUDD(); }
private void UpdateKnowledge(EventModel eventModel) { //Console.WriteLine("Enter update knowledge"); //CUDD.Ref(eventModel.KnowPrecondition); //Console.WriteLine("After ref know precondition"); //CUDDNode knowledgeWithPre = CUDD.Function.And(Knowledge, eventModel.KnowPrecondition); CUDD.Ref(eventModel.KnowPartialSsa); //Console.WriteLine("After ref know partial ssa"); CUDDNode knowledgeWithPssa = CUDD.Function.And(Knowledge, eventModel.KnowPartialSsa); //Console.WriteLine("After get knowledge with pre and partial ssa"); if (eventModel.KnowAffectedPredSet.Count != 0) { CUDDVars oldVars = new CUDDVars(); CUDDVars newVars = new CUDDVars(); foreach (var predicate in eventModel.KnowAffectedPredSet) { CUDDNode trueRestrictBy = CUDD.Var(predicate.PreviousCuddIndex); CUDD.Ref(trueRestrictBy); CUDD.Ref(knowledgeWithPssa); CUDDNode trueNode = CUDD.Function.Restrict(knowledgeWithPssa, trueRestrictBy); CUDDNode falseRestrictBy = CUDD.Function.Not(trueRestrictBy); CUDDNode falseNode = CUDD.Function.Restrict(knowledgeWithPssa, falseRestrictBy); knowledgeWithPssa = CUDD.Function.Or(trueNode, falseNode); oldVars.AddVar(CUDD.Var(predicate.SuccessiveCuddIndex)); newVars.AddVar(CUDD.Var(predicate.PreviousCuddIndex)); } Knowledge = CUDD.Variable.SwapVariables(knowledgeWithPssa, oldVars, newVars); oldVars.Deref(); newVars.Deref(); } else { Knowledge = knowledgeWithPssa; } //Console.WriteLine("Whether knowledge is equal to false: {0}", Knowledge.Equals(CUDD.ZERO)); //Console.WriteLine("Finish!"); }
private void UpdateBelief(CUDDNode partialSsa, HashSet <Predicate> affectedPredSet) { //CUDD.Ref(precondition); //CUDDNode beliefWithPre = CUDD.Function.And(Belief, precondition); CUDD.Ref(partialSsa); CUDDNode beliefWithPssa = CUDD.Function.And(Belief, partialSsa); if (affectedPredSet.Count != 0) { CUDDVars oldVars = new CUDDVars(); CUDDVars newVars = new CUDDVars(); foreach (var predicate in affectedPredSet) { CUDDNode trueRestrictBy = CUDD.Var(predicate.PreviousCuddIndex); CUDD.Ref(trueRestrictBy); CUDD.Ref(beliefWithPssa); CUDDNode trueNode = CUDD.Function.Restrict(beliefWithPssa, trueRestrictBy); CUDDNode falseRestrictBy = CUDD.Function.Not(trueRestrictBy); CUDDNode falseNode = CUDD.Function.Restrict(beliefWithPssa, falseRestrictBy); beliefWithPssa = CUDD.Function.Or(trueNode, falseNode); oldVars.AddVar(CUDD.Var(predicate.SuccessiveCuddIndex)); newVars.AddVar(CUDD.Var(predicate.PreviousCuddIndex)); } Belief = CUDD.Variable.SwapVariables(beliefWithPssa, oldVars, newVars); oldVars.Deref(); newVars.Deref(); } else { Belief = beliefWithPssa; } //Console.WriteLine("Whether belief is equal to false: {0}", Belief.Equals(CUDD.ZERO)); //Console.WriteLine("Finish!"); }