Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public static NumericVariable operator -(NumericVariable v)
        {
            NumericVariable result = v.DeriveVariable("Invrh", $"-.{v.VarIndex}");

            IsInverseConstraint.CreateIsInverseConstraint(v, result);
            return(result);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 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));
     }
 }
Ejemplo n.º 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));
     }
 }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
 protected override bool Update(NumericVariable v)
 {
     return(v.RestrictRange(_range));
 }
Ejemplo n.º 9
0
 private AtLeastConstraint(NumericVariable variable1, NumericVariable variable2) : base(variable1, variable2)
 {
 }
Ejemplo n.º 10
0
 public static AtLeastConstraint CreateAtLeastConstraint(NumericVariable variable1, NumericVariable variable2)
 {
     return(new AtLeastConstraint(variable1, variable2));
 }
Ejemplo n.º 11
0
 protected override bool Update(NumericVariable v)
 {
     return(v.RestrictRange(-(v == _variable1 ? _variable2 : _variable1).Value));
 }
Ejemplo n.º 12
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);
 }
Ejemplo n.º 13
0
 public VariableVector MaxY(NumericVariable value)
 {
     _y.Max(value);
     return(this);
 }
Ejemplo n.º 14
0
 public VariableVector MinY(NumericVariable value)
 {
     _y.Min(value);
     return(this);
 }
Ejemplo n.º 15
0
 protected abstract bool Update(NumericVariable v);
Ejemplo n.º 16
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);
 }
Ejemplo n.º 17
0
 public static ProportionalConstraint CreateProportionalConstraint(double d, NumericVariable variable1, NumericVariable variable2)
 {
     return(new ProportionalConstraint(d, variable1, variable2));
 }
Ejemplo n.º 18
0
 private RangeConstraint(NumericVariable inputVariable, Range range) : base(inputVariable)
 {
     _range = range;
 }
Ejemplo n.º 19
0
 public static RangeConstraint CreateRangeConstraint(NumericVariable inputVariable, Range range)
 {
     return(new RangeConstraint(inputVariable, range));
 }
Ejemplo n.º 20
0
 protected UnaryConstraint([NotNull] NumericVariable inputVariable) : base(inputVariable)
 {
     _inputVariable = inputVariable;
 }
Ejemplo n.º 21
0
 private ProportionalConstraint(double d, NumericVariable variable1, NumericVariable variable2) : base(variable1, variable2)
 {
     _d = d;
 }
Ejemplo n.º 22
0
 protected BinaryConstraint([NotNull] NumericVariable variable1, [NotNull] NumericVariable variable2) : base(variable1, variable2)
 {
     _variable1 = variable1;
     _variable2 = variable2;
 }
Ejemplo n.º 23
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);
        }
Ejemplo n.º 24
0
 public static EqualityConstraint CreateEqualityConstraint(NumericVariable variable1, NumericVariable variable2)
 {
     return(new EqualityConstraint(variable1, variable2));
 }
Ejemplo n.º 25
0
 protected override bool Update(NumericVariable v)
 {
     throw new NotImplementedException("Update(IEnumerable<NumericVariable>) is overridden");
 }
Ejemplo n.º 26
0
 private EqualityConstraint(NumericVariable variable1, NumericVariable variable2) : base(variable1, variable2)
 {
 }
Ejemplo n.º 27
0
 public VariableVector SetY(NumericVariable value)
 {
     _y.Set(value);
     return(this);
 }
Ejemplo n.º 28
0
 public static IsInverseConstraint CreateIsInverseConstraint(NumericVariable variable1, NumericVariable variable2)
 {
     return(new IsInverseConstraint(variable1, variable2));
 }
Ejemplo n.º 29
0
 public VariableVector(string name, [NotNull] NumericVariable x, [NotNull] NumericVariable y)
 {
     Name = name;
     _x   = x;
     _y   = y;
 }
Ejemplo n.º 30
0
 private IsInverseConstraint(NumericVariable variable1, NumericVariable variable2) : base(variable1, variable2)
 {
 }