コード例 #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
ファイル: Variable.cs プロジェクト: relimited/Craft
 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))
 {
 }