Changeset 17995 for branches/3119_AdditionalShapeConstraintFeatures/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/ShapeConstraintsParser.cs
- Timestamp:
- 06/22/21 18:28:36 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3119_AdditionalShapeConstraintFeatures/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/ShapeConstraintsParser.cs
r17946 r17995 76 76 private const string weightRegex = @"\s*(weight:\s*(?<weight>\S*))?"; 77 77 private const string thresholdRegex = @"\s*(threshold\s*in\s*(?<threshold> "+ intervalRegex + @"))?"; 78 private const string dynIntervalStartRegex = @"\s*(start\s*in\s*(?<dynInterval> " + intervalRegex + @"))?"; 78 79 public static ShapeConstraint ParseFunctionRangeConstraint(string expr) { 79 80 if (!expr.StartsWith("f")) throw new ArgumentException($"Invalid function range constraint {expr} (e.g. f in [1..2])"); … … 90 91 // df/d'x' in [0 .. 10] weight: 2.0 91 92 // df / d'x' in [0..10], 'x' in [1 .. 3] 92 // df / d'x' in [0..10], 'x' in [1 .. 3], yin [10..30] weight: 1.293 // df / d'x' in [0..10], 'x' in [1 .. 3], yin [10..30] weight: 1.2 threshold in [-10 .. 10]93 // df / d'x' in [0..10], 'x' in [1 .. 3], 'y' in [10..30] weight: 1.2 94 // df / d'x' in [0..10], 'x' in [1 .. 3], 'y' in [10..30] weight: 1.2 threshold in [-10 .. 10] 94 95 var match = Regex.Match(targetConstraint, 95 96 @"\s*\bin\b" + … … 101 102 @")*" + 102 103 weightRegex + 103 thresholdRegex 104 thresholdRegex + 105 dynIntervalStartRegex 104 106 ); 105 107 … … 112 114 var interval = new Interval(lowerBound, upperBound); 113 115 var weight = 1.0; 114 var threshold = new Interval(double.NegativeInfinity, double.PositiveInfinity); 116 var threshold = new Interval(0, 0); 117 Interval dynInterval = new Interval(double.NegativeInfinity, double.PositiveInfinity); 118 int intervalIdx = 1; 119 var lowerboundCount = match.Groups["lowerBound"].Captures.Count; 120 var upperboundCount = match.Groups["upperBound"].Captures.Count; 115 121 116 122 if (match.Groups["weight"].Success && !string.IsNullOrWhiteSpace(match.Groups["weight"].Value)) 117 123 weight = ParseAndValidateDouble(match.Groups["weight"].Value); 118 124 119 if(match.Groups["threshold"].Success) { 120 var lowerboundCount = match.Groups["lowerBound"].Captures.Count; 121 var upperboundCount = match.Groups["upperBound"].Captures.Count; 122 var thresholdLb = ParseIntervalBounds(match.Groups["lowerBound"].Captures[lowerboundCount - 1].Value); 123 var thresholdUb = ParseIntervalBounds(match.Groups["upperBound"].Captures[upperboundCount - 1].Value); 125 if (match.Groups["dynInterval"].Success) { 126 var dynIntervalLb = ParseIntervalBounds(match.Groups["lowerBound"].Captures[lowerboundCount - intervalIdx].Value); 127 var dynIntervalUb = ParseIntervalBounds(match.Groups["upperBound"].Captures[upperboundCount - intervalIdx].Value); 128 intervalIdx++; 129 dynInterval = new Interval(dynIntervalLb, dynIntervalUb); 130 } 131 132 if (match.Groups["threshold"].Success) { 133 var thresholdLb = ParseIntervalBounds(match.Groups["lowerBound"].Captures[lowerboundCount - intervalIdx].Value); 134 var thresholdUb = ParseIntervalBounds(match.Groups["upperBound"].Captures[upperboundCount - intervalIdx].Value); 135 intervalIdx++; 124 136 threshold = new Interval(thresholdLb, thresholdUb); 125 137 } 138 126 139 127 140 if (match.Groups["varName"].Success) { … … 138 151 throw new ArgumentException($"The constraint {expr} has multiple regions of the same variable."); 139 152 } 140 return new ShapeConstraint(interval, regions, weight, threshold );153 return new ShapeConstraint(interval, regions, weight, threshold, dynInterval); 141 154 } else 142 return new ShapeConstraint(interval, weight, threshold );155 return new ShapeConstraint(interval, weight, threshold, dynInterval); 143 156 } else 144 157 throw new ArgumentException($"The target constraint {expr} is not valid."); … … 160 173 @")*" + 161 174 weightRegex + 162 thresholdRegex 175 thresholdRegex + 176 dynIntervalStartRegex 163 177 ); 164 178 … … 184 198 var interval = new Interval(lowerBound, upperBound); 185 199 var weight = 1.0; 186 var threshold = new Interval(double.NegativeInfinity, double.PositiveInfinity); 200 var threshold = new Interval(0, 0); 201 Interval dynInterval = new Interval(double.NegativeInfinity, double.PositiveInfinity); 202 int intervalIdx = 1; 203 var lowerboundCount = match.Groups["lowerBound"].Captures.Count; 204 var upperboundCount = match.Groups["upperBound"].Captures.Count; 187 205 188 206 if (match.Groups["weight"].Success && !string.IsNullOrWhiteSpace(match.Groups["weight"].Value)) 189 207 weight = ParseAndValidateDouble(match.Groups["weight"].Value); 190 208 209 if (match.Groups["dynInterval"].Success) { 210 var dynIntervalLb = ParseIntervalBounds(match.Groups["lowerBound"].Captures[lowerboundCount - intervalIdx].Value); 211 var dynIntervalUb = ParseIntervalBounds(match.Groups["upperBound"].Captures[upperboundCount - intervalIdx].Value); 212 intervalIdx++; 213 dynInterval = new Interval(dynIntervalLb, dynIntervalUb); 214 } 215 191 216 if (match.Groups["threshold"].Success) { 192 var lowerboundCount = match.Groups["lowerBound"].Captures.Count; 193 var upperboundCount = match.Groups["upperBound"].Captures.Count; 194 var thresholdLb = ParseIntervalBounds(match.Groups["lowerBound"].Captures[lowerboundCount - 1].Value); 195 var thresholdUb = ParseIntervalBounds(match.Groups["upperBound"].Captures[upperboundCount - 1].Value); 217 var thresholdLb = ParseIntervalBounds(match.Groups["lowerBound"].Captures[lowerboundCount - intervalIdx].Value); 218 var thresholdUb = ParseIntervalBounds(match.Groups["upperBound"].Captures[upperboundCount - intervalIdx].Value); 219 intervalIdx++; 196 220 threshold = new Interval(thresholdLb, thresholdUb); 197 221 } … … 210 234 throw new ArgumentException($"The constraint {expr} has multiple regions of the same variable."); 211 235 } 212 return new ShapeConstraint(variable, numberOfDerivation, interval, regions, weight, threshold );236 return new ShapeConstraint(variable, numberOfDerivation, interval, regions, weight, threshold, dynInterval); 213 237 } else 214 return new ShapeConstraint(variable, numberOfDerivation, interval, weight, threshold );238 return new ShapeConstraint(variable, numberOfDerivation, interval, weight, threshold, dynInterval); 215 239 } else 216 240 throw new ArgumentException($"The derivation constraint {expr} is not valid.");
Note: See TracChangeset
for help on using the changeset viewer.