/// <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.");
     IEnumerable<Constant> newPossibleValues = memberDomainMap.GetDomain(RestrictedMemberSlot.MemberPath);
     BoolLiteral newLiteral = new ScalarRestriction(RestrictedMemberSlot, new Domain(range, newPossibleValues));
     return newLiteral.GetDomainBoolExpression(memberDomainMap);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Requires: <see cref="MemberRestriction.IsComplete"/> is true.
        /// </summary>
        internal override DomainBoolExpr FixRange(Set <Constant> range, MemberDomainMap memberDomainMap)
        {
            Debug.Assert(IsComplete, "Ranges are fixed only for complete type restrictions.");
            IEnumerable <Constant> possibleValues = memberDomainMap.GetDomain(RestrictedMemberSlot.MemberPath);
            BoolLiteral            newLiteral     = new TypeRestriction(RestrictedMemberSlot, new Domain(range, possibleValues));

            return(newLiteral.GetDomainBoolExpression(memberDomainMap));
        }
Ejemplo n.º 3
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
                IEnumerable <Constant> 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);
        }
Ejemplo n.º 4
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)
        {
            List <BoolExpression> atoms = new List <BoolExpression>();

            foreach (BoolExpression atom in WhereClause.Atoms)
            {
                BoolLiteral       literal     = atom.AsLiteral;
                MemberRestriction 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.
                IEnumerable <Constant> possibleValues = domainMap.GetDomain(restriction.RestrictedMemberSlot.MemberPath);
                MemberRestriction      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

                ScalarRestriction scalarConst = restriction as ScalarRestriction;
                bool 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
         IEnumerable<Constant> 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;
 }
Ejemplo 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());
            }
        }