Domains. This is an abstract class for domains. A domain ...
Inheritance: ICloneable
Example #1
0
 /// <summary> Constructs a variable of the network
 /// with an initial domain <tt>d</tt>
 /// and a name specified by the parameter <tt>name</tt>.
 /// When the parameter <tt>name</tt> is <tt>null</tt>,
 /// default names (<tt>v1</tt>, <tt>v2</tt>, and so on) are used.
 /// </summary>
 /// <param name="net">the network
 /// </param>
 /// <param name="d">the initial domain
 /// </param>
 /// <param name="name">the name of the variable, or <tt>null</tt> for a default name
 /// </param>
 public Variable(Network net, Domain d, String name)
 {
     Network = net;
     Domain = d;
     _modified = true;
     _watch = false;
     Name = name ?? "v" + (_count++);
     Network.ADD(this);
 }
Example #2
0
        /// <summary> Constructs a solution from the given network.</summary>
        /// <param name="network">the constraint network
        /// </param>
        public Solution(Network network)
        {
            _network = network;
            _objectiveDomain = null;
            if (network.Objective != null)
            {
                _objectiveDomain = network.Objective.Domain;
            }
            System.Collections.IList variables = network.Variables;
            _bindings = new Domain[variables.Count];
            System.Collections.IEnumerator vs = variables.GetEnumerator();
            while (vs.MoveNext())
            {
                var v = (Variable) vs.Current;
                _bindings[v.Index] = v.Domain;
            }
            // Do th efollowing for Soft constraints only
            //SwapValuesToPreferences();

            _code = new Code(network);
        }
Example #3
0
 public abstract bool Equals(Domain d);
Example #4
0
 public abstract Domain Difference(Domain d);
Example #5
0
 public abstract Domain Cup(Domain d);
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IntVariable"/> class.  Constructs an integer variable of the network
 /// with an initial integer domain <tt>d</tt>
 /// and a name specified by the parameter <tt>name</tt>.
 /// When the parameter <tt>name</tt> is <tt>null</tt>,
 /// default names (<tt>v1</tt>, <tt>v2</tt>, and so on) are used.
 /// </summary>
 /// <param name="net">
 /// the network
 /// </param>
 /// <param name="d">
 /// the initial integer domain
 /// </param>
 /// <param name="name">
 /// the name of the variable, or <tt>null</tt> for a default name
 /// </param>
 public IntVariable(Network net, Domain d, string name)
     : base(net, d, name)
 {
     IsValueType = false;
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IntVariable"/> class.  Constructs an integer variable of the network
 /// with an initial integer domain <tt>d</tt>
 /// and a default name.
 /// This constructor is equivalent to <tt>IntVariable(network, d, null)</tt>.
 /// </summary>
 /// <param name="net">
 /// the network
 /// </param>
 /// <param name="d">
 /// the initial integer domain
 /// </param>
 public IntVariable(Network net, Domain d)
     : this(net, d, null)
 {
 }
Example #8
0
        /// <summary>
        /// Checks for equality qith another domain
        /// </summary>
        /// <param name="domain">
        /// The domain
        /// </param>
        /// <returns>
        /// boolean value
        /// </returns>
        public override bool Equals(Domain domain)
        {
            if (this == domain)
            {
                return true;
            }

            if (!(domain is IntDomain))
            {
                return false;
            }

            var d = (IntDomain)domain;
            if (_intervals.Count != d._intervals.Count)
            {
                return false;
            }

            try
            {
                for (int i = 0; i < _intervals.Count; i++)
                {
                    var i0 = (int[])_intervals[i];
                    var i1 = (int[])d._intervals[i];
                    if (i0[0] != i1[0] || i0[1] != i1[1])
                    {
                        return false;
                    }
                }
            }
            catch (IndexOutOfRangeException)
            {
            }

            return true;
        }
Example #9
0
 /// <summary>
 /// Difference between two domains
 /// </summary>
 /// <param name="domian">
 /// The domian.
 /// </param>
 /// <returns>
 /// Domain object
 /// </returns>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public override Domain Difference(Domain domian)
 {
     throw new NotImplementedException();
 }
Example #10
0
 /// <summary>
 /// not implemented method
 /// </summary>
 /// <param name="domain">
 /// The domain.
 /// </param>
 /// <returns>
 /// domain object
 /// </returns>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public override Domain Cup(Domain domain)
 {
     throw new NotImplementedException();
 }
Example #11
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;
        }
Example #12
0
 /// <summary>
 /// Updates the domain of the current variable with the parameter domain d after
 /// pushing the Trail trial
 /// </summary>
 /// <param name="d">the domain to be updated with</param>
 /// <param name="trail">the trail to be pushed</param>
 public virtual void UpdateDomain(Domain d, Trail trail)
 {
     if (_domain == null || !_domain.Equals(d))
     {
         trail.Push(this);
         _domain = d;
         _modified = true;
         if (_watch)
         {
             Console.Out.WriteLine(this + " = " + _domain);
         }
     }
 }
Example #13
0
 /// <summary> Constructs a variable of the network
 /// with an initial domain <tt>d</tt>
 /// and a default name.
 /// This constructor is equivalent to <tt>Variable(network, d, null)</tt>.
 /// </summary>
 /// <param name="net">the network
 /// </param>
 /// <param name="d">the initial domain
 /// </param>
 public Variable(Network net, Domain d) : this(net, d, null)
 {
 }
Example #14
0
 /// <summary>
 /// Difference between two domains
 /// </summary>
 /// <param name="domian">
 /// The domian.
 /// </param>
 /// <returns>
 /// Domain object
 /// </returns>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public override Domain Difference(Domain domian)
 {
     throw new NotImplementedException();
 }
Example #15
0
 /// <summary>
 /// not implemented method
 /// </summary>
 /// <param name="domain">
 /// The domain.
 /// </param>
 /// <returns>
 /// domain object
 /// </returns>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public override Domain Cup(Domain domain)
 {
     throw new NotImplementedException();
 }
Example #16
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);
        }