Exemple #1
0
        /// <summary>
        /// Deletes values between minimum and miximum values
        /// </summary>
        /// <param name="low">
        /// The low.value
        /// </param>
        /// <param name="high">
        /// The high.value
        /// </param>
        /// <returns>
        /// IntDomain object
        /// </returns>
        public virtual IntDomain Delete(int low, int high)
        {
            if (sizeField == 0 || low > high || high < minField || maxField < low)
            {
                return(this);
            }

            if (low == high)
            {
                return(Delete(low));
            }

            var d = new IntDomain();

            try
            {
                for (int i = 0; i < intervals.Count; i++)
                {
                    var interval = (int[])intervals[i];
                    int mi       = Math.Max(low, interval[0]);
                    int ma       = Math.Min(high, interval[1]);
                    if (mi <= ma)
                    {
                        if (interval[0] < mi)
                        {
                            var period = new int[2];
                            period[0] = interval[0];
                            period[1] = mi - 1;
                            d.intervals.Add(period);
                        }

                        if (ma < interval[1])
                        {
                            var period = new int[2];
                            period[0] = ma + 1;
                            period[1] = interval[1];
                            d.intervals.Add(period);
                        }
                    }
                    else
                    {
                        var period = new int[2];
                        period[0] = interval[0];
                        period[1] = interval[1];
                        d.intervals.Add(period);
                    }
                }
            }
            catch (IndexOutOfRangeException)
            {
            }

            d.UpdateSize();
            d.UpdateMinMax();
            return(d);
        }
Exemple #2
0
        /// <summary>
        /// Deletes values between minimum and miximum values
        /// </summary>
        /// <param name="low">
        /// The low.value
        /// </param>
        /// <param name="high">
        /// The high.value
        /// </param>
        /// <returns>
        /// IntDomain object
        /// </returns>
        public virtual IntDomain Delete(int low, int high)
        {
            if (sizeField == 0 || low > high || high < _minField || _maxField < low)
            {
                return this;
            }

            if (low == high)
            {
                return Delete(low);
            }

            var d = new IntDomain();
            try
            {
                for (int i = 0; i < _intervals.Count; i++)
                {
                    var interval = (int[])_intervals[i];
                    int mi = Math.Max(low, interval[0]);
                    int ma = Math.Min(high, interval[1]);
                    if (mi <= ma)
                    {
                        if (interval[0] < mi)
                        {
                            var period = new int[2];
                            period[0] = interval[0];
                            period[1] = mi - 1;
                            d._intervals.Add(period);
                        }

                        if (ma < interval[1])
                        {
                            var period = new int[2];
                            period[0] = ma + 1;
                            period[1] = interval[1];
                            d._intervals.Add(period);
                        }
                    }
                    else
                    {
                        var period = new int[2];
                        period[0] = interval[0];
                        period[1] = interval[1];
                        d._intervals.Add(period);
                    }
                }
            }
            catch (IndexOutOfRangeException)
            {
            }

            d.UpdateSize();
            d.UpdateMinMax();
            return d;
        }
Exemple #3
0
        /// <summary>
        /// Capitalize domain
        /// </summary>
        /// <param name="domain">
        /// The domain.
        /// </param>
        /// <returns>
        /// A modified domain
        /// </returns>
        public override Domain Cap(Domain domain)
        {
            if (!(domain is IntDomain))
            {
                return emptyDomain;
            }

            var newD = new IntDomain();
            IntDomain d0 = this;
            var d1 = (IntDomain)domain;
            try
            {
                int i0 = 0;
                int i1 = 0;
                while (i0 < d0._intervals.Count && i1 < d1._intervals.Count)
                {
                    var interval = (int[])d0._intervals[i0];
                    int min0 = interval[0];
                    int max0 = interval[1];
                    interval = (int[])d1._intervals[i1];
                    int min1 = interval[0];
                    int max1 = interval[1];
                    if (max0 < min1)
                    {
                        i0++;
                        continue;
                    }

                    if (max1 < min0)
                    {
                        i1++;
                        continue;
                    }

                    interval = new int[2];
                    interval[0] = Math.Max(min0, min1);
                    interval[1] = Math.Min(max0, max1);
                    newD._intervals.Add(interval);
                    if (max0 <= max1)
                    {
                        i0++;
                    }

                    if (max1 <= max0)
                    {
                        i1++;
                    }
                }
            }
            catch (IndexOutOfRangeException)
            {
            }

            newD.UpdateSize();
            newD.UpdateMinMax();
            if (newD.Empty)
            {
                return emptyDomain;
            }

            return newD;
        }
Exemple #4
0
        /// <summary>
        /// Capitalize domain
        /// </summary>
        /// <param name="domain">
        /// The domain.
        /// </param>
        /// <returns>
        /// A modified domain
        /// </returns>
        public override Domain Cap(Domain domain)
        {
            if (!(domain is IntDomain))
            {
                return(EmptyDomain);
            }

            var       newD = new IntDomain();
            IntDomain d0   = this;
            var       d1   = (IntDomain)domain;

            try
            {
                int i0 = 0;
                int i1 = 0;
                while (i0 < d0.intervals.Count && i1 < d1.intervals.Count)
                {
                    var interval = (int[])d0.intervals[i0];
                    int min0     = interval[0];
                    int max0     = interval[1];
                    interval = (int[])d1.intervals[i1];
                    int min1 = interval[0];
                    int max1 = interval[1];
                    if (max0 < min1)
                    {
                        i0++;
                        continue;
                    }

                    if (max1 < min0)
                    {
                        i1++;
                        continue;
                    }

                    interval    = new int[2];
                    interval[0] = Math.Max(min0, min1);
                    interval[1] = Math.Min(max0, max1);
                    newD.intervals.Add(interval);
                    if (max0 <= max1)
                    {
                        i0++;
                    }

                    if (max1 <= max0)
                    {
                        i1++;
                    }
                }
            }
            catch (IndexOutOfRangeException)
            {
            }

            newD.UpdateSize();
            newD.UpdateMinMax();
            if (newD.Empty)
            {
                return(EmptyDomain);
            }

            return(newD);
        }