Ejemplo n.º 1
0
        /// <summary>
        /// True if these intervals are equal to intervals to compare I.e. if they share a common dimension and μthis(x) = μsetToCompare(x) for each x in &lt;dimension.minValue, dimension.MaxValue&gt;
        /// </summary>
        /// <param name="setToCompare">Set to compare</param>
        /// <returns>True if this set is equal to setToCompare.</returns>
        public override bool Equals(object setToCompare)
        {
            if (!(setToCompare is IntervalSet))
            {
                return(false);
            }

            IntervalSet isSetToCompare = (IntervalSet)setToCompare;

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

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

            foreach (BinaryInterval operands in binaryInterval)
            {
                if (operands.LowerBound == operands.UpperBound)
                {
                    double val1 = Interval.GetPolynomial(operands.Coefficients1).Evaluate(new Complex((double)operands.LowerBound)).Re;
                    double val2 = Interval.GetPolynomial(operands.Coefficients2).Evaluate(new Complex((double)operands.LowerBound)).Re;

                    if (val1 != val2)
                    {
                        return(false);
                    }
                }
                else
                {
                    for (int i = 0; i < Math.Max(operands.Coefficients1.Length, operands.Coefficients2.Length); i++)
                    {
                        if (i < operands.Coefficients1.Length && i < operands.Coefficients2.Length && Math.Round(operands.Coefficients1[i], 6) != Math.Round(operands.Coefficients2[i], 6))
                        {
                            return(false);
                        }
                        else if (i < operands.Coefficients1.Length && i >= operands.Coefficients2.Length && operands.Coefficients1[i] != 0)
                        {
                            return(false);
                        }
                        else if (i >= operands.Coefficients1.Length && i < operands.Coefficients2.Length && operands.Coefficients2[i] != 0)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 2
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);
        }