Example #1
0
        public static NumericVariable operator /(NumericVariable v, double d)
        {
            NumericVariable result = v.DeriveVariable("Prop/rh", $".{v.VarIndex}/{d}");

            ProportionalConstraint.CreateProportionalConstraint(d, result, v);
            return(result);
        }
Example #2
0
        public static NumericVariable operator -(NumericVariable v)
        {
            NumericVariable result = v.DeriveVariable("Invrh", $"-.{v.VarIndex}");

            IsInverseConstraint.CreateIsInverseConstraint(v, result);
            return(result);
        }
Example #3
0
        public static NumericVariable operator -(NumericVariable left, NumericVariable right)
        {
            NumericVariable result = left.DeriveVariable("+Sum0rh", $".{left.VarIndex}-.{right.VarIndex}");

            SumIs0Constraint.CreateSumIs0Constraint(-left, right, result);
            return(result);
        }
 public SimpleConstraintSolver(double eps = 1.0 / 1024.0 / 1024.0 / 1024.0)
 {
     Eps          = eps;
     ZERO         = CreateConstant("0", 0);
     ONE          = CreateConstant("1", 1);
     NEGATIVE_INF = CreateConstant("-inf", double.NegativeInfinity);
     POSITIVE_INF = CreateConstant("+inf", double.PositiveInfinity);
 }
Example #5
0
 protected override bool Update(NumericVariable v)
 {
     if (v == _variable1)
     {
         return(_variable1.RestrictRange(_variable2.Value.Lo, _variable2.Value.Hi, 1 / _d));
     }
     else
     {
         return(_variable2.RestrictRange(_variable1.Value.Lo, _variable1.Value.Hi, _d));
     }
 }
Example #6
0
 protected override bool Update(NumericVariable v)
 {
     if (v == _variable1)
     {
         // v1 >= v2
         return(_variable1.RestrictRange(_variable2.Value.Lo, double.PositiveInfinity));
     }
     else
     {
         // v2 <= v1
         return(_variable2.RestrictRange(double.NegativeInfinity, _variable1.Value.Hi));
     }
 }
        internal NumericVariable GetOrCreateVariable([NotNull] string shortName, [NotNull] string definition, double?lo, double?hi, float interpolate)
        {
            if (_solved)
            {
                throw new InvalidOperationException($"Solver is solved - no new variable '{shortName}', please! (definition='{definition}')");
            }

            NumericVariable result;

            if (!_allVariables.TryGetValue(definition, out result))
            {
                _allVariables.Add(definition, result = new NumericVariable(shortName, definition, this, lo, hi, interpolate));
            }
            return(result);
        }
Example #8
0
 public static AtLeastConstraint CreateAtLeastConstraint(NumericVariable variable1, NumericVariable variable2)
 {
     return(new AtLeastConstraint(variable1, variable2));
 }
Example #9
0
 protected override bool Update(NumericVariable v)
 {
     return(v.RestrictRange(-(v == _variable1 ? _variable2 : _variable1).Value));
 }
Example #10
0
 private IsInverseConstraint(NumericVariable variable1, NumericVariable variable2) : base(variable1, variable2)
 {
 }
Example #11
0
 public static IsInverseConstraint CreateIsInverseConstraint(NumericVariable variable1, NumericVariable variable2)
 {
     return(new IsInverseConstraint(variable1, variable2));
 }
Example #12
0
 private EqualityConstraint(NumericVariable variable1, NumericVariable variable2) : base(variable1, variable2)
 {
 }
Example #13
0
 public static EqualityConstraint CreateEqualityConstraint(NumericVariable variable1, NumericVariable variable2)
 {
     return(new EqualityConstraint(variable1, variable2));
 }
Example #14
0
 public VariableVector MaxY(NumericVariable value)
 {
     _y.Max(value);
     return(this);
 }
Example #15
0
 protected abstract bool Update(NumericVariable v);
Example #16
0
 public VariableVector SetY(NumericVariable value)
 {
     _y.Set(value);
     return(this);
 }
Example #17
0
 public static ProportionalConstraint CreateProportionalConstraint(double d, NumericVariable variable1, NumericVariable variable2)
 {
     return(new ProportionalConstraint(d, variable1, variable2));
 }
Example #18
0
 protected UnaryConstraint([NotNull] NumericVariable inputVariable) : base(inputVariable)
 {
     _inputVariable = inputVariable;
 }
Example #19
0
 /// <summary>
 /// The variable's maximum is restricted to the (eventual) value of another variable.
 /// </summary>
 /// <returns><c>this</c></returns>
 public NumericVariable Max(NumericVariable value)
 {
     AtLeastConstraint.CreateAtLeastConstraint(value, this);
     return(this);
 }
