Changeset 17765 for branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraintsParser.cs
- Timestamp:
- 09/29/20 10:16:11 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraintsParser.cs
r17736 r17765 93 93 if (match.Groups[10].Success) 94 94 { 95 I Dictionary<string, Interval> pairs = new Dictionary<string, Interval>();95 IList<Region> regions = new List<Region>(); 96 96 // option variables found 97 97 for(int idx = 0; idx < match.Groups[10].Captures.Count; ++idx) 98 98 { 99 AddRegion(pairs,99 Region region = ParseRegion( 100 100 match.Groups[11].Captures[idx].Value, 101 101 match.Groups[13].Captures[idx].Value, 102 102 match.Groups[15].Captures[idx].Value); 103 if(!regions.Any(r => r.VariableName == region.VariableName)) 104 regions.Add(region); 105 else 106 throw new ArgumentException("A constraint cannot contain multiple regions of the same variable."); 103 107 } 104 yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, pairs, weight, isEnabled);108 yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, regions, weight, isEnabled); 105 109 } 106 110 else … … 180 184 if(match.Groups[17].Success) 181 185 { 182 I Dictionary<string, Interval> pairs = new Dictionary<string, Interval>();186 IList<Region> regions = new List<Region>(); 183 187 // option variables found 184 188 for (int idx = 0; idx < match.Groups[17].Captures.Count; ++idx) 185 189 { 186 AddRegion(pairs,187 match.Groups[18].Captures[idx].Value, 188 match.Groups[20].Captures[idx].Value, 190 Region region = ParseRegion( 191 match.Groups[18].Captures[idx].Value, 192 match.Groups[20].Captures[idx].Value, 189 193 match.Groups[22].Captures[idx].Value); 194 if (!regions.Any(r => r.VariableName == region.VariableName)) 195 regions.Add(region); 196 else 197 throw new ArgumentException("A constraint cannot contain multiple regions of the same variable."); 190 198 } 191 yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, pairs, weight, isEnabled);199 yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, regions, weight, isEnabled); 192 200 } else 193 201 yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, weight, isEnabled); … … 209 217 } 210 218 211 private static void AddRegion(IDictionary<string, Interval> dict,string variable, string lb, string ub)219 private static Region ParseRegion(string variable, string lb, string ub) 212 220 { 213 221 var regionLb = ParseIntervalBounds(lb); 214 222 var regionUb = ParseIntervalBounds(ub); 215 if (dict.ContainsKey(variable)) 216 throw new ArgumentException("A constraint cannot contain multiple regions of the same variable."); 217 dict.Add(variable, new Interval(regionLb, regionUb)); 223 return new Region(variable, new Interval(regionLb, regionUb)); 218 224 } 219 225
Note: See TracChangeset
for help on using the changeset viewer.