Changeset 17728
- Timestamp:
- 08/27/20 10:45:57 (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
r17723 r17728 130 130 } 131 131 132 [Storable] 133 private double weight = 1.0; 134 public double Weight 135 { 136 get => weight; 137 set 138 { 139 if(weight != value) 140 { 141 weight = value; 142 UpdateExpression(); 143 OnChanged(); 144 } 145 } 146 } 147 132 148 [StorableConstructor] 133 149 private IntervalConstraint(StorableConstructorFlag _) : base(_) { } 134 150 135 151 public IntervalConstraint(string expression, string variable, string target, int numberOfDerivations, 136 Interval interval, boolenabled)152 Interval interval, double weight, bool enabled) 137 153 : this(expression, variable, target, numberOfDerivations, 138 interval, new Dictionary<string, Interval>(), enabled) { }154 interval, new Dictionary<string, Interval>(), weight, enabled) { } 139 155 140 156 public IntervalConstraint(string expression, string variable, string target, int numberOfDerivations, 141 Interval interval, IDictionary<string, Interval> regions, bool enabled)157 Interval interval, IDictionary<string, Interval> regions, double weight, bool enabled) 142 158 { 143 159 this.expression = expression; … … 147 163 this.interval = interval; 148 164 this.regions = regions; 165 this.weight = weight; 149 166 this.enabled = enabled; 150 167 } -
branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraintsParser.cs
r17723 r17728 46 46 var targetConstraint = trimmedLine.Substring(start, end - start); 47 47 48 var match = 48 var match = 49 49 Regex.Match(targetConstraint, 50 50 @"(['](.*)[']|(.*[^\s]))" + … … 62 62 @"(\S*)\s*" + // 15: region upper bound 63 63 @"([)])" + 64 @")*"); 64 @")*" + 65 @"\s*(<(\S*)>)?"); // 17, 18 66 65 67 66 68 if (match.Success) { 67 if (match.Groups.Count < 9) throw new ArgumentException("The target-constraint is not complete.", line);69 if (match.Groups.Count < 19) throw new ArgumentException("The target-constraint is not complete.", line); 68 70 69 71 var targetVariable = match.Groups[1].Value.Trim(); … … 84 86 var numberOfDerivation = 0; 85 87 var interval = new Interval(lowerBound, upperBound); 88 var weight = 1.0; 89 90 if (match.Groups[18].Success && !string.IsNullOrWhiteSpace(match.Groups[18].Value)) 91 weight = ParseWeight(match.Groups[18].Value); 86 92 87 93 if (match.Groups[10].Success) … … 96 102 pairs.Add(inputVar, new Interval(regionLb, regionUb)); 97 103 } 98 yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, pairs, isEnabled);104 yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, pairs, weight, isEnabled); 99 105 } 100 106 else 101 { 102 yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, isEnabled); 103 } 107 yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, weight, isEnabled); 104 108 } 105 else {109 else 106 110 throw new ArgumentException("The inserted target constraint is not valid.", line); 107 }108 111 109 112 //Check for derivation … … 130 133 @"(\S*)\s*" + // 22: region upper bound 131 134 @"([)])" + 132 @")*"); 135 @")*" + 136 @"\s*(<(\S*)>)?"); // 24, 25 133 137 134 138 if (match.Success) { 135 if (match.Groups.Count < 2 4)139 if (match.Groups.Count < 26) 136 140 throw new ArgumentException("The given derivation-constraint is not complete.", line); 137 141 … … 169 173 var numberOfDerivation = ParseDerivationCount(match.Groups[2].Value.Trim()); 170 174 var interval = new Interval(lowerBound, upperBound); 175 var weight = 1.0; 176 177 if(match.Groups[25].Success && !string.IsNullOrWhiteSpace(match.Groups[25].Value)) 178 weight = ParseWeight(match.Groups[25].Value); 171 179 172 180 if(match.Groups[17].Success) … … 181 189 pairs.Add(inputVar, new Interval(regionLb, regionUb)); 182 190 } 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 } 191 yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, pairs, weight, isEnabled); 192 } else 193 yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, weight, isEnabled); 187 194 } 188 else {195 else 189 196 throw new ArgumentException("The inserted derivation constraint is not valid.", line); 190 }191 197 192 198 //Check for comment … … 219 225 } 220 226 227 private static double ParseWeight(string input) 228 { 229 if (double.TryParse(input, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)) 230 return value; 231 throw new ArgumentException("The given weight is not a double value!"); 232 } 233 221 234 private static int ParseDerivationCount(string input) { 222 235 switch (input) {
Note: See TracChangeset
for help on using the changeset viewer.