Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/24/20 16:14:08 (4 years ago)
Author:
chaider
Message:

#3073

  • Split only variables occuring more than once in the model
  • Fixed returning interval from splitting method
File:
1 edited

Legend:

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

    r17758 r17760  
    160160      Interval outputInterval;
    161161      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);
    165165
    166166        if (containsDependencyProblem) {
     
    171171          //outputInterval = EvaluateRecursive(instructions, intervals, writeableVariableRanges, variables, MinSplittingWidth, MaxSplittingDepth,
    172172          //  ref currIndex, ref currDepth, tree);
    173           outputInterval = EvaluateWithSplitting(instructions, intervals, writeableVariableRanges);
     173          outputInterval = EvaluateWithSplitting(instructions, intervals, writeableVariableRanges, variables);
    174174        } else {
    175175          var instructionCount = 0;
     
    221221    public static Interval EvaluateWithSplitting(Instruction[] instructions,
    222222                                                 IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals,
    223                                                  IDictionary<string, Interval> variableIntervals) {
     223                                                 IDictionary<string, Interval> variableIntervals, List<string> multipleOccurenceVariables) {
    224224      var savedIntervals = variableIntervals.ToDictionary(entry => entry.Key, entry => entry.Value);
    225       var min = FindBound(instructions, nodeIntervals, variableIntervals, minimization: true);
    226       var max = FindBound(instructions, nodeIntervals, savedIntervals, minimization: false);
     225      var min = FindBound(instructions, nodeIntervals, variableIntervals, multipleOccurenceVariables, minimization: true);
     226      var max = FindBound(instructions, nodeIntervals, savedIntervals, multipleOccurenceVariables, minimization: false);
    227227
    228228      return new Interval(min, max);
     
    232232    private static double FindBound(Instruction[] instructions,
    233233                                    IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals,
    234                                     IDictionary<string, Interval> variableIntervals, bool minimization = true) {
     234                                    IDictionary<string, Interval> variableIntervals, List<string> multipleOccurenceVariables, bool minimization = true) {
    235235      SortedSet<BoxBound> prioQ = new SortedSet<BoxBound>();
    236236
     
    241241      // the order of keys in a dictionary is guaranteed to be the same order as values in a dictionary
    242242      // 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]);
    244246      if (minimization) {
    245247        prioQ.Add(new BoxBound(box, interval.LowerBound));
     
    256258
    257259        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
    258266          var intervalEnum = newBox.GetEnumerator();
    259           var keyEnum = readonlyRanges.Keys.GetEnumerator();
    260           while (intervalEnum.MoveNext() & keyEnum.MoveNext()) {
    261             variableIntervals[keyEnum.Current] = intervalEnum.Current;
     267          foreach (var key in multipleOccurenceVariables) {
     268            intervalEnum.MoveNext();
     269            variableIntervals[key] = intervalEnum.Current;
    262270          }
    263271
     
    266274            new ReadOnlyDictionary<string, Interval>(variableIntervals));
    267275          if (minimization) {
    268             prioQ.Add(new BoxBound(newBox, interval.LowerBound));
     276            prioQ.Add(new BoxBound(newBox, res.LowerBound));
    269277          } else {
    270             prioQ.Add(new BoxBound(newBox, -interval.UpperBound));
     278            prioQ.Add(new BoxBound(newBox, -res.UpperBound));
    271279          }
    272280        }
     
    539547    }
    540548
    541     private static bool ContainsVariableMultipleTimes(ISymbolicExpressionTree tree) {
     549    private static bool ContainsVariableMultipleTimes(ISymbolicExpressionTree tree, out List<String> variables) {
     550      variables = new List<string>();
    542551      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
    543558      return varlist.Any(group => group.Count() > 1);
    544559    }
Note: See TracChangeset for help on using the changeset viewer.