Changeset 16713 for branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation
- Timestamp:
- 03/26/19 11:37:29 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Parser/IntervalConstraintsParser.cs
r16632 r16713 5 5 6 6 namespace HeuristicLab.Problems.DataAnalysis { 7 public class IntervalConstraintsParser { 8 public IntervalConstraintsParser() {} 9 private List<IntervalConstraint> intervalConstraints = new List<IntervalConstraint>(); 10 public List<IntervalConstraint> Parse(string input) { 7 public static class IntervalConstraintsParser { 8 public static IEnumerable<IntervalConstraint> Parse(string input) { 11 9 var options = RegexOptions.Multiline | RegexOptions.IgnoreCase; 12 10 var matches = Regex.Matches(input, @"^(.*)\bin\b\s*([\[\]])(.*[^\s])(\s*\.\.\s*)([^\s].*)([\[\]])\r?\s*$", options); 13 11 14 12 for (var i = 0; i < matches.Count; ++i) { 15 if (matches[i].Groups.Count == 7) { 13 if (matches[i].Groups.Count == 7) { 16 14 var intervalConstraint = new IntervalConstraint(); 17 15 //pattern 1 = defintion … … 38 36 intervalConstraint.InclusiveLowerBound = (matches[i].Groups[2].Value == "["); 39 37 intervalConstraint.InclusiveUpperBound = (matches[i].Groups[6].Value == "]"); 40 intervalConstraint.Interval = new Interval(ParseIntervalBounds(matches[i].Groups[3].Value.Replace(" ", string.Empty)), 38 intervalConstraint.Interval = new Interval(ParseIntervalBounds(matches[i].Groups[3].Value.Replace(" ", string.Empty)), 41 39 ParseIntervalBounds(matches[i].Groups[5].Value.Replace(" ", string.Empty))); 42 40 43 intervalConstraints.Add(intervalConstraint);41 yield return intervalConstraint; 44 42 } else { 45 43 throw new ArgumentException($"The given constraint: {matches[i].Value} is not valid."); 46 44 } 47 45 } 48 49 return intervalConstraints;50 46 } 51 47 … … 59 55 return double.NegativeInfinity; 60 56 default: { 61 if (double.TryParse(input, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)) { 62 return value; 63 } else { 64 throw new ArgumentException("The given Interval in the constraint is not valid."); 57 if (double.TryParse(input, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)) { 58 return value; 59 } else { 60 throw new ArgumentException("The given Interval in the constraint is not valid."); 61 } 65 62 } 66 }67 63 } 68 64 }
Note: See TracChangeset
for help on using the changeset viewer.