Changeset 17637
- Timestamp:
- 06/29/20 15:46:34 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
r17631 r17637 24 24 using System; 25 25 using System.Collections.Generic; 26 using System.Collections.ObjectModel; 26 27 using System.Linq; 27 28 using System.Runtime.Remoting.Contexts; … … 79 80 private IntervalInterpreter(IntervalInterpreter original, Cloner cloner) 80 81 : base(original, cloner) { } 81 82 82 83 public IntervalInterpreter() 83 84 : base("IntervalInterpreter", "Interpreter for calculation of intervals of symbolic models.") { … … 88 89 Parameters.Add(new FixedValueParameter<BoolValue>(UseIntervalSplittingParameterName, "", new BoolValue(false))); 89 90 } 90 91 91 92 public override IDeepCloneable Clone(Cloner cloner) { 92 93 return new IntervalInterpreter(this, cloner); … … 107 108 public Interval GetSymbolicExpressionTreeInterval( 108 109 ISymbolicExpressionTree tree, IDataset dataset, 109 IEnumerable<int> rows = null , bool splitting = true) {110 IEnumerable<int> rows = null) { 110 111 var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows); 111 return GetSymbolicExpressionTreeInterval(tree, variableRanges , splitting);112 return GetSymbolicExpressionTreeInterval(tree, variableRanges); 112 113 } 113 114 … … 115 116 ISymbolicExpressionTree tree, IDataset dataset, 116 117 out IDictionary<ISymbolicExpressionTreeNode, Interval> 117 nodeIntervals, IEnumerable<int> rows = null , bool splitting = true) {118 nodeIntervals, IEnumerable<int> rows = null) { 118 119 var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows); 119 return GetSymbolicExpressionTreeIntervals(tree, variableRanges, out nodeIntervals , splitting);120 return GetSymbolicExpressionTreeIntervals(tree, variableRanges, out nodeIntervals); 120 121 } 121 122 122 123 public Interval GetSymbolicExpressionTreeInterval( 123 124 ISymbolicExpressionTree tree, 124 I Dictionary<string, Interval> variableRanges, bool splitting = true) {125 IReadOnlyDictionary<string, Interval> variableRanges) { 125 126 lock (syncRoot) { 126 127 EvaluatedSolutions++; … … 129 130 Interval outputInterval; 130 131 131 if ( splitting) {132 if (UseIntervalSplitting) { 132 133 outputInterval = GetSymbolicExpressionTreeIntervals(tree, variableRanges, 133 134 out var nodeIntervals); … … 146 147 public Interval GetSymbolicExpressionTreeIntervals( 147 148 ISymbolicExpressionTree tree, 148 I Dictionary<string, Interval> variableRanges,149 IReadOnlyDictionary<string, Interval> variableRanges, 149 150 out IDictionary<ISymbolicExpressionTreeNode, Interval> 150 nodeIntervals , bool splitting = true) {151 nodeIntervals) { 151 152 lock (syncRoot) { 152 153 EvaluatedSolutions++; … … 157 158 158 159 Interval outputInterval; 159 if ( splitting) {160 if (UseIntervalSplitting) { 160 161 var variables = tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(x => x.VariableName).Distinct() 161 162 .ToList(); … … 165 166 var currIndex = 0; 166 167 var currDepth = 0; 167 outputInterval = EvaluateRecursive(instructions, intervals, variableRanges, variables, MinSplittingWidth, MaxSplittingDepth, 168 IDictionary<string, Interval> writeableVariableRanges = variableRanges.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); 169 outputInterval = EvaluateRecursive(instructions, intervals, writeableVariableRanges, variables, MinSplittingWidth, MaxSplittingDepth, 168 170 ref currIndex, ref currDepth, tree); 169 171 } else { … … 195 197 private static Instruction[] PrepareInterpreterState( 196 198 ISymbolicExpressionTree tree, 197 I Dictionary<string, Interval> variableRanges) {199 IReadOnlyDictionary<string, Interval> variableRanges) { 198 200 if (variableRanges == null) 199 201 throw new ArgumentNullException("No variablew ranges are present!", nameof(variableRanges)); … … 212 214 return code; 213 215 } 216 217 214 218 215 219 public static Interval EvaluateRecursive( … … 221 225 Interval evaluate() { 222 226 var ic = 0; 223 return Evaluate(instructions, ref ic, nodeIntervals, variableIntervals); 227 IReadOnlyDictionary<string, Interval> readonlyRanges = new ReadOnlyDictionary<string, Interval>(variableIntervals); 228 return Evaluate(instructions, ref ic, nodeIntervals, readonlyRanges); 224 229 } 225 230 … … 261 266 Instruction[] instructions, ref int instructionCounter, 262 267 IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals = null, 263 I Dictionary<string, Interval> variableIntervals = null) {268 IReadOnlyDictionary<string, Interval> variableIntervals = null) { 264 269 var currentInstr = instructions[instructionCounter]; 265 270 //Use ref parameter, because the tree will be iterated through recursively from the left-side branch to the right side
Note: See TracChangeset
for help on using the changeset viewer.