ConstInterp() public méthode

Retrieves the interpretation (the assignment) of a in the model.
public ConstInterp ( Expr a ) : Expr
a Expr A Constant
Résultat Expr
Exemple #1
0
        public IDictionary <string, List <object> > Solve()
        {
            Dictionary <string, List <object> > variableValues = new Dictionary <string, List <object> >(StringComparer.CurrentCultureIgnoreCase);

            new Model.ViewModelLocator().MainModel.AddDisplayText("Z3 Solve");
            Solver s = this.z3Context.MkSolver();

            foreach (BoolExpr sa in this.solverAssertions)
            {
                s.Assert(sa);
            }

            Console.WriteLine(s.Check());
            new Model.ViewModelLocator().MainModel.AddDisplayText(s.Check().ToString());

            Microsoft.Z3.Model m = s.Model;
            foreach (FuncDecl d in m.Decls)
            {
                string varName  = d.Name.ToString();
                Expr   valExpr  = m.ConstInterp(d);
                string varValue = valExpr.ToString();
                if (valExpr is FPExpr)
                {
                    FPExpr fp  = (FPExpr)valExpr;
                    FPNum  fn  = (FPNum)fp;
                    double val = Convert.ToDouble(fn.Significand);
                    val = val * System.Math.Pow(2, fn.ExponentInt64);

                    if (fn.Sign)
                    {
                        val = val * -1;
                    }

                    varValue = val.ToString();

                    if (valExpr.ToString() == "+zero")
                    {
                        varValue = "0.01";
                    }
                    if (valExpr.ToString() == "-zero")
                    {
                        varValue = "-0.01";
                    }
                }


                string message = varName + " -> " + varValue;
                new Model.ViewModelLocator().MainModel.AddDisplayText(message);

                if (!variableValues.ContainsKey(varName))
                {
                    variableValues.Add(varName, new List <object>());
                }

                variableValues[varName].Add(varValue);
            }
            return(variableValues);
        }
Exemple #2
0
        public void Solve1()
        {
            using (Context ctx = new Context()){
                Expr a = ctx.MkIntConst("a");

                IntExpr twelve = ctx.MkInt(12);

                Solver s = ctx.MkSolver();

                s.Assert(ctx.MkEq(a, twelve));
                Console.WriteLine(s.Check());

                Microsoft.Z3.Model m = s.Model;
                foreach (FuncDecl d in m.Decls)
                {
                    Console.WriteLine(d.Name + " -> " + m.ConstInterp(d));
                }

                Console.ReadLine();
            }
        }
 protected int GetConcChoice(Context context, Model model)
 {
     int concChoice = ((IntNum)model.ConstInterp(context.MkIntConst(this.constraintVariable))).Int;
     return concChoice;
 }
 private static BoolExpr CreateAssignmentFormula(Context z3Context, Model lastModel, string choiceVariable)
 {
     ArithExpr z3Variable = z3Context.MkIntConst(choiceVariable);
     ArithExpr assignment = (ArithExpr)lastModel.ConstInterp(z3Variable);
     BoolExpr currentAssignment = z3Context.MkEq(z3Variable, assignment);
     return currentAssignment;
 }
 public char InterpretModel(IList<char> alphabet, Context context, Model model)
 {
     int concChoice = ((IntNum)model.ConstInterp(context.MkIntConst(this.constraintVariable))).Int;
     return alphabet[concChoice];
 }
 public int InterpretModel(IList<char> alphabet, Context context, Model model)
 {
     int concChoice = ((IntNum)model.ConstInterp(context.MkIntConst(this.constraintVariable))).Int;
     Debug.Assert(concChoice != 0 || this.includeZero == true);
     return concChoice;
 }
 public string InterpretModel(IList<char> alphabet, Context context, Model model)
 {
     int concChoice = ((IntNum)model.ConstInterp(context.MkIntConst(this.constraintVariable))).Int;
     int alphabetSize = alphabet.Count;
     string returnValue = "";
     for (int currentIndex = 0; currentIndex < this.originalValue.Length; ++currentIndex)
     {
         int currentChoice = concChoice % alphabetSize;
         returnValue += alphabet[currentChoice];
         concChoice -= currentChoice;
         concChoice = concChoice / alphabetSize;
     }
     return returnValue;
 }