Пример #1
0
        private static void GenerateConstraints(CWExpr choiceExpr, int maxNumVariables, VariableCache.ConstraintMode constraintMode, Context z3Context, Solver z3Solver)
        {
            VariableCache variableGenerator = VariableCache.Create(constraintMode);

            choiceExpr.ToSMTConstraints(z3Context, z3Solver, maxNumVariables, variableGenerator);
            variableGenerator.GenerateAdditionalConstraints(z3Context, z3Solver);
        }
Пример #2
0
        public override void ToSMTConstraints(Context z3Context, Solver z3Solver, int maxNumVars, VariableCache variableGenerator)
        {
            /* constraint variable in { 0, 1 }
             * 0 -> and
             * 1 -> or
             */
            this.constraintVariable = variableGenerator.GetFreshVariableName();
            ArithExpr myVariable = z3Context.MkIntConst(this.constraintVariable);

            z3Solver.Assert(z3Context.MkLe(z3Context.MkInt(0), myVariable));
            z3Solver.Assert(z3Context.MkLe(myVariable, z3Context.MkInt(Enum.GetNames(typeof(WCCompound.Logic)).Length - 1)));
            this.cond1.ToSMTConstraints(z3Context, z3Solver, maxNumVars, variableGenerator);
            this.cond2.ToSMTConstraints(z3Context, z3Solver, maxNumVars, variableGenerator);
        }
Пример #3
0
        public override void ToSMTConstraints(Context z3Context, Solver z3Solver, int maxNumVars, VariableCache variableGenerator)
        {
            this.constraintVariable = variableGenerator.GetVarChoiceVariable(orgId);
            ArithExpr myVariable = z3Context.MkIntConst(this.constraintVariable);

            z3Solver.Assert(z3Context.MkLe(z3Context.MkInt(0), myVariable));
            z3Solver.Assert(z3Context.MkLe(myVariable, z3Context.MkInt(maxNumVars - 1)));
        }
Пример #4
0
        public override void ToSMTConstraints(Context z3Context, Solver z3Solver, int maxNumVars, VariableCache variableGenerator)
        {
            /* constraint variable in { 0, 1 }
             * 0 -> eq
             * 1 -> neq
             */
            this.constraintVariable = variableGenerator.GetFreshVariableName();
            ArithExpr myVariable = z3Context.MkIntConst(this.constraintVariable);

            z3Solver.Assert(z3Context.MkLe(z3Context.MkInt(0), myVariable));
            z3Solver.Assert(z3Context.MkLe(myVariable, z3Context.MkInt(1)));
            this.x.ToSMTConstraints(z3Context, z3Solver, maxNumVars, variableGenerator);
        }
Пример #5
0
        public override void ToSMTConstraints(Context z3Context, Solver z3Solver, int maxNumVars, VariableCache variableGenerator)
        {
            /* constraint variable in { 0, ..., 5 }
             * -> eq, l, leq, neq, g, geq
             */

            this.constraintVariable = variableGenerator.GetFreshVariableName();
            ArithExpr myVariable = z3Context.MkIntConst(this.constraintVariable);

            z3Solver.Assert(z3Context.MkLe(z3Context.MkInt(0), myVariable));
            z3Solver.Assert(z3Context.MkLe(myVariable, z3Context.MkInt(Enum.GetNames(typeof(WCComparison.CompareType)).Length - 1)));
            this.arg1.ToSMTConstraints(z3Context, z3Solver, maxNumVars, variableGenerator);
            //Currently, arg2 may be concretized to a 0 constant, possibly resulting in an '== 0' or '!= 0' condition, which is a simple condition.
            this.arg2.ToSMTConstraints(z3Context, z3Solver, maxNumVars, variableGenerator);
        }
Пример #6
0
        public override void ToSMTConstraints(Context z3Context, Solver z3Solver, int maxNumVars, VariableCache variableGenerator)
        {
            this.constraintVariable = variableGenerator.GetFreshVariableName();
            ArithExpr myVariable = z3Context.MkIntConst(this.constraintVariable);

            z3Solver.Assert(z3Context.MkLe(z3Context.MkInt(0), myVariable));
            z3Solver.Assert(z3Context.MkLe(myVariable, z3Context.MkInt(2)));
            this.lhs.ToSMTConstraints(z3Context, z3Solver, maxNumVars, variableGenerator);
            this.arg1.ToSMTConstraints(z3Context, z3Solver, maxNumVars, variableGenerator);
            this.arg2.ToSMTConstraints(z3Context, z3Solver, maxNumVars, variableGenerator);
        }
Пример #7
0
        public override void ToSMTConstraints(Context z3Context, Solver z3Solver, int maxNumVars, VariableCache variableGenerator)
        {
            /* constraint variable in { 0, 1 }
             * 0 -> plus
             * 1 -> minus
             */
            this.constraintVariable = variableGenerator.GetFreshVariableName();
            ArithExpr myVariable = z3Context.MkIntConst(this.constraintVariable);

            z3Solver.Assert(z3Context.MkLe(z3Context.MkInt(0), myVariable));
            z3Solver.Assert(z3Context.MkLe(myVariable, z3Context.MkInt(Enum.GetNames(typeof(WEArith.ArithOp)).Length - 1)));
            this.lhs.ToSMTConstraints(z3Context, z3Solver, maxNumVars, variableGenerator);
            this.arg1.ToSMTConstraints(z3Context, z3Solver, maxNumVars, variableGenerator);
            this.arg2.ToSMTConstraints(z3Context, z3Solver, maxNumVars, variableGenerator);
        }
Пример #8
0
 /* Traverses the choice tree, creating constraints in the <z3Context>.
  * Stores identifiers in <constraintVariable>.
  * <maxNumVars> is the number of distinct WEVars in the original program. Only used in CWEVar.ToSMTConstraints.
  */
 public abstract void ToSMTConstraints(Context z3Context, Solver z3Solver, int maxNumVars, VariableCache variableGenerator);
Пример #9
0
        public override void ToSMTConstraints(Context z3Context, Solver z3Solver, int maxNumVars, VariableCache variableGenerator)
        {
            this.constraintVariable = variableGenerator.GetFreshVariableName();
            ArithExpr myVariable = z3Context.MkIntConst(this.constraintVariable);

            z3Solver.Assert(z3Context.MkEq(z3Context.MkInt(0), myVariable));
            this.condition.ToSMTConstraints(z3Context, z3Solver, maxNumVars, variableGenerator);
            this.thenBody.ToSMTConstraints(z3Context, z3Solver, maxNumVars, variableGenerator);
            if (elseBody != null)
            {
                this.elseBody.ToSMTConstraints(z3Context, z3Solver, maxNumVars, variableGenerator);
            }
        }
Пример #10
0
        public override void ToSMTConstraints(Context z3Context, Solver z3Solver, int maxNumVars, VariableCache variableGenerator)
        {
            this.constraintVariable = variableGenerator.GetConstChoiceVariable(orgValue);
            ArithExpr myVariable = z3Context.MkIntConst(this.constraintVariable);
            //range for variation of constants
            //TODO: allow 0?
            int lowerBound = Math.Max((int)(this.orgValue / 2), 0);
            int upperBound = Math.Max((int)(this.orgValue * 2), 0);

            z3Solver.Assert(z3Context.MkLe(z3Context.MkInt(lowerBound), myVariable));
            z3Solver.Assert(z3Context.MkLe(myVariable, z3Context.MkInt(upperBound)));
        }