Changeset 17723
- Timestamp:
- 08/11/20 14:22:45 (4 years ago)
- Location:
- branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraint.cs
r17607 r17723 22 22 #endregion 23 23 using System; 24 using System.Collections.Generic; 24 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; … … 113 114 } 114 115 116 [Storable] 117 private IDictionary<string, Interval> regions = new Dictionary<string, Interval>(); 118 public IDictionary<string, Interval> Regions 119 { 120 get => regions; 121 set 122 { 123 if (regions != value) 124 { 125 regions = value; 126 UpdateExpression(); 127 OnChanged(); 128 } 129 } 130 } 131 115 132 [StorableConstructor] 116 133 private IntervalConstraint(StorableConstructorFlag _) : base(_) { } 117 134 118 135 public IntervalConstraint(string expression, string variable, string target, int numberOfDerivations, 119 Interval interval, bool enabled) { 120 this.expression = expression; 121 this.variable = variable; 122 this.target = target; 136 Interval interval, bool enabled) 137 : this(expression, variable, target, numberOfDerivations, 138 interval, new Dictionary<string, Interval>(), enabled) { } 139 140 public IntervalConstraint(string expression, string variable, string target, int numberOfDerivations, 141 Interval interval, IDictionary<string, Interval> regions, bool enabled) 142 { 143 this.expression = expression; 144 this.variable = variable; 145 this.target = target; 123 146 this.numberOfDerivations = numberOfDerivations; 124 this.interval = interval; 125 this.enabled = enabled; 147 this.interval = interval; 148 this.regions = regions; 149 this.enabled = enabled; 126 150 } 127 151 … … 137 161 NumberOfDerivations = original.NumberOfDerivations; 138 162 Interval = original.Interval; 163 Regions = original.Regions; 139 164 Enabled = original.Enabled; 140 165 } … … 171 196 Interval?.UpperBound, 172 197 "]"); 198 foreach(var kvp in Regions) 199 expression += $", {kvp.Key}=({kvp.Value.LowerBound} .. {kvp.Value.UpperBound})"; 173 200 Expression = expression; 174 201 return; … … 183 210 "]", 184 211 GetDerivationString(numberOfDerivations)); 212 foreach (var kvp in Regions) 213 expression += $", {kvp.Key}=({kvp.Value.LowerBound} .. {kvp.Value.UpperBound})"; 185 214 Expression = expression; 186 215 } -
branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraintsParser.cs
r17607 r17723 45 45 var end = trimmedLine.Length; 46 46 var targetConstraint = trimmedLine.Substring(start, end - start); 47 var match = Regex.Match(targetConstraint, 48 @"(['](.*)[']|(.*[^\s]))\s*(\bin\b)\s*([\[])\s*(\S*)\s*(\.{2})\s*(\S*)\s*([\]])"); 47 48 var match = 49 Regex.Match(targetConstraint, 50 @"(['](.*)[']|(.*[^\s]))" + 51 @"\s*(\bin\b)" + 52 @"\s*([\[])" + 53 @"\s*(\S*)" + // 6: interval lower bound 54 @"\s*(\.{2})" + 55 @"\s*(\S*)" + // 8: interval upper bound 56 @"\s*([\]])" + 57 @"(" + 58 @"\s*,\s*(\S*)\s*=\s*" + // 11: variable name 59 @"([(])\s*" + 60 @"(\S*)\s*" + // 13: region lower bound 61 @"(\.{2})\s*" + 62 @"(\S*)\s*" + // 15: region upper bound 63 @"([)])" + 64 @")*"); 65 49 66 if (match.Success) { 50 if (match.Groups.Count != 10) throw new ArgumentException("The target-constraint is not complete.", line);67 if (match.Groups.Count < 9) throw new ArgumentException("The target-constraint is not complete.", line); 51 68 52 69 var targetVariable = match.Groups[1].Value.Trim(); 53 if ( match.Groups[1].Value.Trim().StartsWith("'") && match.Groups[1].Value.Trim().EndsWith("'"))70 if (targetVariable.StartsWith("'") && targetVariable.EndsWith("'")) 54 71 targetVariable = targetVariable.Substring(1, targetVariable.Length - 2); 55 72 … … 68 85 var interval = new Interval(lowerBound, upperBound); 69 86 70 var constraint = 71 new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, isEnabled); 72 73 yield return constraint; 87 if (match.Groups[10].Success) 88 { 89 IDictionary<string, Interval> pairs = new Dictionary<string, Interval>(); 90 // option variables found 91 for(int idx = 0; idx < match.Groups[10].Captures.Count; ++idx) 92 { 93 var inputVar = match.Groups[11].Captures[idx].Value; 94 var regionLb = ParseIntervalBounds(match.Groups[13].Captures[idx].Value); 95 var regionUb = ParseIntervalBounds(match.Groups[15].Captures[idx].Value); 96 pairs.Add(inputVar, new Interval(regionLb, regionUb)); 97 } 98 yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, pairs, isEnabled); 99 } 100 else 101 { 102 yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, isEnabled); 103 } 74 104 } 75 105 else { … … 80 110 } 81 111 else if (trimmedLine.StartsWith("d") || trimmedLine.StartsWith("\u2202")) { 82 var match = Regex.Match(trimmedLine, 83 @"([d∂])([²³]?)\s*(['](.*)[']|(.*[^\s]))\s*(\/)\s*([d∂])\s*(['](.*)[']|(.*[^\s²³]))\s*([²³]?)\s*\bin\b\s*([\[])\s*(\S*)\s*(\.{2})\s*(\S*)\s*([\]])"); 112 var match = Regex.Match(trimmedLine, 113 @"([d∂])" + 114 @"([²³]?)\s*" + 115 @"(['](.*)[']|(.*[^\s]))\s*" + 116 @"(\/)\s*" + 117 @"([d∂])\s*" + 118 @"(['](.*)[']|(.*[^\s²³]))\s*" + 119 @"([²³]?)\s*\bin\b\s*" + 120 @"([\[])\s*" + 121 @"(\S*)\s*" + 122 @"(\.{2})\s*" + 123 @"(\S*)\s*" + 124 @"([\]])" + 125 @"(" + 126 @"\s*,\s*(\S*)\s*=\s*" + // 18: variable name 127 @"([(])\s*" + 128 @"(\S*)\s*" + // 20: region lower bound 129 @"(\.{2})\s*" + 130 @"(\S*)\s*" + // 22: region upper bound 131 @"([)])" + 132 @")*"); 84 133 85 134 if (match.Success) { 86 if (match.Groups.Count != 17)135 if (match.Groups.Count < 24) 87 136 throw new ArgumentException("The given derivation-constraint is not complete.", line); 88 137 … … 121 170 var interval = new Interval(lowerBound, upperBound); 122 171 123 var constraint = 124 new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, isEnabled); 125 126 yield return constraint; 172 if(match.Groups[17].Success) 173 { 174 IDictionary<string, Interval> pairs = new Dictionary<string, Interval>(); 175 // option variables found 176 for (int idx = 0; idx < match.Groups[17].Captures.Count; ++idx) 177 { 178 var inputVar = match.Groups[18].Captures[idx].Value; 179 var regionLb = ParseIntervalBounds(match.Groups[20].Captures[idx].Value); 180 var regionUb = ParseIntervalBounds(match.Groups[22].Captures[idx].Value); 181 pairs.Add(inputVar, new Interval(regionLb, regionUb)); 182 } 183 yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, pairs, isEnabled); 184 } else { 185 yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, isEnabled); 186 } 127 187 } 128 188 else {
Note: See TracChangeset
for help on using the changeset viewer.