Changeset 17891 for branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/ShapeConstraintsParser.cs
- Timestamp:
- 03/12/21 16:41:42 (3 years ago)
- 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 1 1 bin 2 TestResults
-
- Property svn:ignore
-
branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/ShapeConstraintsParser.cs
r17887 r17891 30 30 namespace HeuristicLab.Problems.DataAnalysis { 31 31 public static class ShapeConstraintsParser { 32 public static IEnumerable<ShapeConstraint> ParseConstraints(string text, IEnumerable<string> variables) {32 public static ShapeConstraints ParseConstraints(string text) { 33 33 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));36 34 37 35 var lines = text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); 38 36 37 var sc = new ShapeConstraints(); 39 38 foreach (var line in lines) { 40 39 var trimmedLine = line.Trim(); 41 if (trimmedLine == "") continue; //If it is a comment just continue without saving anything40 if (trimmedLine == "") continue; // If it is a comment just continue without saving anything 42 41 if (trimmedLine.StartsWith("#")) { 43 42 // 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); 47 46 } else { 48 yield return ParseConstaint(trimmedLine, variables); 47 var constraint = ParseConstaint(trimmedLine); 48 sc.Add(constraint); 49 sc.SetItemCheckedState(constraint, true); 49 50 } 50 51 } 51 } 52 53 public static ShapeConstraint ParseConstaint(string expr, IEnumerable<string> variables) { 52 return sc; 53 } 54 55 public static ShapeConstraint ParseConstaint(string expr) { 54 56 var trimmedLine = expr.TrimStart(); 55 57 if (trimmedLine.StartsWith("f")) { 56 58 return ParseFunctionRangeConstraint(expr); 57 59 } else if (trimmedLine.StartsWith("d") || trimmedLine.StartsWith("∂")) { 58 return ParseDerivationConstraint(expr , variables);60 return ParseDerivationConstraint(expr); 59 61 } else { 60 62 throw new … … 125 127 throw new ArgumentException("A constraint cannot contain multiple regions of the same variable."); 126 128 } 127 return new ShapeConstraint(interval, regions, weight , enabled: true);129 return new ShapeConstraint(interval, regions, weight); 128 130 } else 129 return new ShapeConstraint(interval, weight , enabled: true);131 return new ShapeConstraint(interval, weight); 130 132 } else 131 133 throw new ArgumentException("The inserted target constraint is not valid.", nameof(expr)); 132 134 } 133 public static ShapeConstraint ParseDerivationConstraint(string expr , IEnumerable<string> variables) {135 public static ShapeConstraint ParseDerivationConstraint(string expr) { 134 136 var match = Regex.Match(expr, 135 137 @"([d∂])" + … … 155 157 var derivationVariable = match.Groups["varName"].Captures[0].Value.Trim(); 156 158 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 161 159 var enumeratorNumDeriv = match.Groups["numDerivations"].Captures[0].Value.Trim(); 162 160 var denominatorNumDeriv = match.Groups["numDerivations"].Captures[1].Value.Trim(); … … 191 189 throw new ArgumentException("A constraint cannot contain multiple regions of the same variable."); 192 190 } 193 return new ShapeConstraint(variable, numberOfDerivation, interval, regions, weight , enabled: true);191 return new ShapeConstraint(variable, numberOfDerivation, interval, regions, weight); 194 192 } else 195 return new ShapeConstraint(variable, numberOfDerivation, interval, weight , enabled: true);193 return new ShapeConstraint(variable, numberOfDerivation, interval, weight); 196 194 } else 197 195 throw new ArgumentException("The inserted derivation constraint is not valid.", nameof(expr));
Note: See TracChangeset
for help on using the changeset viewer.