Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/26/19 11:37:29 (6 years ago)
Author:
bburlacu
Message:

#2971: Make IntervalConstraintsParser class static, adapt code. Add SymbolicRegressionConstraintSatisfactionEvaluator.

File:
1 edited

Legend:

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

    r16632 r16713  
    55
    66namespace 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) {
    119      var options = RegexOptions.Multiline | RegexOptions.IgnoreCase;
    1210      var matches = Regex.Matches(input, @"^(.*)\bin\b\s*([\[\]])(.*[^\s])(\s*\.\.\s*)([^\s].*)([\[\]])\r?\s*$", options);
    1311
    1412      for (var i = 0; i < matches.Count; ++i) {
    15         if (matches[i].Groups.Count == 7) { 
     13        if (matches[i].Groups.Count == 7) {
    1614          var intervalConstraint = new IntervalConstraint();
    1715          //pattern 1 = defintion
     
    3836          intervalConstraint.InclusiveLowerBound = (matches[i].Groups[2].Value == "[");
    3937          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)),
    4139            ParseIntervalBounds(matches[i].Groups[5].Value.Replace(" ", string.Empty)));
    4240
    43           intervalConstraints.Add(intervalConstraint);
     41          yield return intervalConstraint;
    4442        } else {
    4543          throw new ArgumentException($"The given constraint: {matches[i].Value} is not valid.");
    4644        }
    4745      }
    48 
    49       return intervalConstraints;
    5046    }
    5147
     
    5955          return double.NegativeInfinity;
    6056        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            }
    6562          }
    66         }
    6763      }
    6864    }
Note: See TracChangeset for help on using the changeset viewer.