internal void UpdateWhereClause(MemberDomainMap domainMap)
        {
            List <BoolExpression> boolExpressionList = new List <BoolExpression>();

            foreach (BoolExpression atom in this.WhereClause.Atoms)
            {
                MemberRestriction      asLiteral         = atom.AsLiteral as MemberRestriction;
                IEnumerable <Constant> domain            = domainMap.GetDomain(asLiteral.RestrictedMemberSlot.MemberPath);
                MemberRestriction      memberRestriction = asLiteral.CreateCompleteMemberRestriction(domain);
                ScalarRestriction      scalarRestriction = asLiteral as ScalarRestriction;
                bool flag = scalarRestriction != null && !scalarRestriction.Domain.Contains(Constant.Null) && !scalarRestriction.Domain.Contains(Constant.NotNull) && !scalarRestriction.Domain.Contains(Constant.Undefined);
                if (flag)
                {
                    domainMap.AddSentinel(memberRestriction.RestrictedMemberSlot.MemberPath);
                }
                boolExpressionList.Add(BoolExpression.CreateLiteral((BoolLiteral)memberRestriction, domainMap));
                if (flag)
                {
                    domainMap.RemoveSentinel(memberRestriction.RestrictedMemberSlot.MemberPath);
                }
            }
            if (boolExpressionList.Count <= 0)
            {
                return;
            }
            this.m_whereClause = BoolExpression.CreateAnd(boolExpressionList.ToArray());
        }
 // <summary>
 // Fixes the range of the restriction in accordance with <paramref name="range" />.
 // Member restriction must be complete for this operation.
 // </summary>
 internal override DomainBoolExpr FixRange(Set<Constant> range, MemberDomainMap memberDomainMap)
 {
     Debug.Assert(IsComplete, "Ranges are fixed only for complete scalar restrictions.");
     var newPossibleValues = memberDomainMap.GetDomain(RestrictedMemberSlot.MemberPath);
     BoolLiteral newLiteral = new ScalarRestriction(RestrictedMemberSlot, new Domain(range, newPossibleValues));
     return newLiteral.GetDomainBoolExpression(memberDomainMap);
 }
        // <summary>
        // Fixes the range of the restriction in accordance with <paramref name="range" />.
        // Member restriction must be complete for this operation.
        // </summary>
        internal override DomainBoolExpr FixRange(Set <Constant> range, MemberDomainMap memberDomainMap)
        {
            Debug.Assert(IsComplete, "Ranges are fixed only for complete scalar restrictions.");
            var         newPossibleValues = memberDomainMap.GetDomain(RestrictedMemberSlot.MemberPath);
            BoolLiteral newLiteral        = new ScalarRestriction(RestrictedMemberSlot, new Domain(range, newPossibleValues));

            return(newLiteral.GetDomainBoolExpression(memberDomainMap));
        }
        internal override BoolExpr <DomainConstraint <BoolLiteral, Constant> > FixRange(
            Set <Constant> range,
            MemberDomainMap memberDomainMap)
        {
            IEnumerable <Constant> domain = memberDomainMap.GetDomain(this.RestrictedMemberSlot.MemberPath);

            return(new ScalarRestriction(this.RestrictedMemberSlot, new Domain((IEnumerable <Constant>)range, domain)).GetDomainBoolExpression(memberDomainMap));
        }
Esempio n. 5
0
        // <summary>
        // Returns a boolean expression that is domain-aware and ready for optimizations etc.
        // </summary>
        // <param name="domainMap"> Maps members to the values that each member can take; it can be null in which case the possible and actual values are the same. </param>
        internal override DomainBoolExpr GetDomainBoolExpression(MemberDomainMap domainMap)
        {
            // Get the variable name from the slot's memberpath and the possible domain values from the slot
            DomainTermExpr result;

            if (domainMap != null)
            {
                // Look up the domain from the domainMap
                var domain = domainMap.GetDomain(m_restrictedMemberSlot.MemberPath);
                result = MakeTermExpression(this, domain, m_domain.Values);
            }
            else
            {
                result = MakeTermExpression(this, m_domain.AllPossibleValues, m_domain.Values);
            }
            return(result);
        }
