Changeset 17760 for branches/3073_IA_constraint_splitting
- Timestamp:
- 09/24/20 16:14:08 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
r17758 r17760 160 160 Interval outputInterval; 161 161 if (UseIntervalSplitting) { 162 var variables = tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(x => x.VariableName).Distinct()163 .ToList();164 var containsDependencyProblem = ContainsVariableMultipleTimes(tree );162 //var variables = tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(x => x.VariableName).Distinct() 163 // .ToList(); 164 var containsDependencyProblem = ContainsVariableMultipleTimes(tree, out var variables); 165 165 166 166 if (containsDependencyProblem) { … … 171 171 //outputInterval = EvaluateRecursive(instructions, intervals, writeableVariableRanges, variables, MinSplittingWidth, MaxSplittingDepth, 172 172 // ref currIndex, ref currDepth, tree); 173 outputInterval = EvaluateWithSplitting(instructions, intervals, writeableVariableRanges );173 outputInterval = EvaluateWithSplitting(instructions, intervals, writeableVariableRanges, variables); 174 174 } else { 175 175 var instructionCount = 0; … … 221 221 public static Interval EvaluateWithSplitting(Instruction[] instructions, 222 222 IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals, 223 IDictionary<string, Interval> variableIntervals ) {223 IDictionary<string, Interval> variableIntervals, List<string> multipleOccurenceVariables) { 224 224 var savedIntervals = variableIntervals.ToDictionary(entry => entry.Key, entry => entry.Value); 225 var min = FindBound(instructions, nodeIntervals, variableIntervals, m inimization: true);226 var max = FindBound(instructions, nodeIntervals, savedIntervals, m inimization: false);225 var min = FindBound(instructions, nodeIntervals, variableIntervals, multipleOccurenceVariables, minimization: true); 226 var max = FindBound(instructions, nodeIntervals, savedIntervals, multipleOccurenceVariables, minimization: false); 227 227 228 228 return new Interval(min, max); … … 232 232 private static double FindBound(Instruction[] instructions, 233 233 IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals, 234 IDictionary<string, Interval> variableIntervals, bool minimization = true) {234 IDictionary<string, Interval> variableIntervals, List<string> multipleOccurenceVariables, bool minimization = true) { 235 235 SortedSet<BoxBound> prioQ = new SortedSet<BoxBound>(); 236 236 … … 241 241 // the order of keys in a dictionary is guaranteed to be the same order as values in a dictionary 242 242 // https://docs.microsoft.com/en-us/dotnet/api/system.collections.idictionary.keys?view=netcore-3.1#remarks 243 var box = variableIntervals.Values; 243 //var box = variableIntervals.Values; 244 //Box only contains intervals from multiple occurence variables 245 var box = multipleOccurenceVariables.Select(k => variableIntervals[k]); 244 246 if (minimization) { 245 247 prioQ.Add(new BoxBound(box, interval.LowerBound)); … … 256 258 257 259 foreach (var newBox in newBoxes) { 260 //var intervalEnum = newBox.GetEnumerator(); 261 //var keyEnum = readonlyRanges.Keys.GetEnumerator(); 262 //while (intervalEnum.MoveNext() & keyEnum.MoveNext()) { 263 // variableIntervals[keyEnum.Current] = intervalEnum.Current; 264 //} 265 //Set the splitted variables 258 266 var intervalEnum = newBox.GetEnumerator(); 259 var keyEnum = readonlyRanges.Keys.GetEnumerator();260 while (intervalEnum.MoveNext() & keyEnum.MoveNext()) {261 variableIntervals[key Enum.Current] = intervalEnum.Current;267 foreach (var key in multipleOccurenceVariables) { 268 intervalEnum.MoveNext(); 269 variableIntervals[key] = intervalEnum.Current; 262 270 } 263 271 … … 266 274 new ReadOnlyDictionary<string, Interval>(variableIntervals)); 267 275 if (minimization) { 268 prioQ.Add(new BoxBound(newBox, interval.LowerBound));276 prioQ.Add(new BoxBound(newBox, res.LowerBound)); 269 277 } else { 270 prioQ.Add(new BoxBound(newBox, - interval.UpperBound));278 prioQ.Add(new BoxBound(newBox, -res.UpperBound)); 271 279 } 272 280 } … … 539 547 } 540 548 541 private static bool ContainsVariableMultipleTimes(ISymbolicExpressionTree tree) { 549 private static bool ContainsVariableMultipleTimes(ISymbolicExpressionTree tree, out List<String> variables) { 550 variables = new List<string>(); 542 551 var varlist = tree.IterateNodesPrefix().OfType<VariableTreeNode>().GroupBy(x => x.VariableName); 552 foreach (var group in varlist) { 553 if (group.Count() > 1) { 554 variables.Add(group.Key); 555 } 556 } 557 543 558 return varlist.Any(group => group.Count() > 1); 544 559 }
Note: See TracChangeset
for help on using the changeset viewer.