Example #20
0
 /// <summary>
 /// The variable's value is restricted to be equal to the (eventual) value of another variable.
 /// </summary>
 /// <returns><c>this</c></returns>
 public NumericVariable Set(NumericVariable value)
 {
     EqualityConstraint.CreateEqualityConstraint(this, value);
     return(this);
 }
Example #21
0
 /// <summary>
 /// The variable's minimum is restricted to the (eventual) value of another variable.
 /// </summary>
 /// <returns><c>this</c></returns>
 public NumericVariable Min(NumericVariable value)
 {
     AtLeastConstraint.CreateAtLeastConstraint(this, value);
     return(this);
 }
Example #22
0
 private AtLeastConstraint(NumericVariable variable1, NumericVariable variable2) : base(variable1, variable2)
 {
 }
Example #23
0
 public static RangeConstraint CreateRangeConstraint(NumericVariable inputVariable, Range range)
 {
     return(new RangeConstraint(inputVariable, range));
 }
Example #24
0
 public VariableVector(string name, [NotNull] NumericVariable x, [NotNull] NumericVariable y)
 {
     Name = name;
     _x   = x;
     _y   = y;
 }
Example #25
0
 private ProportionalConstraint(double d, NumericVariable variable1, NumericVariable variable2) : base(variable1, variable2)
 {
     _d = d;
 }
Example #26
0
 private RangeConstraint(NumericVariable inputVariable, Range range) : base(inputVariable)
 {
     _range = range;
 }
Example #27
0
        //public SumIs0Constraint Plus(DoubleHolder d) {
        //    return new SumIs0Constraint(_plus.Concat(new[] { d }));
        //}

        protected override bool Update(NumericVariable v)
        {
            bool changed = false;

            // The following propagation uses these ideas:
            // For each variable v, take the sum S of all OTHER Lo values. A high value that is higher
            // than -S will never cancel S to zero, let alone sums that are greater than S. Hence,
            // v.Hi can be restricted to <= -S.
            // Likewise, v.Lo can be restricted to >= -S where S is the sum of all other Hi values.

            // O(n^2) algorithm - a O(n) algorithm is possible ... later
            double loSum = 0;

            // OnceExcluded is necessary for a constraint like X + X + Y = 0: When we already know
            // that X = [100..100] and Y = [-200..-200], this should succeed. However, when during
            // Upgrade(X) we skip both X's (via w != v), the sum will not be 100-200 == 100, but
            // -200; and hence
            // X will then be restricted to [200..+inf], which, together with the previously known
            // value X = 100 will erroneously imply that there is no solution for X.
            // By the way, when in X + X + Y = 0, we have X = [-inf...+inf] and Y = [-200..-200] at
            // the beginning, we will NOT conclude that X = [100..100] - that would be equation
            // solving, which we do not support at this level.

            bool onceExcluded = false;

            foreach (var w in _inputVariables)
            {
                if (onceExcluded || w != v)
                {
                    double wLo = w.Value.Lo;
                    if (double.IsNegativeInfinity(wLo))
                    {
                        // Nothing can be said about the sum of lows - cancel this computation;
                        goto SKIP_LO;
                    }
                    loSum += wLo;
                }
                else
                {
                    onceExcluded = true;
                }
            }
            changed |= v.RestrictRange(double.NegativeInfinity, -loSum);
SKIP_LO:

            double hiSum = 0;

            onceExcluded = false;
            foreach (var w in _inputVariables)
            {
                if (onceExcluded || w != v)
                {
                    double wHi = w.Value.Hi;
                    if (double.IsPositiveInfinity(wHi))
                    {
                        // Nothing can be said about the sum of his - cancel this computation;
                        goto SKIP_HI;
                    }
                    hiSum += wHi;
                }
                else
                {
                    onceExcluded = true;
                }
            }
            changed |= v.RestrictRange(-hiSum, double.PositiveInfinity);
SKIP_HI:
            return(changed);
        }
Example #28
0
 protected override bool Update(NumericVariable v)
 {
     return(v.RestrictRange(_range));
 }
Example #29
0
 protected override bool Update(NumericVariable v)
 {
     throw new NotImplementedException("Update(IEnumerable<NumericVariable>) is overridden");
 }
Example #30
0
 protected BinaryConstraint([NotNull] NumericVariable variable1, [NotNull] NumericVariable variable2) : base(variable1, variable2)
 {
     _variable1 = variable1;
     _variable2 = variable2;
 }