当前位置: 首页>>代码示例>>C#>>正文


C# Context.MkSimpleSolver方法代码示例

本文整理汇总了C#中Microsoft.Z3.Context.MkSimpleSolver方法的典型用法代码示例。如果您正苦于以下问题:C# Context.MkSimpleSolver方法的具体用法?C# Context.MkSimpleSolver怎么用?C# Context.MkSimpleSolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Z3.Context的用法示例。


在下文中一共展示了Context.MkSimpleSolver方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    public static void Main()
    {
        Context ctx = new Context();

        Params p = ctx.MkParams();
        p.Add("smt.arith.nl", true);
        p.Add("smt.arith.nl.rounds", 42);

        Solver s = ctx.MkSolver();
        s.Parameters = p;
        Console.WriteLine(s); // says "(solver)"

        s = ctx.MkSimpleSolver();
        s.Parameters = p;
        Console.WriteLine(s); // should also say "(solver)"
    }
开发者ID:ExiaHan,项目名称:z3test,代码行数:16,代码来源:solver_params1.cs

示例2: Solve

        internal ObjectTheoremResult Solve()
        {
            var settings = new Dictionary<string, string> {
                { "model", "true" },
                { "unsat_core", "true" }
            };

            using (var context = new Context(settings))
            {
                var stopwatch = Stopwatch.StartNew();

                Environment environment = GenerateEnvironment(context);

                BoolExpr[] assertions = GenerateConstraints(context, environment, _assertions);

                BoolExpr[] allAssertions = GenerateAllConstraints(context, environment, _allAssertions);

                Solver solver = context.MkSimpleSolver();

                int assertionCount = 0;
                foreach (var assertion in assertions.Concat(allAssertions))
                {
                    assertionCount++;
                    solver.Assert(assertion);
                }

                int assumptionCount = 0;
                var assumptions = new Dictionary<LambdaExpression, BoolExpr>();
                foreach (var assumption in _assumptions)
                {
                    var generator = new LambdaExpressionToConstraintGenerator(context, environment);

                    var assumptionExpr = generator.Visit(assumption);

                    var assumptionCheck = context.MkBoolConst(Guid.NewGuid().ToString());
                    solver.Assert(context.MkEq(assumptionExpr, assumptionCheck));

                    assumptionCount++;
                    assumptions.Add(assumption, assumptionCheck);
                }

                stopwatch.Stop();
                var constraintGenerationTimeSpan = stopwatch.Elapsed;

                var solverString = solver.ToString();
                var totalConstraintsCount = solverString.Split('\n').Count(l => l.StartsWith("  ("));

                Trace.WriteLine("Statistics:");
                Trace.WriteLine("assertionCount: " + assertionCount);
                Trace.WriteLine("assumptionCount: " + assumptionCount);
                Trace.WriteLine("totalConstraintsCount: " + totalConstraintsCount);
                Trace.WriteLine("constraintGenerationTimeSpan: " + constraintGenerationTimeSpan);

                var classCount = environment.Types.Count(t => !t.Key.IsValueType && t.Key.Name != "String");
                var propertyCount = environment.Types
                    .Where(t => !t.Key.IsValueType && t.Key.Name != "String")
                    .Select(p => p.Key.GetProperties())
                    .Count();

                stopwatch.Restart();
                Microsoft.Z3.Status status = solver.Check(assumptions.Values.ToArray());
                stopwatch.Stop();

                var solvingTimeSpan = stopwatch.Elapsed;
                Trace.WriteLine("solvingTimeSpan: " + solvingTimeSpan);

                if (status != Microsoft.Z3.Status.SATISFIABLE)
                {
                    if (solver.UnsatCore.Length > 0)
                    {
                        var result = new ObjectTheoremResult(context, environment, solver, status);
                        result.SetUnsatCore(assumptions, solver.UnsatCore);
                        return result;
                    }

                    return null;
                }

                var modelString = solver.Model.ToString();

                return new ObjectTheoremResult(context, environment, solver, status);
            }
        }
开发者ID:RicardoNiepel,项目名称:Z3.ObjectTheorem,代码行数:83,代码来源:ObjectTheoremSolver.cs


注:本文中的Microsoft.Z3.Context.MkSimpleSolver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。