Пример #1
0
        public override IEnumerable TryNarrowing()
        {
            bool fail = false;

#if SearchHints
            if (SafeToGuess)
#endif
            {
                double randomElement = Value.RandomElement();
                CSP.PushChoice("Guess {0}={1}", this.Name, randomElement);
                this.NarrowTo(new Interval(randomElement), ref fail);
                Debug.Assert(!fail, "trial narrowing failed");
                yield return(false);
            }

            if ((CSP.Random.Next() & 1) == 0)
            {
                CSP.PushChoice("Lower half {0} to {1}", this.Name, this.Value.LowerHalf);
                this.NarrowTo(Value.LowerHalf, ref fail);
                Debug.Assert(!fail, "trial narrowing failed");
                yield return(false);

                CSP.PushChoice("Upper half {0} to {1}", this.Name, this.Value.UpperHalf);
                this.NarrowTo(Value.UpperHalf, ref fail);
                Debug.Assert(!fail, "trial narrowing failed");
                yield return(false);
            }
            else
            {
                CSP.PushChoice("Upper half {0} to {1}", this.Name, this.Value.UpperHalf);
                this.NarrowTo(Value.UpperHalf, ref fail);
                Debug.Assert(!fail, "trial narrowing failed");
                yield return(false);

                CSP.PushChoice("Lower half {0} to {1}", this.Name, this.Value.LowerHalf);
                this.NarrowTo(Value.LowerHalf, ref fail);
                Debug.Assert(!fail, "trial narrowing failed");
                yield return(false);
            }
        }
Пример #2
0
 protected Variable(string name, CSP p)
 {
     Name = name;
     p.Variables.Add(this);
     CSP = p;
 }
Пример #3
0
 public Vector3Variable(string name, CSP p, double x, double y, double z)
     : this(name, p, new Interval(x), new Interval(y), new Interval(z))
 {
 }
Пример #4
0
 public Vector3Variable(string name, CSP p, BoundingBox b)
     : this(name, p, b.X, b.Y, b.Z)
 {
 }
Пример #5
0
        public static FloatVariable Constant(CSP p, double c)
        {
// ReSharper disable SpecifyACultureInStringConversionExplicitly
            return(p.Memoize("constant", () => new FloatVariable(c.ToString(), p, c, c), c));
// ReSharper restore SpecifyACultureInStringConversionExplicitly
        }
Пример #6
0
 public FloatVariable(string name, CSP csp)
     : this(name, csp, Interval.AllValues)
 {
 }
Пример #7
0
 public FloatVariable(string name, CSP p, Interval initialValue)
     : base(name, p, p.IntervalUndoStack, initialValue)
 {
 }
Пример #8
0
 public FloatVariable(string name, CSP p, double lower, double upper)
     : this(name, p, new Interval(lower, upper))
 {
 }