/// <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); }
/// <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); }
public abstract bool Equals(Domain d);
public abstract Domain Difference(Domain d);
public abstract Domain Cup(Domain d);
/// <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; }
/// <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) { }
/// <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; }
/// <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(); }
/// <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(); }
/// <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; }
/// <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); } } }
/// <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) { }
/// <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); }