Changeset 16591


Ignore:
Timestamp:
02/06/19 14:41:06 (2 weeks ago)
Author:
chaider
Message:

#2971 Fixed checking if a given interval is in another interval

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator.cs

    r16589 r16591  
    5151      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5252      QualityParameter.ActualValue = new DoubleValue(quality);
    53 
    5453      return base.InstrumentedApply();
    5554    }
     
    6766
    6867      foreach (var constraint in constraints) {
    69         if (!variableRanges.ContainsKey(constraint.Variable))
     68        if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable))
    7069          throw new ArgumentException($"The given variable {constraint.Variable} in the constraint does not exists in the model.", nameof(IntervalConstraintsParser));
    7170        if (!constraint.IsDerivation) {
     
    118117
    119118    private static bool IntervalInBoundaries(Interval i1, Interval i2, bool inclusiveLower, bool inclusiveUpper) {
    120       if (inclusiveLower) {
    121         if (i2.LowerBound < i1.LowerBound)
    122           return false;
    123       } else {
    124         if (i2.LowerBound <= i1.LowerBound)
    125           return false;
     119      if (double.IsNegativeInfinity(i1.LowerBound) && double.IsPositiveInfinity(i1.UpperBound))
     120        return true;
     121      //Left-unbounded and right-bounded:
     122      if (double.IsNegativeInfinity(i1.LowerBound)) {
     123        if (inclusiveUpper)
     124          return i2.LowerBound <= i1.UpperBound && i2.UpperBound <= i1.UpperBound;
     125        return i2.LowerBound < i1.UpperBound && i2.UpperBound < i1.UpperBound;
    126126      }
    127127
    128       if (inclusiveUpper) {
    129         if (i2.UpperBound > i1.UpperBound)
    130           return false;
    131       } else {
    132         if (i2.UpperBound >= i1.UpperBound)
    133           return false;
     128      //Left-bounded and right-unbounded:
     129      if (double.IsPositiveInfinity(i1.UpperBound)) {
     130        if (inclusiveLower)
     131          return i2.LowerBound >= i1.LowerBound && i2.UpperBound >= i1.LowerBound;
     132        return i2.LowerBound > i1.LowerBound && i2.UpperBound > i1.LowerBound;
    134133      }
    135134
    136       return true;
     135      //Proper and bounded:
     136      //Closed:
     137      if (inclusiveLower && inclusiveUpper) {
     138        return i1.LowerBound <= i2.LowerBound && i2.UpperBound <= i1.UpperBound;
     139      }
     140      //Open:
     141      if (!inclusiveLower && !inclusiveUpper) {
     142        return i1.LowerBound < i2.LowerBound && i2.UpperBound < i1.UpperBound;
     143      }
     144      //Left-closed, right-open:
     145      if (inclusiveLower) {
     146        return i1.LowerBound <= i2.LowerBound && i2.UpperBound < i1.UpperBound;
     147      }
     148      //Left-open, right-closed:
     149      return i1.LowerBound < i2.LowerBound && i2.UpperBound <= i1.UpperBound;
    137150    }
    138151  }
Note: See TracChangeset for help on using the changeset viewer.