Changeset 17906 for trunk/HeuristicLab.Problems.DataAnalysis
- Timestamp:
- 03/16/21 15:26:50 (4 years ago)
- 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 35 35 } 36 36 37 //[Storable]38 37 private IDictionary<string, Interval> intervals { get; set; } = new Dictionary<string, Interval>(); 39 38 -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/ShapeConstraint.cs
r17902 r17906 171 171 private string GenerateExpressionString() { 172 172 string expression; 173 173 string write(double val) => double.IsPositiveInfinity(val) ? "inf." : double.IsNegativeInfinity(val) ? "-inf." : $"{val}"; 174 174 if (!IsDerivative) { 175 expression = string.Format($"f in [{ Interval?.LowerBound} .. {Interval?.UpperBound}]");175 expression = string.Format($"f in [{write(Interval.LowerBound)} .. {write(Interval.UpperBound)}]"); 176 176 if (Regions != null) { 177 177 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)}]"; 179 179 } 180 180 if (Weight != 1.0) { … … 194 194 derivationString = "³"; break; 195 195 } 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)}]"); 197 197 if (Regions != null) { 198 198 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)}]"; 200 200 } 201 201 if (Weight != 1.0) { -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/ShapeConstraintsParser.cs
r17902 r17906 61 61 } else { 62 62 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 | ∂ | #)", 64 64 nameof(expr)); 65 65 } … … 68 68 // [124 .. 145] 69 69 private const string intervalRegex = @"\s*[\[]" + 70 @"\s*(?<lowerBound>[^\s \.;]*)" +70 @"\s*(?<lowerBound>[^\s;]*)" + 71 71 @"\s*(\.{2}|\s+|;)" + 72 72 @"\s*(?<upperBound>[^\s\]]*)" + … … 76 76 private const string weightRegex = @"\s*(weight:\s*(?<weight>\S*))?"; 77 77 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)); 79 79 var start = "f".Length; 80 80 var end = expr.Length; … … 95 95 intervalRegex + 96 96 @"(" + 97 @"\s*,\s*" + variableRegex +97 @"\s*,\s*" + variableRegex + 98 98 @"\s *\bin\b" + 99 99 intervalRegex + 100 100 @")*" + 101 101 weightRegex 102 ); 102 ); 103 103 104 104 … … 125 125 regions.AddInterval(region.Key, region.Value); 126 126 else 127 throw new ArgumentException( "A constraint cannot containmultiple regions of the same variable.");127 throw new ArgumentException($"The constraint {expr} has multiple regions of the same variable."); 128 128 } 129 129 return new ShapeConstraint(interval, regions, weight); … … 131 131 return new ShapeConstraint(interval, weight); 132 132 } else 133 throw new ArgumentException( "The inserted target constraintis not valid.", nameof(expr));133 throw new ArgumentException($"The inserted target constraint {expr} is not valid.", nameof(expr)); 134 134 } 135 135 public static ShapeConstraint ParseDerivationConstraint(string expr) { … … 149 149 @")*" + 150 150 weightRegex 151 ); 151 ); 152 152 153 153 if (match.Success) { … … 161 161 if (enumeratorNumDeriv != "" || denominatorNumDeriv != "") { 162 162 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)); 164 164 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)); 166 166 } 167 167 … … 187 187 regions.AddInterval(region.Key, region.Value); 188 188 else 189 throw new ArgumentException( "A constraint cannot containmultiple regions of the same variable.");189 throw new ArgumentException($"The constraint {expr} has multiple regions of the same variable."); 190 190 } 191 191 return new ShapeConstraint(variable, numberOfDerivation, interval, regions, weight); … … 193 193 return new ShapeConstraint(variable, numberOfDerivation, interval, weight); 194 194 } else 195 throw new ArgumentException( "The inserted derivation constraintis not valid.", nameof(expr));195 throw new ArgumentException($"The inserted derivation constraint {expr} is not valid.", nameof(expr)); 196 196 } 197 197 … … 220 220 var valid = double.TryParse(input, out var value); 221 221 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() + "\")"); 223 223 } 224 224
Note: See TracChangeset
for help on using the changeset viewer.