Changeset 16403
- Timestamp:
- 12/19/18 10:56:29 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
r16393 r16403 70 70 71 71 public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows = null) { 72 var intervalBoundaries = DatasetUtil.GetVariableRanges(dataset, rows);73 return GetSymbolicExressionTreeIntervals(tree, intervalBoundaries);72 var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows); 73 return GetSymbolicExressionTreeIntervals(tree, variableRanges); 74 74 } 75 75 76 76 public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset, 77 77 out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals, IEnumerable<int> rows = null) { 78 var intervalBoundaries = DatasetUtil.GetVariableRanges(dataset, rows);79 return GetSymbolicExressionTreeIntervals(tree, intervalBoundaries, out intervals);80 } 81 82 public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, Dictionary<string, Interval> customIntervals ) {78 var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows); 79 return GetSymbolicExressionTreeIntervals(tree, variableRanges, out intervals); 80 } 81 82 public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, Dictionary<string, Interval> customIntervalsForVariables) { 83 83 lock (syncRoot) { 84 84 EvaluatedSolutions++; 85 85 } 86 86 int instructionCount = 0; 87 var instructions = PrepareInterpreterState(tree, customIntervals );87 var instructions = PrepareInterpreterState(tree, customIntervalsForVariables); 88 88 var outputInterval = Evaluate(instructions, ref instructionCount); 89 89 … … 93 93 94 94 public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, 95 Dictionary<string, Interval> customIntervals , out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals) {95 Dictionary<string, Interval> customIntervalsForVariables, out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals) { 96 96 lock (syncRoot) { 97 97 EvaluatedSolutions++; … … 99 99 int instructionCount = 0; 100 100 intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>(); 101 var instructions = PrepareInterpreterState(tree, customIntervals );101 var instructions = PrepareInterpreterState(tree, customIntervalsForVariables); 102 102 var outputInterval = Evaluate(instructions, ref instructionCount, intervals); 103 103 … … 106 106 107 107 108 private static Instruction[] PrepareInterpreterState(ISymbolicExpressionTree tree, Dictionary<string, Interval> customIntervals ) {108 private static Instruction[] PrepareInterpreterState(ISymbolicExpressionTree tree, Dictionary<string, Interval> customIntervalsForVariables) { 109 109 Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCodes.MapSymbolToOpCode); 110 110 111 if (customIntervals == null)112 throw new ArgumentException("No interval ranges are present!", nameof(customIntervals ));111 if (customIntervalsForVariables == null) 112 throw new ArgumentException("No interval ranges are present!", nameof(customIntervalsForVariables)); 113 113 114 114 foreach (var variable in tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(n => n.VariableName).Distinct()) { 115 if (!customIntervals .ContainsKey(variable)) throw new InvalidOperationException($"No ranges for variable {variable} is present");115 if (!customIntervalsForVariables.ContainsKey(variable)) throw new InvalidOperationException($"No ranges for variable {variable} is present"); 116 116 } 117 117 118 118 foreach (Instruction instr in code.Where(i => i.opCode == OpCodes.Variable)) { 119 119 var variableTreeNode = (VariableTreeNode)instr.dynamicNode; 120 instr.data = customIntervals [variableTreeNode.VariableName];120 instr.data = customIntervalsForVariables[variableTreeNode.VariableName]; 121 121 } 122 122 return code; … … 130 130 //Variables, Constants, ... 131 131 case OpCodes.Variable: { 132 if (intervals != null)133 intervals.Add(currentInstr.dynamicNode, (Interval)currentInstr.data);134 132 var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode; 135 133 var variableWeight = variableTreeNode.Weight; 136 137 return Interval.Multiply((Interval)currentInstr.data, new Interval(variableWeight, variableWeight)); 134 var varibleWeightInterval = new Interval(variableWeight, variableWeight); 135 136 result = Interval.Multiply((Interval)currentInstr.data, varibleWeightInterval); 137 break; 138 138 } 139 139 case OpCodes.Constant: { 140 140 var constTreeNode = (ConstantTreeNode)currentInstr.dynamicNode; 141 var inter = new Interval(constTreeNode.Value, constTreeNode.Value); 142 if (intervals != null) 143 intervals.Add(currentInstr.dynamicNode, inter); 144 return inter; 141 result = new Interval(constTreeNode.Value, constTreeNode.Value); 142 break; 145 143 } 146 144 //Elementary arithmetic rules
Note: See TracChangeset
for help on using the changeset viewer.