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


C# Context.MkEnumSort方法代码示例

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


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

示例1: Run

    public void Run()
    {
        Dictionary<string, string> cfg = new Dictionary<string, string>() {
            { "AUTO_CONFIG", "true" },
            { "MODEL", "true" } };

        using (Context ctx = new Context(cfg))
        {
            EnumSort color = ctx.MkEnumSort("Color", new string[] { "red", "green", "blue" });

            Expr red = color.Consts[0];
            Expr green = color.Consts[1];
            Expr blue = color.Consts[2];

            Console.WriteLine(ctx.MkEq(green, blue));
            Console.WriteLine(ctx.MkEq(green, blue).Simplify());

            Expr c = ctx.MkConst("c", color);

            Solver s = ctx.MkSolver();
            s.Assert(ctx.MkNot(ctx.MkEq(c, green)));
            s.Assert(ctx.MkNot(ctx.MkEq(c, blue)));
            Console.WriteLine(s.Check());
            Console.WriteLine(s.Model);
        }
    }
开发者ID:ahorn,项目名称:z3test,代码行数:26,代码来源:datatype.4.cs

示例2: GetOrAddMemberAccessFunction

        internal static FuncDecl GetOrAddMemberAccessFunction(Context context, Environment environment, MemberInfo memberInfo)
        {
            FuncDecl memberFunc;
            if (!environment.Members.TryGetValue(memberInfo, out memberFunc))
            {
                Sort memberTypeSort;
                if (!environment.Types.TryGetValue(memberInfo.DeclaringType, out memberTypeSort))
                {
                    throw new KeyNotFoundException(memberInfo.DeclaringType + " could not be found at environment.Types");
                }

                Sort memberReturnTypeEnumSort;
                var propertyType = ((PropertyInfo)memberInfo).PropertyType;
                if (propertyType == typeof(bool))
                    memberReturnTypeEnumSort = context.MkBoolSort();
                else if (propertyType == typeof(int))
                    memberReturnTypeEnumSort = context.MkIntSort();
                else if (propertyType == typeof(long))
                    memberReturnTypeEnumSort = context.MkRealSort();
                else if (propertyType == typeof(string))
                    memberReturnTypeEnumSort = environment.PossibleStringValues;
                else
                {
                    if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
                    {
                        var listItemType = propertyType.GenericTypeArguments[0];

                        var listSort = context.MkSetSort(environment.Types[listItemType]);

                        memberReturnTypeEnumSort = listSort;

                        // TODO: add TryGetValue
                        environment.Types.Add(propertyType, listSort);
                    }
                    else if (propertyType.IsEnum)
                    {
                        EnumSort enumSort = context.MkEnumSort(propertyType.Name, Enum.GetNames(propertyType));

                        memberReturnTypeEnumSort = enumSort;

                        // TODO: add TryGetValue
                        environment.Types.Add(propertyType, enumSort);
                    }
                    else
                    {
                        // TODO throw exception if type is not supported
                        memberReturnTypeEnumSort = environment.Types[propertyType];
                    }
                }

                memberFunc = context.MkFuncDecl(memberInfo.Name, memberTypeSort, memberReturnTypeEnumSort);
                environment.Members.Add(memberInfo, memberFunc);
            }
            return memberFunc;
        }
开发者ID:RicardoNiepel,项目名称:Z3.ObjectTheorem,代码行数:55,代码来源:LambdaExpressionToConstraintGenerator.cs

