internal override CellTreeNode VisitTerm(TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
            {
                var oneOf = (MemberRestriction)expression.Identifier.Variable.Identifier;
                var range = expression.Identifier.Range;

                // create a disjunction
                var          disjunctionNode = new OpCellTreeNode(_viewgenContext, CellTreeOpType.Union);
                CellTreeNode singleNode      = null;

                foreach (var value in range)
                {
                    if (TryGetCellTreeNode(oneOf.RestrictedMemberSlot.MemberPath, value, out singleNode))
                    {
                        disjunctionNode.Add(singleNode);
                    }
                    // else, there is no rewriting for this member value, i.e., it is empty
                }
                switch (disjunctionNode.Children.Count)
                {
                case 0:
                    return(null);    // empty rewriting

                case 1:
                    return(singleNode);

                default:
                    return(disjunctionNode);
                }
            }
Exemple #2
0
            internal override CellTreeNode VisitTerm(
                TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
            {
                MemberRestriction identifier     = (MemberRestriction)expression.Identifier.Variable.Identifier;
                Set <Constant>    range          = expression.Identifier.Range;
                OpCellTreeNode    opCellTreeNode = new OpCellTreeNode(this._viewgenContext, CellTreeOpType.Union);
                CellTreeNode      singleNode     = (CellTreeNode)null;

                foreach (Constant constant in range)
                {
                    if (this.TryGetCellTreeNode(identifier.RestrictedMemberSlot.MemberPath, constant, out singleNode))
                    {
                        opCellTreeNode.Add(singleNode);
                    }
                }
                switch (opCellTreeNode.Children.Count)
                {
                case 0:
                    return((CellTreeNode)null);

                case 1:
                    return(singleNode);

                default:
                    return((CellTreeNode)opCellTreeNode);
                }
            }
 private Vertex[] ConvertMappingConditionsToVertices(
     ConversionContext <DomainConstraint <string, ValueCondition> > converter,
     DomainVariable <string, ValueCondition>[] variables)
 {
     Vertex[] vertexArray = new Vertex[this.NormalizedEntityTypeMappings.Count];
     for (int index1 = 0; index1 < vertexArray.Length; ++index1)
     {
         FunctionImportNormalizedEntityTypeMapping entityTypeMapping = this.NormalizedEntityTypeMappings[index1];
         Vertex left = Vertex.One;
         for (int index2 = 0; index2 < this.DiscriminatorColumns.Count; ++index2)
         {
             FunctionImportEntityTypeMappingCondition columnCondition = entityTypeMapping.ColumnConditions[index2];
             if (columnCondition != null)
             {
                 ValueCondition conditionValue = columnCondition.ConditionValue;
                 if (conditionValue.IsNotNullCondition)
                 {
                     TermExpr <DomainConstraint <string, ValueCondition> > term = new TermExpr <DomainConstraint <string, ValueCondition> >(new DomainConstraint <string, ValueCondition>(variables[index2], ValueCondition.IsNull));
                     Vertex vertex = converter.TranslateTermToVertex(term);
                     left = converter.Solver.And(left, converter.Solver.Not(vertex));
                 }
                 else
                 {
                     TermExpr <DomainConstraint <string, ValueCondition> > term = new TermExpr <DomainConstraint <string, ValueCondition> >(new DomainConstraint <string, ValueCondition>(variables[index2], conditionValue));
                     left = converter.Solver.And(left, converter.TranslateTermToVertex(term));
                 }
             }
         }
         vertexArray[index1] = left;
     }
     return(vertexArray);
 }
            internal override Literal <DomainConstraint <T_Variable, T_Element> > NegateLiteral(
                Literal <DomainConstraint <T_Variable, T_Element> > literal)
            {
                // negate the literal by inverting the range, rather than changing the sign
                // of the literal
                var term = new TermExpr <DomainConstraint <T_Variable, T_Element> >(
                    literal.Term.Identifier.InvertDomainConstraint());

                return(new Literal <DomainConstraint <T_Variable, T_Element> >(term, literal.IsTermPositive));
            }
        private static void AddMessagingConstraints(List <InternodeMessage> messages, Solver.IModel solverModel, Dictionary <A.Message, MessageDecision> msgDecisions, Dictionary <NodeId, NodeDecision> nodeDecisions)
        {
            Func <A.Message, Expr> getTerm = m =>
            {
                Expr ret = new TermExpr()
                {
                    Variable = nodeDecisions[m.Node.NodeId].Decision
                };
                for (; m != null; m = m.Prev)
                {
                    MessageDecision d;
                    if (msgDecisions.TryGetValue(m, out d))
                    {
                        ret = new OperatorExpr()
                        {
                            Op    = OperatorExpr.OpType.Sub,
                            Left  = ret,
                            Right = new TermExpr()
                            {
                                Variable = d.Decision
                            }
                        }
                    }
                    ;
                }
                return(ret);
            };

            foreach (var message in messages)
            {
                var toNodeDecision   = getTerm(message.IncomingMessage);
                var fromNodeDecision = getTerm(message.OutgoingMessage);

                solverModel.AddConstraints(
                    SolverUtils.MakeValidSolverIdentifierFromString("MessageConstraint_" + message.Id),
                    new OperatorExpr()
                {
                    Op   = OperatorExpr.OpType.Get,
                    Left = new OperatorExpr()
                    {
                        Op    = OperatorExpr.OpType.Sub,
                        Left  = toNodeDecision,
                        Right = fromNodeDecision,
                    },
                    Right = new ConstantExpr()
                    {
                        Value = (message.FromTimestamp - message.ToTimestamp).Ticks + 1
                    }
                }
                    );
                nodeDecisions[message.IncomingMessage.Node.NodeId].UsedInConstraint();
                nodeDecisions[message.OutgoingMessage.Node.NodeId].UsedInConstraint();
            }
        }
            internal override StringBuilder VisitTerm(
                TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
            {
                BoolLiteral boolLiteral = BoolExpression.GetBoolLiteral(expression);

                if (boolLiteral is ScalarRestriction || boolLiteral is TypeRestriction)
                {
                    return(boolLiteral.AsUserString(this.m_builder, Strings.ViewGen_EntityInstanceToken, this.m_skipIsNotNull));
                }
                return(boolLiteral.AsUserString(this.m_builder, this.m_blockAlias, this.m_skipIsNotNull));
            }
        internal BoolExpr <DomainConstraint <BoolLiteral, Constant> > Chase(
            TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
        {
            BoolExpr <DomainConstraint <BoolLiteral, Constant> > boolExpr;

            this.Implications.TryGetValue(expression, out boolExpr);
            return((BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new AndExpr <DomainConstraint <BoolLiteral, Constant> >(new BoolExpr <DomainConstraint <BoolLiteral, Constant> >[2]
            {
                (BoolExpr <DomainConstraint <BoolLiteral, Constant> >)expression,
                boolExpr ?? (BoolExpr <DomainConstraint <BoolLiteral, Constant> >)TrueExpr <DomainConstraint <BoolLiteral, Constant> > .Value
            }));
        }
            internal override StringBuilder VisitNot(
                NotExpr <DomainConstraint <BoolLiteral, Constant> > expression)
            {
                this.m_skipIsNotNull = false;
                TermExpr <DomainConstraint <BoolLiteral, Constant> > child = expression.Child as TermExpr <DomainConstraint <BoolLiteral, Constant> >;

                if (child != null)
                {
                    return(BoolExpression.GetBoolLiteral(child).AsNegatedUserString(this.m_builder, this.m_blockAlias, this.m_skipIsNotNull));
                }
                this.m_builder.Append("NOT(");
                expression.Child.Accept <StringBuilder>((Visitor <DomainConstraint <BoolLiteral, Constant>, StringBuilder>) this);
                this.m_builder.Append(")");
                return(this.m_builder);
            }
Exemple #9
0
                internal override DomainBoolExpr VisitTerm(TermExpr <DomainConstraint> expression)
                {
                    var invertedConstraint = expression.Identifier.InvertDomainConstraint();

                    if (invertedConstraint.Range.Count == 0)
                    {
                        return(FalseExpr <DomainConstraint> .Value);
                    }

                    var split    = new List <DomainBoolExpr>();
                    var variable = invertedConstraint.Variable;

                    foreach (var element in invertedConstraint.Range)
                    {
                        split.Add(new DomainConstraint(variable, new Set <Constant>(new[] { element }, Constant.EqualityComparer)));
                    }

                    return(new OrExpr <DomainConstraint>(split));
                }
        private void CacheNormalizedImplication(
            TermExpr <DomainConstraint <BoolLiteral, Constant> > condition,
            BoolExpr <DomainConstraint <BoolLiteral, Constant> > implies)
        {
            foreach (TermExpr <DomainConstraint <BoolLiteral, Constant> > key in this.Implications.Keys)
            {
                if (key.Identifier.Variable.Equals((object)condition.Identifier.Variable) && !key.Identifier.Range.SetEquals(condition.Identifier.Range))
                {
                    this.CacheResidualFact((BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new OrExpr <DomainConstraint <BoolLiteral, Constant> >(new BoolExpr <DomainConstraint <BoolLiteral, Constant> >[2]
                    {
                        (BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new NotExpr <DomainConstraint <BoolLiteral, Constant> >((BoolExpr <DomainConstraint <BoolLiteral, Constant> >)condition),
                        implies
                    }));
                    return;
                }
            }
            BoolExpr <DomainConstraint <BoolLiteral, Constant> > expr1 = new Converter <DomainConstraint <BoolLiteral, Constant> >(this.Chase(implies), IdentifierService <DomainConstraint <BoolLiteral, Constant> > .Instance.CreateConversionContext()).Dnf.Expr;
            FragmentQueryKBChaseSupport queryKbChaseSupport            = new FragmentQueryKBChaseSupport();

            queryKbChaseSupport.Implications[condition] = expr1;
            bool flag = true;

            foreach (TermExpr <DomainConstraint <BoolLiteral, Constant> > index in new Set <TermExpr <DomainConstraint <BoolLiteral, Constant> > >((IEnumerable <TermExpr <DomainConstraint <BoolLiteral, Constant> > >) this.Implications.Keys))
            {
                BoolExpr <DomainConstraint <BoolLiteral, Constant> > expr2 = queryKbChaseSupport.Chase(this.Implications[index]);
                if (index.Equals(condition))
                {
                    flag  = false;
                    expr2 = (BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new AndExpr <DomainConstraint <BoolLiteral, Constant> >(new BoolExpr <DomainConstraint <BoolLiteral, Constant> >[2]
                    {
                        expr2,
                        expr1
                    });
                }
                this.Implications[index] = new Converter <DomainConstraint <BoolLiteral, Constant> >(expr2, IdentifierService <DomainConstraint <BoolLiteral, Constant> > .Instance.CreateConversionContext()).Dnf.Expr;
            }
            if (flag)
            {
                this.Implications[condition] = expr1;
            }
            this._residueSize = -1;
        }
                internal override BoolExpr <DomainConstraint <BoolLiteral, Constant> > VisitTerm(
                    TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
                {
                    DomainConstraint <BoolLiteral, Constant> domainConstraint = expression.Identifier.InvertDomainConstraint();

                    if (domainConstraint.Range.Count == 0)
                    {
                        return((BoolExpr <DomainConstraint <BoolLiteral, Constant> >)FalseExpr <DomainConstraint <BoolLiteral, Constant> > .Value);
                    }
                    List <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > boolExprList = new List <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >();
                    DomainVariable <BoolLiteral, Constant> variable = domainConstraint.Variable;

                    foreach (Constant constant in domainConstraint.Range)
                    {
                        boolExprList.Add((BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new DomainConstraint <BoolLiteral, Constant>(variable, new Set <Constant>((IEnumerable <Constant>) new Constant[1]
                        {
                            constant
                        }, Constant.EqualityComparer)));
                    }
                    return((BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new OrExpr <DomainConstraint <BoolLiteral, Constant> >((IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >)boolExprList));
                }
Exemple #12
0
                internal override DomainBoolExpr VisitTerm(TermExpr <DomainConstraint> expression)
                {
                    switch (expression.Identifier.Range.Count)
                    {
                    case 0:
                        return(FalseExpr <DomainConstraint> .Value);

                    case 1:
                        return(expression);
                    }

                    var split    = new List <DomainBoolExpr>();
                    var variable = expression.Identifier.Variable;

                    foreach (var element in expression.Identifier.Range)
                    {
                        split.Add(new DomainConstraint(variable, new Set <Constant>(new[] { element }, Constant.EqualityComparer)));
                    }

                    return(new OrExpr <DomainConstraint>(split));
                }
        private Vertex[] ConvertMappingConditionsToVertices(
            ConversionContext <DomainConstraint <string, ValueCondition> > converter,
            DomainVariable <string, ValueCondition>[] variables)
        {
            var conditions = new Vertex[NormalizedEntityTypeMappings.Count];

            for (var i = 0; i < conditions.Length; i++)
            {
                var typeMapping = NormalizedEntityTypeMappings[i];

                // create conjunction representing the condition
                var condition = Vertex.One;
                for (var j = 0; j < DiscriminatorColumns.Count; j++)
                {
                    var columnCondition = typeMapping.ColumnConditions[j];
                    if (null != columnCondition)
                    {
                        var conditionValue = columnCondition.ConditionValue;
                        if (conditionValue.IsNotNullCondition)
                        {
                            // the 'not null' condition is not actually part of the domain (since it
                            // covers other elements), so create a Not(value in {null}) condition
                            var isNull = new TermExpr <DomainConstraint <string, ValueCondition> >(
                                new DomainConstraint <string, ValueCondition>(variables[j], ValueCondition.IsNull));
                            var isNullVertex = converter.TranslateTermToVertex(isNull);
                            condition = converter.Solver.And(condition, converter.Solver.Not(isNullVertex));
                        }
                        else
                        {
                            var hasValue = new TermExpr <DomainConstraint <string, ValueCondition> >(
                                new DomainConstraint <string, ValueCondition>(variables[j], conditionValue));
                            condition = converter.Solver.And(condition, converter.TranslateTermToVertex(hasValue));
                        }
                    }
                }
                conditions[i] = condition;
            }
            return(conditions);
        }
                internal override BoolExpr <DomainConstraint <BoolLiteral, Constant> > VisitTerm(
                    TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
                {
                    switch (expression.Identifier.Range.Count)
                    {
                    case 0:
                        return((BoolExpr <DomainConstraint <BoolLiteral, Constant> >)FalseExpr <DomainConstraint <BoolLiteral, Constant> > .Value);

                    case 1:
                        return((BoolExpr <DomainConstraint <BoolLiteral, Constant> >)expression);

                    default:
                        List <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > boolExprList = new List <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >();
                        DomainVariable <BoolLiteral, Constant> variable = expression.Identifier.Variable;
                        foreach (Constant constant in expression.Identifier.Range)
                        {
                            boolExprList.Add((BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new DomainConstraint <BoolLiteral, Constant>(variable, new Set <Constant>((IEnumerable <Constant>) new Constant[1]
                            {
                                constant
                            }, Constant.EqualityComparer)));
                        }
                        return((BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new OrExpr <DomainConstraint <BoolLiteral, Constant> >((IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >)boolExprList));
                    }
                }
 internal override BoolExpr <DomainConstraint <BoolLiteral, Constant> > VisitTerm(
     TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
 {
     return(this._kb.Chase(expression));
 }
 internal override int VisitTerm(
     TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
 {
     return(expression.Identifier.Variable.Domain.Count - expression.Identifier.Range.Count);
 }
Exemple #17
0
 internal Literal(TermExpr <T_Identifier> term, bool isTermPositive)
     : base(isTermPositive ? (BoolExpr <T_Identifier>)term : (BoolExpr <T_Identifier>) new NotExpr <T_Identifier>((BoolExpr <T_Identifier>)term))
 {
     this._term           = term;
     this._isTermPositive = isTermPositive;
 }
 internal override BoolExpr <DomainConstraint <BoolLiteral, Constant> > VisitTerm(
     TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
 {
     return(BoolExpression.GetBoolLiteral(expression).RemapBool(this.m_remap).GetDomainBoolExpression(this.m_memberDomainMap));
 }
Exemple #19
0
 internal override int VisitTerm(TermExpr <DomainConstraint> expression)
 {
     //this might be imprecise (precise would be count the elements in the set difference),
     //but this class is only needed for estimating the count
     return(expression.Identifier.Variable.Domain.Count - expression.Identifier.Range.Count);
 }
Exemple #20
0
 internal abstract T_Return VisitTerm(TermExpr <T_Identifier> expression);
 internal static BoolLiteral GetBoolLiteral(
     TermExpr <DomainConstraint <BoolLiteral, Constant> > term)
 {
     return(term.Identifier.Variable.Identifier);
 }
 internal override T_Return VisitTerm(
     TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
 {
     return(this.BooleanLiteralAsCql(BoolExpression.GetBoolLiteral(expression), this.m_skipIsNotNull));
 }
 internal override BoolExpr <DomainConstraint <BoolLiteral, Constant> > VisitTerm(
     TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
 {
     BoolExpression.GetBoolLiteral(expression).GetRequiredSlots(this.m_projectedSlotMap, this.m_requiredSlots);
     return((BoolExpr <DomainConstraint <BoolLiteral, Constant> >)expression);
 }
Exemple #24
0
 // static KMETHOD ParseExpr_Term(CTX, ksfp_t *sfp _RIX)
 public static KonohaExpr ParseExpr_Term(Context ctx, Syntax syn, KStatement stmt, IList<Token> tls, int s, int c, int e)
 {
     Debug.Assert(s == c);
     Token tk = tls[c];
     KonohaExpr expr = new TermExpr();
         //new_W(Expr, SYN_(kStmt_ks(stmt), tk->kw));
     //Expr_setTerm(expr, 1);
     expr.tk = tk;
     return Expr_rightJoin(ctx, expr, stmt, tls, s + 1, c + 1, e);
 }
 internal override int VisitTerm(TermExpr <T_Identifier> expression)
 {
     return(1);
 }
 internal override BoolExpr <DomainConstraint <BoolLiteral, Constant> > VisitTerm(
     TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
 {
     return(BoolExpression.GetBoolLiteral(expression).FixRange(expression.Identifier.Range, this.m_memberDomainMap));
 }
 internal override StringBuilder VisitTerm(
     TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
 {
     BoolExpression.GetBoolLiteral(expression).ToCompactString(this.m_builder);
     return(this.m_builder);
 }
Exemple #28
0
 internal override int VisitTerm(TermExpr <DomainConstraint> expression)
 {
     return(expression.Identifier.Range.Count);
 }
        private Vertex[] ConvertMappingConditionsToVertices(
            ConversionContext<DomainConstraint<string, ValueCondition>> converter,
            DomainVariable<string, ValueCondition>[] variables)
        {
            var conditions = new Vertex[NormalizedEntityTypeMappings.Count];
            for (var i = 0; i < conditions.Length; i++)
            {
                var typeMapping = NormalizedEntityTypeMappings[i];

                // create conjunction representing the condition
                var condition = Vertex.One;
                for (var j = 0; j < DiscriminatorColumns.Count; j++)
                {
                    var columnCondition = typeMapping.ColumnConditions[j];
                    if (null != columnCondition)
                    {
                        var conditionValue = columnCondition.ConditionValue;
                        if (conditionValue.IsNotNullCondition)
                        {
                            // the 'not null' condition is not actually part of the domain (since it
                            // covers other elements), so create a Not(value in {null}) condition
                            var isNull = new TermExpr<DomainConstraint<string, ValueCondition>>(
                                new DomainConstraint<string, ValueCondition>(variables[j], ValueCondition.IsNull));
                            var isNullVertex = converter.TranslateTermToVertex(isNull);
                            condition = converter.Solver.And(condition, converter.Solver.Not(isNullVertex));
                        }
                        else
                        {
                            var hasValue = new TermExpr<DomainConstraint<string, ValueCondition>>(
                                new DomainConstraint<string, ValueCondition>(variables[j], conditionValue));
                            condition = converter.Solver.And(condition, converter.TranslateTermToVertex(hasValue));
                        }
                    }
                }
                conditions[i] = condition;
            }
            return conditions;
        }
 internal override IEnumerable <TermExpr <DomainConstraint <BoolLiteral, Constant> > > VisitTerm(
     TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
 {
     yield return(expression);
 }