Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/25/19 13:39:43 (5 years ago)
Author:
chaider
Message:

#2971 Removed the possibility of declaring open and closed intervals. All intervals are closed intervals now.

Location:
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs

    r17368 r17370  
    7171    }
    7272
    73     public bool Contains(Interval other, bool lowerBoundInclusive = true, bool upperBoundInclusive = false) {
    74       if (double.IsNegativeInfinity(this.LowerBound) && double.IsPositiveInfinity(this.UpperBound))
    75         return true;
    76       //Left-unbounded and right-bounded:
    77       if (double.IsNegativeInfinity(this.LowerBound)) {
    78         if (upperBoundInclusive)
    79           return other.LowerBound <= this.UpperBound && other.UpperBound <= this.UpperBound;
    80         return other.LowerBound < this.UpperBound && other.UpperBound < this.UpperBound;
    81       }
    82 
    83       //Left-bounded and right-unbounded:
    84       if (double.IsPositiveInfinity(this.UpperBound)) {
    85         if (lowerBoundInclusive)
    86           return other.LowerBound >= this.LowerBound && other.UpperBound >= this.LowerBound;
    87         return other.LowerBound > this.LowerBound && other.UpperBound > this.LowerBound;
    88       }
    89 
    90       //Proper and bounded:
    91       //Closed:
    92       if (lowerBoundInclusive && upperBoundInclusive) {
    93         return this.LowerBound <= other.LowerBound && other.UpperBound <= this.UpperBound;
    94       }
    95 
    96       //Open:
    97       if (!lowerBoundInclusive && !upperBoundInclusive) {
    98         return this.LowerBound < other.LowerBound && other.UpperBound < this.UpperBound;
    99       }
    100 
    101       //Left-closed, right-open:
    102       if (lowerBoundInclusive) {
    103         return this.LowerBound <= other.LowerBound && other.UpperBound < this.UpperBound;
    104       }
    105 
    106       //Left-open, right-closed:
    107       return this.LowerBound < other.LowerBound && other.UpperBound <= this.UpperBound;
     73    public bool Contains(Interval other) {
     74      if (double.IsNegativeInfinity(LowerBound) && double.IsPositiveInfinity(UpperBound)) return true;
     75      if (other.LowerBound >= LowerBound && other.UpperBound <= UpperBound) return true;
     76 
     77      return false;
    10878    }
    10979
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraint.cs

    r16964 r17370  
    9898
    9999    [Storable]
    100     private bool inclusiveLowerBound;
    101     public bool InclusiveLowerBound {
    102       get => inclusiveLowerBound;
    103       set {
    104         if (inclusiveLowerBound == value) return;
    105         inclusiveLowerBound = value;
    106         UpdateExpression();
    107         OnChanged();
    108       }
    109     }
    110 
    111     [Storable]
    112     private bool inclusiveUpperBound;
    113     public bool InclusiveUpperBound {
    114       get => inclusiveUpperBound;
    115       set {
    116         if (inclusiveUpperBound == value) return;
    117         inclusiveUpperBound = value;
    118         UpdateExpression();
    119         OnChanged();
    120       }
    121     }
    122 
    123     [Storable]
    124100    private bool enabled;
    125101    public bool Enabled {
     
    135111    private IntervalConstraint(StorableConstructorFlag _) : base(_) { }
    136112
    137     public IntervalConstraint(string expression, string variable, string target, int numberOfDerivation, Interval interval, bool inclusiveLowerBound,
    138       bool inclusiveUpperBound, bool enabled) : base(){
     113    public IntervalConstraint(string expression, string variable, string target, int numberOfDerivation, Interval interval, bool enabled) : base(){
    139114      this.expression = expression;
    140115      this.variable = variable;
     
    142117      this.numberOfDerivation = numberOfDerivation;
    143118      this.interval = interval;
    144       this.inclusiveLowerBound = inclusiveLowerBound;
    145       this.inclusiveUpperBound = inclusiveUpperBound;
    146119      this.enabled = enabled;
    147120    }
     
    158131      this.NumberOfDerivation = original.NumberOfDerivation;
    159132      this.Interval = original.Interval;
    160       this.InclusiveLowerBound = original.InclusiveLowerBound;
    161       this.InclusiveUpperBound = original.InclusiveUpperBound;
    162133      this.Enabled = original.Enabled;
    163134    }
     
    189160        expression = string.Format("Target:{0} in {1}{2} .. {3}{4}",
    190161          Variable,
    191           (InclusiveLowerBound) ? "[" : "]",
     162          "[",
    192163          Interval?.LowerBound,
    193164          Interval?.UpperBound,
    194           (InclusiveUpperBound) ? "]" : "[");
     165          "]");
    195166        Expression = expression;
    196167        return;
     
    199170        Variable,
    200171        Target,
    201         (InclusiveLowerBound) ? "[" : "]",
     172        "[",
    202173        Interval?.LowerBound,
    203174        Interval?.UpperBound,
    204         (InclusiveUpperBound) ? "]" : "[",
     175        "]",
    205176        GetDerivationString(numberOfDerivation));
    206177        Expression = expression;
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraintsParser.cs

    r17250 r17370  
    3333      if (string.IsNullOrEmpty(target)) throw new ArgumentNullException("No target variable has been provided.");
    3434      if (variables == null) throw new ArgumentNullException("No variables have been provided.");
    35       if (!variables.Any()) throw new ArgumentException("Varialbes are empty.");
     35      if (!variables.Any()) throw new ArgumentException("Variables are empty.");
    3636
    3737      var lines = inputText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
     
    4444          var targetConstraint = trimmedLine.Substring(start, end - start);
    4545          var match = Regex.Match(targetConstraint,
    46             @"(['](.*)[']|(.*[^\s]))\s*(\bin\b)\s*([\[\]])\s*(\S*)\s*(\.{2})\s*(\S*)\s*([\[\]])");
     46            @"(['](.*)[']|(.*[^\s]))\s*(\bin\b)\s*([\[])\s*(\S*)\s*(\.{2})\s*(\S*)\s*([\]])");
    4747          if (match.Success) {
    4848            if (match.Groups.Count != 10) {
     
    6363              var parsedTarget = match.Groups[1].Value.Trim();
    6464              var variable = targetVariable;
    65               var inclLowerBound = match.Groups[5].Value.Trim() == "[";
    66               var inclUpperBound = match.Groups[9].Value.Trim() == "]";
    6765              var isEnabled = true;
    6866              var numberOfDerivation = 0;
    6967              var interval = new Interval(lowerBound, upperBound);
    7068
    71               var constraint = new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, inclLowerBound, inclUpperBound, isEnabled);
     69              var constraint = new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, isEnabled);
    7270
    7371              yield return constraint;
     
    7977        } else if (trimmedLine.StartsWith("d") || trimmedLine.StartsWith("\u2202")) {
    8078          var match = Regex.Match(trimmedLine,
    81             @"([d∂])([²³]?)\s*(['](.*)[']|(.*[^\s]))\s*(\/)\s*([d∂])\s*(['](.*)[']|(.*[^\s²³]))\s*([²³]?)\s*\bin\b\s*([\[\]])\s*(\S*)\s*(\.{2})\s*(\S*)\s*([\[\]])");
     79            @"([d∂])([²³]?)\s*(['](.*)[']|(.*[^\s]))\s*(\/)\s*([d∂])\s*(['](.*)[']|(.*[^\s²³]))\s*([²³]?)\s*\bin\b\s*([\[])\s*(\S*)\s*(\.{2})\s*(\S*)\s*([\]])");
    8280
    8381          if (match.Success) {
     
    115113              var parsedTarget = derivationTarget;
    116114              var isEnabled = true;
    117               var inclLowerBound = match.Groups[12].Value.Trim() == "[";
    118               var inclUpperBound = match.Groups[16].Value.Trim() == "]";
    119115              var variable = derivationVariable;
    120116              var numberOfDerivation = ParseDerivationCount(match.Groups[2].Value.Trim());
    121117              var interval = new Interval(lowerBound, upperBound);
    122118
    123               var constraint = new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, inclLowerBound, inclUpperBound, isEnabled);
     119              var constraint = new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, isEnabled);
    124120
    125121              yield return constraint;
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/ProblemDataConstraint.cs

    r17256 r17370  
    3737                                                  "# Example for constraint on model parameter: " + Environment.NewLine +
    3838                                                  "d'y'/d'x' in [0 .. 10]" + Environment.NewLine +
    39                                                   "∂²'y'/∂'x'² in ]-1 .. inf.[";
     39                                                  "∂²'y'/∂'x'² in [-1 .. inf.]";
    4040
    4141    [Storable]
Note: See TracChangeset for help on using the changeset viewer.