示例3: EnumExample

        /// <summary>
        /// Create an enumeration data type.
        /// </summary>
        public static void EnumExample(Context ctx)
        {
            Console.WriteLine("EnumExample");

            Symbol name = ctx.MkSymbol("fruit");

            EnumSort fruit = ctx.MkEnumSort(ctx.MkSymbol("fruit"), new Symbol[] { ctx.MkSymbol("apple"), ctx.MkSymbol("banana"), ctx.MkSymbol("orange") });

            Console.WriteLine("{0}", (fruit.Consts[0]));
            Console.WriteLine("{0}", (fruit.Consts[1]));
            Console.WriteLine("{0}", (fruit.Consts[2]));

            Console.WriteLine("{0}", (fruit.TesterDecls[0]));
            Console.WriteLine("{0}", (fruit.TesterDecls[1]));
            Console.WriteLine("{0}", (fruit.TesterDecls[2]));

            Expr apple = fruit.Consts[0];
            Expr banana = fruit.Consts[1];
            Expr orange = fruit.Consts[2];

            /* Apples are different from oranges */
            Prove(ctx, ctx.MkNot(ctx.MkEq(apple, orange)));

            /* Apples pass the apple test */
            Prove(ctx, (BoolExpr)ctx.MkApp(fruit.TesterDecls[0], apple));

            /* Oranges fail the apple test */
            Disprove(ctx, (BoolExpr)ctx.MkApp(fruit.TesterDecls[0], orange));
            Prove(ctx, (BoolExpr)ctx.MkNot((BoolExpr)ctx.MkApp(fruit.TesterDecls[0], orange)));

            Expr fruity = ctx.MkConst("fruity", fruit);

            /* If something is fruity, then it is an apple, banana, or orange */

            Prove(ctx, ctx.MkOr(new BoolExpr[] { ctx.MkEq(fruity, apple), ctx.MkEq(fruity, banana), ctx.MkEq(fruity, orange) }));
        }
开发者ID:perillaseed,项目名称:z3,代码行数:39,代码来源:Program.cs

示例4: GenerateEnvironment

        private Environment GenerateEnvironment(Context context)
        {
            var environment = new Environment();

            // Class instances
            // TODO: support NULL values
            foreach (var instancesPerClassType in _instances.GroupBy(_ => _.Value.GetType()))
            {
                string classType = instancesPerClassType.Key.Name;

                EnumSort instancesEnumSort = context.MkEnumSort(classType + "_instances", instancesPerClassType.Select(_ => _.Key).ToArray());
                environment.Types.Add(instancesPerClassType.Key, instancesEnumSort);

                Expr[] instancesEnumSortValues = instancesEnumSort.Consts;
                int instancesIndex = 0;
                foreach (KeyValuePair<string, object> instance in instancesPerClassType)
                {
                    environment.Instances.Add(instance.Key,
                        new InstanceInfo(instancesEnumSortValues[instancesIndex++], objectInstance: instance.Value));
                }
            }

            // Super Types
            foreach (var superType in _superTypes)
            {
                var subTypeSorts = environment.Types.Where(t => t.Key.IsSubclassOf(superType)).Select(t => t.Value).ToList();
                if (subTypeSorts.Count == 0)
                    continue;

                var superTypeConstructors = new List<Constructor>();
                foreach (var subTypeSort in subTypeSorts)
                {
                    var subTypeConstr = context.MkConstructor(
                        name: subTypeSort.Name.ToString(),
                        recognizer: "Is" + subTypeSort.Name,
                        fieldNames: new[] { subTypeSort.Name + "2" + superType.Name },
                        sorts: new[] { subTypeSort },
                        sortRefs: null);
                    superTypeConstructors.Add(subTypeConstr);
                }

                DatatypeSort superTypeSort = context.MkDatatypeSort(superType.Name, superTypeConstructors.ToArray());

                //DatatypeSort = context.MkDatatypeSort("Types", new Constructor[] {
                //    context.MkConstructor("ValTypes", "isValType", new String[] {"Val2Type"}, new Sort[] {ValTypeSort}, null),
                //    context.MkConstructor("RefTypes", "isRefType", new String[] {"Ref2Type"}, new Sort[] {RefTypeSort}, null)
                //});

                environment.Types.Add(superType, superTypeSort);
            }

            // Strings
            if (_possibleStringValues.Any())
            {
                EnumSort enumSort = context.MkEnumSort("Strings", _possibleStringValues.ToArray());
                environment.PossibleStringValues = enumSort;
            }



            foreach (var member in _members)
            {
                LambdaExpressionToConstraintGenerator.GetOrAddMemberAccessFunction(context, environment, member);
            }

            return environment;
        }
开发者ID:RicardoNiepel,项目名称:Z3.ObjectTheorem,代码行数:67,代码来源:ObjectTheoremSolver.cs


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