Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17637


Ignore:
Timestamp:
06/29/20 15:46:34 (4 years ago)
Author:
chaider
Message:

#3073 Changed variable ranges to readonly at GetIntervals methods

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs

    r17631 r17637  
    2424using System;
    2525using System.Collections.Generic;
     26using System.Collections.ObjectModel;
    2627using System.Linq;
    2728using System.Runtime.Remoting.Contexts;
     
    7980    private IntervalInterpreter(IntervalInterpreter original, Cloner cloner)
    8081      : base(original, cloner) { }
    81 
     82   
    8283    public IntervalInterpreter()
    8384      : base("IntervalInterpreter", "Interpreter for calculation of intervals of symbolic models.") {
     
    8889      Parameters.Add(new FixedValueParameter<BoolValue>(UseIntervalSplittingParameterName, "", new BoolValue(false)));
    8990    }
    90 
     91   
    9192    public override IDeepCloneable Clone(Cloner cloner) {
    9293      return new IntervalInterpreter(this, cloner);
     
    107108    public Interval GetSymbolicExpressionTreeInterval(
    108109      ISymbolicExpressionTree tree, IDataset dataset,
    109       IEnumerable<int> rows = null, bool splitting = true) {
     110      IEnumerable<int> rows = null) {
    110111      var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows);
    111       return GetSymbolicExpressionTreeInterval(tree, variableRanges, splitting);
     112      return GetSymbolicExpressionTreeInterval(tree, variableRanges);
    112113    }
    113114
     
    115116      ISymbolicExpressionTree tree, IDataset dataset,
    116117      out IDictionary<ISymbolicExpressionTreeNode, Interval>
    117         nodeIntervals, IEnumerable<int> rows = null, bool splitting = true) {
     118        nodeIntervals, IEnumerable<int> rows = null) {
    118119      var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows);
    119       return GetSymbolicExpressionTreeIntervals(tree, variableRanges, out nodeIntervals, splitting);
     120      return GetSymbolicExpressionTreeIntervals(tree, variableRanges, out nodeIntervals);
    120121    }
    121122
    122123    public Interval GetSymbolicExpressionTreeInterval(
    123124      ISymbolicExpressionTree tree,
    124       IDictionary<string, Interval> variableRanges, bool splitting = true) {
     125      IReadOnlyDictionary<string, Interval> variableRanges) {
    125126      lock (syncRoot) {
    126127        EvaluatedSolutions++;
     
    129130      Interval outputInterval;
    130131
    131       if (splitting) {
     132      if (UseIntervalSplitting) {
    132133        outputInterval = GetSymbolicExpressionTreeIntervals(tree, variableRanges,
    133134          out var nodeIntervals);
     
    146147    public Interval GetSymbolicExpressionTreeIntervals(
    147148      ISymbolicExpressionTree tree,
    148       IDictionary<string, Interval> variableRanges,
     149      IReadOnlyDictionary<string, Interval> variableRanges,
    149150      out IDictionary<ISymbolicExpressionTreeNode, Interval>
    150         nodeIntervals, bool splitting = true) {
     151        nodeIntervals) {
    151152      lock (syncRoot) {
    152153        EvaluatedSolutions++;
     
    157158
    158159      Interval outputInterval;
    159       if (splitting) {
     160      if (UseIntervalSplitting) {
    160161        var variables = tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(x => x.VariableName).Distinct()
    161162                            .ToList();
     
    165166          var currIndex = 0;
    166167          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,
    168170            ref currIndex, ref currDepth, tree);
    169171        } else {
     
    195197    private static Instruction[] PrepareInterpreterState(
    196198      ISymbolicExpressionTree tree,
    197       IDictionary<string, Interval> variableRanges) {
     199      IReadOnlyDictionary<string, Interval> variableRanges) {
    198200      if (variableRanges == null)
    199201        throw new ArgumentNullException("No variablew ranges are present!", nameof(variableRanges));
     
    212214      return code;
    213215    }
     216
     217
    214218
    215219    public static Interval EvaluateRecursive(
     
    221225      Interval evaluate() {
    222226        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);
    224229      }
    225230
     
    261266      Instruction[] instructions, ref int instructionCounter,
    262267      IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals = null,
    263       IDictionary<string, Interval> variableIntervals = null) {
     268      IReadOnlyDictionary<string, Interval> variableIntervals = null) {
    264269      var currentInstr = instructions[instructionCounter];
    265270      //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.