Beispiel #1
0
        private CardExpr MkAnyUnion(DependencyNode node, AppFreeCanUnn arg)
        {
            CardExpr expr = MkConstantCount(arg);

            if (expr.IsInfinity)
            {
                return(expr);
            }

            foreach (var m in arg.NonRangeMembers)
            {
                if (m.Kind != SymbolKind.UserSortSymb)
                {
                    continue;
                }

                var data = varMap[((UserSortSymb)m).DataSymbol];
                if (data.Item1 == node)
                {
                    return(new CardCnst(Cardinality.Infinity));
                }
                else
                {
                    expr += data.Item2;
                }
            }

            return(expr);
        }
Beispiel #2
0
        private Cardinality Eval(CardExpr expr, CardVar cvar, Cardinality val, bool evalOnLower)
        {
            switch (expr.Kind)
            {
            case CardExpr.ExprKind.Cnst:
                return(((CardCnst)expr).Value);

            case CardExpr.ExprKind.Var:
                if (expr == cvar)
                {
                    return(val);
                }
                else if (evalOnLower)
                {
                    return(GetRange((CardVar)expr).Lower);
                }
                else
                {
                    return(GetRange((CardVar)expr).Upper);
                }

            case CardExpr.ExprKind.Prod:
                return(Eval(expr[0], cvar, val, evalOnLower) * Eval(expr[1], cvar, val, evalOnLower));

            case CardExpr.ExprKind.Unn:
                return(Eval(expr[0], cvar, val, evalOnLower) + Eval(expr[1], cvar, val, evalOnLower));

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #3
0
 public CardConstraint(OpKind op, CardVar lhs, CardExpr rhs)
 {
     Contract.Requires(lhs != null && rhs != null);
     Op  = op;
     Lhs = lhs;
     Rhs = rhs;
     GetRHSVars(rhs);
 }
Beispiel #4
0
 private void GetRHSVars(CardExpr subexpr)
 {
     if (subexpr.Kind == CardExpr.ExprKind.Var)
     {
         rhsVars.Add((CardVar)subexpr);
     }
     else
     {
         for (int i = 0; i < subexpr.Arity; ++i)
         {
             GetRHSVars(subexpr[i]);
         }
     }
 }
Beispiel #5
0
        private CardRange Eval(CardExpr expr)
        {
            switch (expr.Kind)
            {
            case CardExpr.ExprKind.Cnst:
                return(((CardCnst)expr).ValueAsRange);

            case CardExpr.ExprKind.Var:
                return(GetRange((CardVar)expr));

            case CardExpr.ExprKind.Prod:
                return(Eval(expr[0]) * Eval(expr[1]));

            case CardExpr.ExprKind.Unn:
                return(Eval(expr[0]) + Eval(expr[1]));

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #6
0
        private CardExpr MkRelationalUnion(DependencyNode node, AppFreeCanUnn arg)
        {
            CardExpr expr = MkConstantCount(arg);

            if (expr.IsInfinity)
            {
                return(expr);
            }

            foreach (var m in arg.NonRangeMembers)
            {
                if (m.Kind != SymbolKind.UserSortSymb)
                {
                    continue;
                }

                var data = varMap[((UserSortSymb)m).DataSymbol];
                Contract.Assert(data.Item1 != node);
                expr += data.Item3;
            }

            return(expr);
        }
Beispiel #7
0
 public CardCartProd(CardExpr expr1, CardExpr expr2)
 {
     Contract.Requires(expr1 != null && expr2 != null);
     Expr1 = expr1;
     Expr2 = expr2;
 }
Beispiel #8
0
 public CardDisjUnion(CardExpr expr1, CardExpr expr2)
 {
     Contract.Requires(expr1 != null && expr2 != null);
     Expr1 = expr1;
     Expr2 = expr2;
 }