Exemplo n.º 1
0
        public VariableGlobal(string name, string rate, VarType type, VarUpdateType update_type, string initial)
            : base(name, rate, type, update_type, initial)
        {
            Expr globalVariable      = null;
            Expr globalVariablePrime = null;

            //switch ((ParameterTypes)Enum.Parse(typeof(ParameterTypes), type, true))
            // todo: next blockcan likely be converted (for the most part) into a function call instead of switch (e.g., lots of repition)
            switch (type)
            {
            case Variable.VarType.boolean:
                globalVariable      = Controller.Instance.Z3.MkBoolConst(name);
                this.Type           = Variable.VarType.boolean;
                globalVariablePrime = Controller.Instance.Z3.MkBoolConst(name + Controller.PRIME_SUFFIX);
                break;

            case Variable.VarType.index:
                globalVariable      = Controller.Instance.Z3.MkIntConst(name);                           // todo: vs Controller.Instance.IndexType
                this.Type           = Variable.VarType.index;
                globalVariablePrime = Controller.Instance.Z3.MkIntConst(name + Controller.PRIME_SUFFIX); // todo: vs Controller.Instance.IndexType
                break;

            case Variable.VarType.integer:
                globalVariable      = Controller.Instance.Z3.MkIntConst(name);
                this.Type           = Variable.VarType.integer;
                globalVariablePrime = Controller.Instance.Z3.MkIntConst(name + Controller.PRIME_SUFFIX);
                break;

            case Variable.VarType.real:
                globalVariable      = Controller.Instance.Z3.MkRealConst(name);
                this.Type           = Variable.VarType.real;
                globalVariablePrime = Controller.Instance.Z3.MkRealConst(name + Controller.PRIME_SUFFIX);
                break;

            case Variable.VarType.nnreal:
                globalVariable      = Controller.Instance.Z3.MkRealConst(name);
                this.Type           = Variable.VarType.nnreal;
                globalVariablePrime = Controller.Instance.Z3.MkRealConst(name + Controller.PRIME_SUFFIX);
                break;
            }

            if (globalVariable != null && globalVariablePrime != null)
            {
                if (!Controller.Instance.GlobalVariables.ContainsKey(name))
                {
                    Controller.Instance.Sys.Variables.Add(this);
                    Controller.Instance.GlobalVariables.Add(name, globalVariable);
                    Controller.Instance.GlobalVariablesPrimed.Add(name, globalVariablePrime);
                }
            }
            else
            {
                throw new System.Exception("Parameter term not created.");
            }



            this.finishConstruction();
        }
Exemplo n.º 2
0
        public VariableParameter(string name, VarType type, VarUpdateType update_type, string assumption)
            : base(name, "", type, update_type, assumption)
        {
            Expr param = null;

            // TODO: refactor all these switches in the constructors into common variable parent class
            switch (type)
            {
            case VarType.index:
                param = Controller.Instance.Z3.MkIntConst(name);     // todo: vs Controller.Instance.IndexType
                break;

            case VarType.integer:
                param = Controller.Instance.Z3.MkIntConst(name);
                break;

            case VarType.real:
                param = Controller.Instance.Z3.MkRealConst(name);
                break;
            }

            if (param != null)
            {
                if (!Controller.Instance.Params.ContainsKey(name))
                {
                    Controller.Instance.Params.Add(name, param);
                }
            }
            else
            {
                throw new System.Exception("Parameter term not created.");
            }


            if (assumption != null && assumption.Length > 0)
            {
                Antlr.Runtime.Tree.CommonTree tmptree = passel.controller.parsing.math.Expression.Parse(assumption);
                //Expression.FixTypes(ref tmptree);
                Expr passump = LogicalExpression.CreateTerm(tmptree);
                if (!Controller.Instance.ParamsAssumps.ContainsKey(name))
                {
                    Controller.Instance.ParamsAssumps.Add(name, passump);
                    Controller.Instance.Z3.Assumptions.Add((BoolExpr)passump);
                }
            }
        }
Exemplo n.º 3
0
        /**
         *
         */
        public Variable(String name, String rate, VarType type, VarUpdateType update_type, String initial)
        {
            switch (type)
            {
            case VarType.boolean:
                this.TypeSort = Controller.Instance.Z3.BoolSort;
                break;

            case VarType.index:
                this.TypeSort = Controller.Instance.Z3.IntSort;
                break;

            case VarType.real:
            case VarType.nnreal:
            case VarType.posreal:
                this.TypeSort = Controller.Instance.Z3.RealSort;
                break;

            case VarType.integer:
            case VarType.nat:
            case VarType.nnnat:
            case VarType.posnat:
                this.TypeSort = Controller.Instance.Z3.IntSort;
                break;

            case VarType.location:
                this.TypeSort = Controller.Instance.LocType;
                break;

            default:
                throw new Exception("Bad sort");
            }
            this._name         = name;
            this.NamePrimed    = name + controller.Controller.PRIME_SUFFIX;
            this._rate         = rate;
            this._type         = type;
            this.InitialString = initial;
            this.UpdateType    = update_type;
        }