Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/16/21 15:26:50 (4 years ago)
Author:
gkronber
Message:

#3073 bugfixing

Location:
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalCollection.cs

    r17902 r17906  
    3535    }
    3636
    37     //[Storable]
    3837    private IDictionary<string, Interval> intervals { get; set; } = new Dictionary<string, Interval>();
    3938
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/ShapeConstraint.cs

    r17902 r17906  
    171171    private string GenerateExpressionString() {
    172172      string expression;
    173 
     173      string write(double val) => double.IsPositiveInfinity(val) ? "inf." : double.IsNegativeInfinity(val) ? "-inf." : $"{val}";
    174174      if (!IsDerivative) {
    175         expression = string.Format($"f in [{Interval?.LowerBound} .. {Interval?.UpperBound}]");
     175        expression = string.Format($"f in [{write(Interval.LowerBound)} .. {write(Interval.UpperBound)}]");
    176176        if (Regions != null) {
    177177          foreach (var region in Regions.GetReadonlyDictionary())
    178             expression += $", {region.Key} in [{region.Value.LowerBound} .. {region.Value.UpperBound}]";
     178            expression += $", {region.Key} in [{write(region.Value.LowerBound)} .. {write(region.Value.UpperBound)}]";
    179179        }
    180180        if (Weight != 1.0) {
     
    194194          derivationString = "³"; break;
    195195      }
    196       expression = string.Format($"∂{derivationString}f/∂{Variable}{derivationString} in [{Interval?.LowerBound} .. {Interval?.UpperBound}]");
     196      expression = string.Format($"∂{derivationString}f/∂{Variable}{derivationString} in [{write(Interval.LowerBound)} .. {write(Interval.UpperBound)}]");
    197197      if (Regions != null) {
    198198        foreach (var region in Regions.GetReadonlyDictionary())
    199           expression += $", {region.Key} in [{region.Value.LowerBound} .. {region.Value.UpperBound}]";
     199          expression += $", {region.Key} in [{write(region.Value.LowerBound)} .. {write(region.Value.UpperBound)}]";
    200200      }
    201201      if (Weight != 1.0) {
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/ShapeConstraintsParser.cs

    r17902 r17906  
    6161      } else {
    6262        throw new
    63           ArgumentException("Error at your constraints definition constraints have to start with (f | d | ∂ | #)",
     63          ArgumentException($"Error at in definition {expr}. Constraints have to start with (f | d | ∂ | #)",
    6464                            nameof(expr));
    6565      }
     
    6868    // [124 .. 145]
    6969    private const string intervalRegex = @"\s*[\[]" +
    70                                          @"\s*(?<lowerBound>[^\s\.;]*)" +
     70                                         @"\s*(?<lowerBound>[^\s;]*)" +
    7171                                         @"\s*(\.{2}|\s+|;)" +
    7272                                         @"\s*(?<upperBound>[^\s\]]*)" +
     
    7676    private const string weightRegex = @"\s*(weight:\s*(?<weight>\S*))?";
    7777    public static ShapeConstraint ParseFunctionRangeConstraint(string expr) {
    78       if (!expr.StartsWith("f")) throw new ArgumentException("Invalid function range constraint (e.g. f in [1..2])", nameof(expr));
     78      if (!expr.StartsWith("f")) throw new ArgumentException($"Invalid function range constraint {expr} (e.g. f in [1..2])", nameof(expr));
    7979      var start = "f".Length;
    8080      var end = expr.Length;
     
    9595                    intervalRegex +
    9696                    @"(" +
    97                       @"\s*,\s*"+ variableRegex +
     97                      @"\s*,\s*" + variableRegex +
    9898                      @"\s *\bin\b" +
    9999                      intervalRegex +
    100100                    @")*" +
    101101                    weightRegex
    102                     ); 
     102                    );
    103103
    104104
     
    125125              regions.AddInterval(region.Key, region.Value);
    126126            else
    127               throw new ArgumentException("A constraint cannot contain multiple regions of the same variable.");
     127              throw new ArgumentException($"The constraint {expr} has multiple regions of the same variable.");
    128128          }
    129129          return new ShapeConstraint(interval, regions, weight);
     
    131131          return new ShapeConstraint(interval, weight);
    132132      } else
    133         throw new ArgumentException("The inserted target constraint is not valid.", nameof(expr));
     133        throw new ArgumentException($"The inserted target constraint {expr} is not valid.", nameof(expr));
    134134    }
    135135    public static ShapeConstraint ParseDerivationConstraint(string expr) {
     
    149149                                  @")*" +
    150150                                weightRegex
    151                                 ); 
     151                                );
    152152
    153153      if (match.Success) {
     
    161161        if (enumeratorNumDeriv != "" || denominatorNumDeriv != "") {
    162162          if (enumeratorNumDeriv == "" || denominatorNumDeriv == "")
    163             throw new ArgumentException("Number of derivation has to be written on both sides.", nameof(expr));
     163            throw new ArgumentException($"Number of derivation has to be written on both sides in {expr}.", nameof(expr));
    164164          if (enumeratorNumDeriv != denominatorNumDeriv)
    165             throw new ArgumentException("Derivation number is not equal on both sides.", nameof(expr));
     165            throw new ArgumentException($"Derivation number is not equal on both sides in {expr}.", nameof(expr));
    166166        }
    167167
     
    187187              regions.AddInterval(region.Key, region.Value);
    188188            else
    189               throw new ArgumentException("A constraint cannot contain multiple regions of the same variable.");
     189              throw new ArgumentException($"The constraint {expr} has multiple regions of the same variable.");
    190190          }
    191191          return new ShapeConstraint(variable, numberOfDerivation, interval, regions, weight);
     
    193193          return new ShapeConstraint(variable, numberOfDerivation, interval, weight);
    194194      } else
    195         throw new ArgumentException("The inserted derivation constraint is not valid.", nameof(expr));
     195        throw new ArgumentException($"The inserted derivation constraint {expr} is not valid.", nameof(expr));
    196196    }
    197197
     
    220220      var valid = double.TryParse(input, out var value);
    221221      if (!valid) {
    222         throw new ArgumentException("Invalid value (valid value format: \"" + FormatPatterns.GetDoubleFormatPattern() + "\")");
     222        throw new ArgumentException($"Invalid value {input} (valid value format: \"" + "+inf. | inf. | -inf. | " + FormatPatterns.GetDoubleFormatPattern() + "\")");
    223223      }
    224224
Note: See TracChangeset for help on using the changeset viewer.