Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/21 16:41:42 (3 years ago)
Author:
gkronber
Message:

#3073 refactoring to prepare for trunk reintegration

Location:
branches/3073_IA_constraint_splitting_reintegration
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3073_IA_constraint_splitting_reintegration

    • Property svn:ignore
      •  

        old new  
        11bin
         2TestResults
  • branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/ShapeConstraintsParser.cs

    r17887 r17891  
    3030namespace HeuristicLab.Problems.DataAnalysis {
    3131  public static class ShapeConstraintsParser {
    32     public static IEnumerable<ShapeConstraint> ParseConstraints(string text, IEnumerable<string> variables) {
     32    public static ShapeConstraints ParseConstraints(string text) {
    3333      if (string.IsNullOrEmpty(text)) throw new ArgumentNullException(nameof(text));
    34       if (variables == null) throw new ArgumentNullException(nameof(variables));
    35       if (!variables.Any()) throw new ArgumentException("Variables are empty.", nameof(variables));
    3634
    3735      var lines = text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
    3836
     37      var sc = new ShapeConstraints();
    3938      foreach (var line in lines) {
    4039        var trimmedLine = line.Trim();
    41         if (trimmedLine == "") continue;         //If it is a comment just continue without saving anything
     40        if (trimmedLine == "") continue; // If it is a comment just continue without saving anything
    4241        if (trimmedLine.StartsWith("#")) {
    4342          // disabled constraints are commented
    44           var constraint = ParseConstaint(trimmedLine.TrimStart('#', ' '), variables);
    45           constraint.Enabled = false;
    46           yield return constraint;
     43          var constraint = ParseConstaint(trimmedLine.TrimStart('#', ' '));
     44          sc.Add(constraint);
     45          sc.SetItemCheckedState(constraint, false);
    4746        } else {
    48           yield return ParseConstaint(trimmedLine, variables);
     47          var constraint = ParseConstaint(trimmedLine);
     48          sc.Add(constraint);
     49          sc.SetItemCheckedState(constraint, true);
    4950        }
    5051      }
    51     }
    52 
    53     public static ShapeConstraint ParseConstaint(string expr, IEnumerable<string> variables) {
     52      return sc;
     53    }
     54
     55    public static ShapeConstraint ParseConstaint(string expr) {
    5456      var trimmedLine = expr.TrimStart();
    5557      if (trimmedLine.StartsWith("f")) {
    5658        return ParseFunctionRangeConstraint(expr);
    5759      } else if (trimmedLine.StartsWith("d") || trimmedLine.StartsWith("∂")) {
    58         return ParseDerivationConstraint(expr, variables);
     60        return ParseDerivationConstraint(expr);
    5961      } else {
    6062        throw new
     
    125127              throw new ArgumentException("A constraint cannot contain multiple regions of the same variable.");
    126128          }
    127           return new ShapeConstraint(interval, regions, weight, enabled: true);
     129          return new ShapeConstraint(interval, regions, weight);
    128130        } else
    129           return new ShapeConstraint(interval, weight, enabled: true);
     131          return new ShapeConstraint(interval, weight);
    130132      } else
    131133        throw new ArgumentException("The inserted target constraint is not valid.", nameof(expr));
    132134    }
    133     public static ShapeConstraint ParseDerivationConstraint(string expr, IEnumerable<string> variables) {
     135    public static ShapeConstraint ParseDerivationConstraint(string expr) {
    134136      var match = Regex.Match(expr,
    135137                                @"([d∂])" +
     
    155157        var derivationVariable = match.Groups["varName"].Captures[0].Value.Trim();
    156158
    157         if (variables.All(v => v != derivationVariable))
    158           throw new ArgumentException($"The given variable {derivationVariable} does not exist in the dataset.",
    159                                       nameof(expr));
    160 
    161159        var enumeratorNumDeriv = match.Groups["numDerivations"].Captures[0].Value.Trim();
    162160        var denominatorNumDeriv = match.Groups["numDerivations"].Captures[1].Value.Trim();
     
    191189              throw new ArgumentException("A constraint cannot contain multiple regions of the same variable.");
    192190          }
    193           return new ShapeConstraint(variable, numberOfDerivation, interval, regions, weight, enabled: true);
     191          return new ShapeConstraint(variable, numberOfDerivation, interval, regions, weight);
    194192        } else
    195           return new ShapeConstraint(variable, numberOfDerivation, interval, weight, enabled: true);
     193          return new ShapeConstraint(variable, numberOfDerivation, interval, weight);
    196194      } else
    197195        throw new ArgumentException("The inserted derivation constraint is not valid.", nameof(expr));
Note: See TracChangeset for help on using the changeset viewer.