Exemplo n.º 1
0
        /// <summary>
        /// True if these intervals includes the intervals to compare. I.e. if they share a common dimension and μthis(x) &lt;= μsetToCompare(x) for each x in &lt;dimension.minValue, dimension.MaxValue&gt;.
        /// Note that equalty is a special case of inclusion. To check for proper inclusion, you woud have to evaluate if this.Includes(setToCompare) && ! this.Equals(setToCompare).
        /// </summary>
        /// <param name="relationToCompare">Set to compare</param>
        /// <returns>True if this set is a subset of setToCompare.</returns>
        public bool Includes(IntervalSet setToCompare)
        {
            IntervalSet isSetToCompare = setToCompare;

            if (this.Dimension != isSetToCompare.Dimension)
            {
                return(false);
            }

            List <BinaryInterval> binaryInterval = BinaryOperator.BuildBinaryInterval(this, isSetToCompare);

            foreach (BinaryInterval operands in binaryInterval)
            {
                IntervalSet minimum = new IntervalSet(this.Dimension);
                BinaryOperator.GetMinMax(operands, ref minimum, true);



                //Does the minimum equals operands.Operand2? That is the question
                IntervalSet included = new IntervalSet(this.Dimension);
                included.AddInterval(new Interval(included, operands.LowerBound, operands.UpperBound, operands.Coefficients2));

                if (this.Dimension is IContinuousDimension)
                {
                    //add empty intervals just to pass the check() method
                    decimal minVal = ((IContinuousDimension)this.Dimension).MinValue;
                    decimal maxVal = ((IContinuousDimension)this.Dimension).MaxValue;
                    if (minVal < operands.LowerBound)
                    {
                        minimum.AddInterval(new Interval(minimum, minVal, operands.LowerBound, 0));
                        included.AddInterval(new Interval(included, minVal, operands.LowerBound, 0));
                    }
                    if (maxVal > operands.UpperBound)
                    {
                        minimum.AddInterval(new Interval(minimum, operands.UpperBound, maxVal, 0));
                        included.AddInterval(new Interval(included, operands.UpperBound, maxVal, 0));
                    }
                }

                if (!minimum.Equals(included))
                {
                    return(false);
                }
            }

            return(true);
        }