Esempio n. 1
0
        /// <summary>
        /// Can support array of array
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private ExpressionBDDEncoding TranslateArrayExpression(Model model)
        {
            if (this.Argument2 is IntConstant)
            {
                int indexValue = ((IntConstant)this.Argument2).Value;
                if (Operator == ARRAY)
                {
                    return(new Variable(this.Argument1 + Model.NAME_SEPERATOR + indexValue).TranslateIntExpToBDD(model));
                }
                else
                {
                    return(new VariablePrime(this.Argument1 + Model.NAME_SEPERATOR + indexValue).TranslateIntExpToBDD(model));
                }
            }

            ExpressionBDDEncoding indexBddEncoding = this.Argument2.TranslateIntExpToBDD(model);

            //Get the array range
            int min = model.GetArrayRange(this.Argument1.ExpressionID)[0];
            int max = model.GetArrayRange(this.Argument1.ExpressionID)[1];

            ExpressionBDDEncoding result = new ExpressionBDDEncoding();

            //a[i]
            for (int i = min; i <= max; i++)
            {
                for (int j = 0; j < indexBddEncoding.Count(); j++)
                {
                    //index = i & guard of index
                    CUDD.Ref(indexBddEncoding.ExpressionDDs[j], indexBddEncoding.GuardDDs[j]);
                    CUDDNode guard = CUDD.Function.And(CUDD.Function.Equal(indexBddEncoding.ExpressionDDs[j], CUDD.Constant(i)),
                                                       indexBddEncoding.GuardDDs[j]);

                    if (guard != CUDD.ZERO)
                    {
                        //a[i]
                        result.GuardDDs.Add(guard);
                        Expression arrayExpression;
                        if (Operator == ARRAY)
                        {
                            arrayExpression = new Variable(this.Argument1.ExpressionID + Model.NAME_SEPERATOR + i);
                        }
                        else
                        {
                            arrayExpression = new VariablePrime(this.Argument1.ExpressionID + Model.NAME_SEPERATOR + i);
                        }
                        result.ExpressionDDs.Add(arrayExpression.TranslateIntExpToBDD(model).ExpressionDDs[0]);
                    }
                    else
                    {
                        CUDD.Deref(guard);
                    }
                }
            }

            //dereference later because 2 loops above
            indexBddEncoding.DeRef();

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Return only guards for complete boolean expression, no expression
        /// Use this when we want to encode a single assignment or the assignment does not depend other assignments.
        /// </summary>
        public override ExpressionBDDEncoding TranslateBoolExpToBDD(Model model)
        {
            ExpressionBDDEncoding result = new ExpressionBDDEncoding();
            ExpressionBDDEncoding variableBddEncoding = new VariablePrime(this.LeftHandSide).TranslateIntExpToBDD(model);

            ExpressionBDDEncoding valueBddEncoding = this.RightHandSide.TranslateIntExpToBDD(model);

            for (int i = 0; i < variableBddEncoding.Count(); i++)
            {
                for (int j = 0; j < valueBddEncoding.Count(); j++)
                {
                    CUDD.Ref(variableBddEncoding.GuardDDs[i], valueBddEncoding.GuardDDs[j]);
                    CUDDNode guardDD = CUDD.Function.And(variableBddEncoding.GuardDDs[i], valueBddEncoding.GuardDDs[j]);
                    if (guardDD.Equals(CUDD.ZERO))
                    {
                        CUDD.Deref(guardDD);
                        continue;
                    }

                    CUDD.Ref(variableBddEncoding.ExpressionDDs[i], valueBddEncoding.ExpressionDDs[j]);
                    CUDDNode assignmentDD = CUDD.Function.Equal(variableBddEncoding.ExpressionDDs[i], valueBddEncoding.ExpressionDDs[j]);

                    guardDD = CUDD.Function.And(guardDD, assignmentDD);
                    result.AddNodeToGuard(guardDD);
                }
            }
            //remove unused expression
            variableBddEncoding.DeRef();
            valueBddEncoding.DeRef();

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Return only guards for complete boolean expression, no expression
        /// Use this when we want to encode a single assignment or the assignment does not depend other assignments.
        /// </summary>
        public override ExpressionBDDEncoding TranslateBoolExpToBDD(Model model)
        {
            ExpressionBDDEncoding result = new ExpressionBDDEncoding();
            ExpressionBDDEncoding variableBddEncoding = new VariablePrime(this.LeftHandSide).TranslateIntExpToBDD(model);

            ExpressionBDDEncoding valueBddEncoding = this.RightHandSide.TranslateIntExpToBDD(model);

            for (int i = 0; i < variableBddEncoding.Count(); i++)
            {
                for (int j = 0; j < valueBddEncoding.Count(); j++)
                {
                    CUDD.Ref(variableBddEncoding.GuardDDs[i], valueBddEncoding.GuardDDs[j]);
                    CUDDNode guardDD = CUDD.Function.And(variableBddEncoding.GuardDDs[i], valueBddEncoding.GuardDDs[j]);
                    if (guardDD.Equals(CUDD.ZERO))
                    {
                        CUDD.Deref(guardDD);
                        continue;
                    }

                    CUDD.Ref(variableBddEncoding.ExpressionDDs[i], valueBddEncoding.ExpressionDDs[j]);
                    CUDDNode assignmentDD = CUDD.Function.Equal(variableBddEncoding.ExpressionDDs[i], valueBddEncoding.ExpressionDDs[j]);

                    guardDD = CUDD.Function.And(guardDD, assignmentDD);
                    result.AddNodeToGuard(guardDD);
                }
            }
            //remove unused expression
            variableBddEncoding.DeRef();
            valueBddEncoding.DeRef();

            return result;
        }
Esempio n. 4
0
        /// <summary>
        /// Can support array of array
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private ExpressionBDDEncoding TranslateArrayExpression(Model model)
        {
            if (this.Argument2 is IntConstant)
            {
                int indexValue = ((IntConstant)this.Argument2).Value;
                if(Operator == ARRAY)
                {
                    return new Variable(this.Argument1 + Model.NAME_SEPERATOR + indexValue).TranslateIntExpToBDD(model);
                }
                else
                {
                    return new VariablePrime(this.Argument1 + Model.NAME_SEPERATOR + indexValue).TranslateIntExpToBDD(model);
                }
            }

            ExpressionBDDEncoding indexBddEncoding = this.Argument2.TranslateIntExpToBDD(model);

            //Get the array range
            int min = model.GetArrayRange(this.Argument1.ExpressionID)[0];
            int max = model.GetArrayRange(this.Argument1.ExpressionID)[1];

            ExpressionBDDEncoding result = new ExpressionBDDEncoding();
            //a[i]
            for (int i = min; i <= max; i++)
            {
                for(int j = 0; j < indexBddEncoding.Count(); j++)
                {
                    //index = i & guard of index
                    CUDD.Ref(indexBddEncoding.ExpressionDDs[j], indexBddEncoding.GuardDDs[j]);
                    CUDDNode guard = CUDD.Function.And(CUDD.Function.Equal(indexBddEncoding.ExpressionDDs[j], CUDD.Constant(i)),
                                          indexBddEncoding.GuardDDs[j]);

                    if(guard != CUDD.ZERO)
                    {
                        //a[i]
                        result.GuardDDs.Add(guard);
                        Expression arrayExpression;
                        if(Operator == ARRAY)
                        {
                            arrayExpression = new Variable(this.Argument1.ExpressionID + Model.NAME_SEPERATOR + i);
                        }
                        else
                        {
                            arrayExpression = new VariablePrime(this.Argument1.ExpressionID + Model.NAME_SEPERATOR + i);
                        }
                        result.ExpressionDDs.Add(arrayExpression.TranslateIntExpToBDD(model).ExpressionDDs[0]);
                    }
                    else
                    {
                        CUDD.Deref(guard);
                    }
                }
            }

            //dereference later because 2 loops above
            indexBddEncoding.DeRef();

            return result;
        }