Esempio n. 6
0
        // requires: The CellConstantDomains in the OneOfConsts of the where
        // clause are partially done
        // effects: Given the domains of different variables in domainMap,
        // fixes the whereClause of this such that all the
        // CellConstantDomains in OneOfConsts are complete
        internal void UpdateWhereClause(MemberDomainMap domainMap)
        {
            var atoms = new List <BoolExpression>();

            foreach (var atom in WhereClause.Atoms)
            {
                var literal     = atom.AsLiteral;
                var restriction = literal as MemberRestriction;
                Debug.Assert(restriction != null, "All bool literals must be OneOfConst at this point");
                // The oneOfConst needs to be fixed with the new possible values from the domainMap.
                var possibleValues = domainMap.GetDomain(restriction.RestrictedMemberSlot.MemberPath);
                var newOneOf       = restriction.CreateCompleteMemberRestriction(possibleValues);

                // Prevent optimization of single constraint e.g: "300 in (300)"
                // But we want to optimize type constants e.g: "category in (Category)"
                // To prevent optimization of bool expressions we add a Sentinel OneOF

                var scalarConst = restriction as ScalarRestriction;
                var addSentinel =
                    scalarConst != null &&
                    !scalarConst.Domain.Contains(Constant.Null) &&
                    !scalarConst.Domain.Contains(Constant.NotNull) &&
                    !scalarConst.Domain.Contains(Constant.Undefined);

                if (addSentinel)
                {
                    domainMap.AddSentinel(newOneOf.RestrictedMemberSlot.MemberPath);
                }

                atoms.Add(BoolExpression.CreateLiteral(newOneOf, domainMap));

                if (addSentinel)
                {
                    domainMap.RemoveSentinel(newOneOf.RestrictedMemberSlot.MemberPath);
                }
            }
            // We create a new whereClause that has the memberDomainMap set
            if (atoms.Count > 0)
            {
                m_whereClause = BoolExpression.CreateAnd(atoms.ToArray());
            }
        }
Esempio n. 7
0
        // requires: The CellConstantDomains in the OneOfConsts of the where
        // clause are partially done
        // effects: Given the domains of different variables in domainMap,
        // fixes the whereClause of this such that all the
        // CellConstantDomains in OneOfConsts are complete
        internal void UpdateWhereClause(MemberDomainMap domainMap)
        {
            var atoms = new List<BoolExpression>();
            foreach (var atom in WhereClause.Atoms)
            {
                var literal = atom.AsLiteral;
                var restriction = literal as MemberRestriction;
                Debug.Assert(restriction != null, "All bool literals must be OneOfConst at this point");
                // The oneOfConst needs to be fixed with the new possible values from the domainMap.
                var possibleValues = domainMap.GetDomain(restriction.RestrictedMemberSlot.MemberPath);
                var newOneOf = restriction.CreateCompleteMemberRestriction(possibleValues);

                // Prevent optimization of single constraint e.g: "300 in (300)"
                // But we want to optimize type constants e.g: "category in (Category)"
                // To prevent optimization of bool expressions we add a Sentinel OneOF

                var scalarConst = restriction as ScalarRestriction;
                var addSentinel =
                    scalarConst != null &&
                    !scalarConst.Domain.Contains(Constant.Null) &&
                    !scalarConst.Domain.Contains(Constant.NotNull) &&
                    !scalarConst.Domain.Contains(Constant.Undefined);

                if (addSentinel)
                {
                    domainMap.AddSentinel(newOneOf.RestrictedMemberSlot.MemberPath);
                }

                atoms.Add(BoolExpression.CreateLiteral(newOneOf, domainMap));

                if (addSentinel)
                {
                    domainMap.RemoveSentinel(newOneOf.RestrictedMemberSlot.MemberPath);
                }
            }
            // We create a new whereClause that has the memberDomainMap set
            if (atoms.Count > 0)
            {
                m_whereClause = BoolExpression.CreateAnd(atoms.ToArray());
            }
        }
 /// <summary>
 /// Returns a boolean expression that is domain-aware and ready for optimizations etc.
 /// </summary>
 /// <param name="domainMap">Maps members to the values that each member can take;
 /// it can be null in which case the possible and actual values are the same.</param>
 internal override DomainBoolExpr GetDomainBoolExpression(MemberDomainMap domainMap)
 {
     // Get the variable name from the slot's memberpath and the possible domain values from the slot
     DomainTermExpr result;
     if (domainMap != null)
     {
         // Look up the domain from the domainMap
         var domain = domainMap.GetDomain(m_restrictedMemberSlot.MemberPath);
         result = MakeTermExpression(this, domain, m_domain.Values);
     }
     else
     {
         result = MakeTermExpression(this, m_domain.AllPossibleValues, m_domain.Values);
     }
     return result;
 }
 internal override BoolExpr <DomainConstraint <BoolLiteral, Constant> > GetDomainBoolExpression(
     MemberDomainMap domainMap)
 {
     return(domainMap == null ? (BoolExpr <DomainConstraint <BoolLiteral, Constant> >)BoolLiteral.MakeTermExpression((BoolLiteral)this, this.m_domain.AllPossibleValues, this.m_domain.Values) : (BoolExpr <DomainConstraint <BoolLiteral, Constant> >)BoolLiteral.MakeTermExpression((BoolLiteral)this, domainMap.GetDomain(this.m_restrictedMemberSlot.MemberPath), this.m_domain.Values));
 }