Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/21 14:00:36 (4 years ago)
Author:
gkronber
Message:

#3073: intermediate comment while refactoring the branch

Location:
branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/IntervalArithmeticGrammar.cs

    r17880 r17887  
    3535      var cos = new Cosine();
    3636      var tan = new Tangent();
     37      var tanh = new HyperbolicTangent();
    3738      var log = new Logarithm();
    38       var pow = new Power();
     39      var exp = new Exponential();
    3940      var square = new Square();
    40       var root = new Root();
    4141      var sqrt = new SquareRoot();
    42       var exp = new Exponential();
    43       var tanh = new HyperbolicTangent();
     42      var cube = new Cube();
     43      var cbrt = new CubeRoot();
     44      var abs = new Absolute();
     45      var aq = new AnalyticQuotient();
    4446      var constant = new Constant();
    45       var aq = new AnalyticQuotient();
    4647      constant.MinValue = -20;
    4748      constant.MaxValue = 20;
     
    5152
    5253      //Special symbols
    53       var offset = new Addition {Name = "Offset"};
    54       var scaling = new Multiplication {Name = "Scaling"};
     54      var offset = new Addition { Name = "Offset" };
     55      var scaling = new Multiplication { Name = "Scaling" };
    5556      //all other symbols
    5657      var allSymbols = new List<Symbol> {
    57         add, sub, mul, div, constant, variableSymbol, sin, cos, tan, log, pow, square, root, sqrt, exp,
    58         tanh, aq
     58        add, sub, mul, div, constant, variableSymbol, sin, cos, tan, log, square, sqrt, cube, cbrt, exp,
     59        tanh, aq, abs
    5960      };
    6061
    61       var arithmeticSymbols = new List<Symbol> {add, sub, mul, div};
    62       var trigonometricSymbols = new List<Symbol> {sin, cos, tan, tanh};
    63       var exponentialAndLogarithmicSymbols = new List<Symbol> {exp, log};
    64       var powerSymbols = new List<Symbol> {square, pow, sqrt, root};
    65       var specialSymbols = new List<Symbol> {aq};
    66       var realValueSymbols = new List<Symbol>
    67         {add, sub, mul, div, sin, cos, tan, tanh, exp, log, variableSymbol, constant, aq};
     62      var bivariateFuncs = new List<Symbol> { add, sub, mul, div, aq };
     63      var univariateFuncs = new List<Symbol> { sin, cos, tan, tanh, exp, log, abs, square, cube, sqrt, cbrt };
     64      var realValueSymbols = new List<Symbol> {
     65         add, sub, mul, div, sin, cos, tan, tanh, exp, log, aq, abs, square, cube, sqrt, cbrt,
     66         variableSymbol, constant,
     67        };
    6868
    6969
     
    7676      #region define subtree count for special symbols
    7777
    78       foreach (var symb in arithmeticSymbols) SetSubtreeCount(symb, 2, 2);
     78      foreach (var symb in bivariateFuncs) SetSubtreeCount(symb, 2, 2);
    7979
    80       foreach (var symb in trigonometricSymbols) SetSubtreeCount(symb, 1, 1);
    81 
    82       foreach (var symb in exponentialAndLogarithmicSymbols) SetSubtreeCount(symb, 1, 1);
     80      foreach (var symb in univariateFuncs) SetSubtreeCount(symb, 1, 1);
    8381
    8482      SetSubtreeCount(offset, 2, 2);
    8583      SetSubtreeCount(scaling, 2, 2);
    86       SetSubtreeCount(pow, 2, 2);
    87       SetSubtreeCount(root, 2, 2);
    88       SetSubtreeCount(square, 1, 1);
    89       SetSubtreeCount(sqrt, 1, 1);
    90       SetSubtreeCount(aq, 2, 2);
    9184
    9285      #endregion
     
    109102      }
    110103
    111       //define childs for power symbols
    112       foreach (var symb in powerSymbols) {
    113         AddAllowedChildSymbol(symb, variableSymbol, 0);
    114         AddAllowedChildSymbol(symb, constant, 1);
    115       }
    116 
    117       //define child for sqrt and square
    118       foreach (var c in realValueSymbols) {
    119         AddAllowedChildSymbol(square, c, 0);
    120         AddAllowedChildSymbol(sqrt, c, 0);
    121       }
    122 
    123       //define child for aq
    124       foreach (var c in realValueSymbols) {
    125         AddAllowedChildSymbol(aq, c, 0);
    126         AddAllowedChildSymbol(aq, c, 1);
    127       }
    128 
    129104      #endregion
    130105
    131       Symbols.First(s => s is Power).Enabled = false;
    132       Symbols.First(s => s is Root).Enabled = false;
    133       Symbols.First(s => s is AnalyticQuotient).Enabled = false;
     106      Symbols.First(s => s is Cube).Enabled = false;
     107      Symbols.First(s => s is CubeRoot).Enabled = false;
     108      Symbols.First(s => s is Absolute).Enabled = false;
    134109    }
    135110  }
  • branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/IBoundsEstimator.cs

    r17768 r17887  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
     1using System.Collections.Generic;
    62using HEAL.Attic;
    73using HeuristicLab.Core;
    84using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    95
    10 namespace HeuristicLab.Problems.DataAnalysis.Symbolic{
     6namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    117  [StorableType("C94A360D-5A9F-48A3-A6D3-CF920C77E50D")]
    128  public interface IBoundsEstimator : INamedItem, IStatefulItem {
    139    Interval GetModelBound(ISymbolicExpressionTree tree, IntervalCollection variableRanges);
    1410
    15     IDictionary<ISymbolicExpressionTreeNode, Interval> GetModelNodesBounds(
     11    IDictionary<ISymbolicExpressionTreeNode, Interval> GetModelNodeBounds(
    1612      ISymbolicExpressionTree tree, IntervalCollection variableRanges);
    1713
     14    // returns the size of the violation which is the distance to one of the bounds
    1815    double CheckConstraint(
    19       ISymbolicExpressionTree tree, IntervalCollection variableRanges, IntervalConstraint constraint);
     16      ISymbolicExpressionTree tree, IntervalCollection variableRanges, ShapeConstraint constraint);
    2017
    2118    bool IsCompatible(ISymbolicExpressionTree tree);
    2219
    2320    int EvaluatedSolutions { get; set; }
    24     }
     21  }
    2522}
  • branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IABoundsEstimator.cs

    r17880 r17887  
    461461    }
    462462
    463     public IDictionary<ISymbolicExpressionTreeNode, Interval> GetModelNodesBounds(
     463    public IDictionary<ISymbolicExpressionTreeNode, Interval> GetModelNodeBounds(
    464464      ISymbolicExpressionTree tree, IntervalCollection variableRanges) {
    465465      throw new NotImplementedException();
     
    467467
    468468    public double CheckConstraint(
    469       ISymbolicExpressionTree tree, IntervalCollection variableRanges, IntervalConstraint constraint) {
     469      ISymbolicExpressionTree tree, IntervalCollection variableRanges, ShapeConstraint constraint) {
    470470      var occuringVariableRanges = GetOccurringVariableRanges(tree, variableRanges);
    471471      var instructions = PrepareInterpreterState(tree, occuringVariableRanges);
  • branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IACompiledExpressionBoundsEstimator.cs

    r17772 r17887  
    104104
    105105
    106     public double CheckConstraint(ISymbolicExpressionTree tree, IntervalCollection variableRanges, IntervalConstraint constraint) {
     106    public double CheckConstraint(ISymbolicExpressionTree tree, IntervalCollection variableRanges, ShapeConstraint constraint) {
    107107      if (!UseIntervalSplitting) {
    108108        var modelBound = GetModelBound(tree, variableRanges);
     
    166166    }
    167167
    168     public IDictionary<ISymbolicExpressionTreeNode, Interval> GetModelNodesBounds(ISymbolicExpressionTree tree, IntervalCollection variableRanges) {
     168    public IDictionary<ISymbolicExpressionTreeNode, Interval> GetModelNodeBounds(ISymbolicExpressionTree tree, IntervalCollection variableRanges) {
    169169      throw new NotSupportedException("Model nodes bounds are not supported.");
    170170    }
  • branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs

    r17760 r17887  
    2424using System;
    2525using System.Collections.Generic;
    26 using System.Collections.ObjectModel;
    2726using System.Linq;
    2827using HEAL.Attic;
     
    3837  public sealed class IntervalInterpreter : ParameterizedNamedItem, IStatefulItem {
    3938    private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
    40     private const string MinSplittingWidthParameterName = "MinSplittingWidth";
    41     private const string MaxSplittingDepthParameterName = "MaxSplittingDepth";
    42     private const string UseIntervalSplittingParameterName = "UseIntervalSplitting";
    43 
    4439    public IFixedValueParameter<IntValue> EvaluatedSolutionsParameter =>
    4540      (IFixedValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName];
    46 
    47     public IFixedValueParameter<IntValue> MinSplittingWithParameter =>
    48       (IFixedValueParameter<IntValue>)Parameters[MinSplittingWidthParameterName];
    49 
    50     public IFixedValueParameter<IntValue> MaxSplittingDepthParameter =>
    51       (IFixedValueParameter<IntValue>)Parameters[MaxSplittingDepthParameterName];
    52 
    53     public IFixedValueParameter<BoolValue> UseIntervalSplittingParameter =>
    54       (IFixedValueParameter<BoolValue>)Parameters[UseIntervalSplittingParameterName];
    55 
    56     public int MinSplittingWidth {
    57       get => MinSplittingWithParameter.Value.Value;
    58       set => MinSplittingWithParameter.Value.Value = value;
    59     }
    60 
    61     public int MaxSplittingDepth {
    62       get => MaxSplittingDepthParameter.Value.Value;
    63       set => MaxSplittingDepthParameter.Value.Value = value;
    64     }
    65 
    66     public bool UseIntervalSplitting {
    67       get => UseIntervalSplittingParameter.Value.Value;
    68       set => UseIntervalSplittingParameter.Value.Value = value;
    69     }
    7041
    7142    public int EvaluatedSolutions {
     
    8455      Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName,
    8556        "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
    86       Parameters.Add(new FixedValueParameter<IntValue>(MinSplittingWidthParameterName,
    87         "Minimum interval width until splitting is stopped", new IntValue(0)));
    88       Parameters.Add(new FixedValueParameter<IntValue>(MaxSplittingDepthParameterName,
    89         "Maximum recursion depth of the splitting", new IntValue(5)));
    90       Parameters.Add(new FixedValueParameter<BoolValue>(UseIntervalSplittingParameterName, "", new BoolValue(false)));
    9157    }
    9258
     
    13197      Interval outputInterval;
    13298
    133       if (UseIntervalSplitting) {
    134         outputInterval = GetSymbolicExpressionTreeIntervals(tree, variableRanges,
    135           out var _);
    136       } else {
    137         var instructionCount = 0;
    138         var instructions = PrepareInterpreterState(tree, variableRanges);
    139         outputInterval = Evaluate(instructions, ref instructionCount);
    140       }
     99      var instructionCount = 0;
     100      var instructions = PrepareInterpreterState(tree, variableRanges);
     101      outputInterval = Evaluate(instructions, ref instructionCount);
    141102
    142103      return outputInterval.LowerBound <= outputInterval.UpperBound
     
    159120
    160121      Interval outputInterval;
    161       if (UseIntervalSplitting) {
    162         //var variables = tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(x => x.VariableName).Distinct()
    163         //                    .ToList();
    164         var containsDependencyProblem = ContainsVariableMultipleTimes(tree, out var variables);
    165 
    166         if (containsDependencyProblem) {
    167           var currIndex = 0;
    168           var currDepth = 0;
    169           IDictionary<string, Interval> writeableVariableRanges =
    170             variableRanges.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
    171           //outputInterval = EvaluateRecursive(instructions, intervals, writeableVariableRanges, variables, MinSplittingWidth, MaxSplittingDepth,
    172           //  ref currIndex, ref currDepth, tree);
    173           outputInterval = EvaluateWithSplitting(instructions, intervals, writeableVariableRanges, variables);
    174         } else {
    175           var instructionCount = 0;
    176           outputInterval = Evaluate(instructions, ref instructionCount, intervals);
    177         }
    178       } else {
    179         var instructionCount = 0;
    180         outputInterval = Evaluate(instructions, ref instructionCount, intervals);
    181       }
     122      var instructionCount = 0;
     123      outputInterval = Evaluate(instructions, ref instructionCount, intervals);
    182124
    183125      nodeIntervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>();
     
    219161    }
    220162
    221     public static Interval EvaluateWithSplitting(Instruction[] instructions,
    222                                                  IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals,
    223                                                  IDictionary<string, Interval> variableIntervals, List<string> multipleOccurenceVariables) {
    224       var savedIntervals = variableIntervals.ToDictionary(entry => entry.Key, entry => entry.Value);
    225       var min = FindBound(instructions, nodeIntervals, variableIntervals, multipleOccurenceVariables, minimization: true);
    226       var max = FindBound(instructions, nodeIntervals, savedIntervals, multipleOccurenceVariables, minimization: false);
    227 
    228       return new Interval(min, max);
    229     }
    230 
    231 
    232     private static double FindBound(Instruction[] instructions,
    233                                     IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals,
    234                                     IDictionary<string, Interval> variableIntervals, List<string> multipleOccurenceVariables, bool minimization = true) {
    235       SortedSet<BoxBound> prioQ = new SortedSet<BoxBound>();
    236 
    237       var ic = 0;
    238       //Calculate full box
    239       IReadOnlyDictionary<string, Interval> readonlyRanges = variableIntervals.ToDictionary(k => k.Key, k => k.Value);
    240       var interval = Evaluate(instructions, ref ic, nodeIntervals, readonlyRanges);
    241       // the order of keys in a dictionary is guaranteed to be the same order as values in a dictionary
    242       // https://docs.microsoft.com/en-us/dotnet/api/system.collections.idictionary.keys?view=netcore-3.1#remarks
    243       //var box = variableIntervals.Values;
    244       //Box only contains intervals from multiple occurence variables
    245       var box = multipleOccurenceVariables.Select(k => variableIntervals[k]);
    246       if (minimization) {
    247         prioQ.Add(new BoxBound(box, interval.LowerBound));
    248       } else {
    249         prioQ.Add(new BoxBound(box, -interval.UpperBound));
    250       }
    251 
    252       // TODO a fixed limit for depth?!
    253       for (var depth = 0; depth < 200; ++depth) {
    254         var currentBound = prioQ.Min;
    255         prioQ.Remove(currentBound);
    256 
    257         var newBoxes = Split(currentBound.box);
    258 
    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
    266           var intervalEnum = newBox.GetEnumerator();
    267           foreach (var key in multipleOccurenceVariables) {
    268             intervalEnum.MoveNext();
    269             variableIntervals[key] = intervalEnum.Current;
    270           }
    271 
    272           ic = 0;
    273           var res = Evaluate(instructions, ref ic, nodeIntervals,
    274             new ReadOnlyDictionary<string, Interval>(variableIntervals));
    275           if (minimization) {
    276             prioQ.Add(new BoxBound(newBox, res.LowerBound));
    277           } else {
    278             prioQ.Add(new BoxBound(newBox, -res.UpperBound));
    279           }
    280         }
    281       }
    282 
    283       return minimization ?
    284         prioQ.First().bound :
    285         -prioQ.First().bound;
    286     }
    287 
    288     private static IEnumerable<IEnumerable<Interval>> Split(List<Interval> box) {
    289       var boxes = box.Select(region => region.Split()).Select(split => new List<Interval> { split.Item1, split.Item2 })
    290                      .ToList();
    291 
    292       return boxes.CartesianProduct();
    293     }
    294 
    295     // a multi-dimensional box with an associated bound
    296     // boxbounds are ordered first by bound (smaller first), then by size of box (larger first) then by distance of bottom left corner to origin
    297     private class BoxBound : IComparable<BoxBound> {
    298       public List<Interval> box;
    299       public double bound;
    300       public BoxBound(IEnumerable<Interval> box, double bound) {
    301         this.box = new List<Interval>(box);
    302         this.bound = bound;
    303       }
    304       public int CompareTo(BoxBound other) {
    305         if (bound != other.bound) return bound.CompareTo(other.bound);
    306 
    307         var thisSize = box.Aggregate(1.0, (current, dimExtent) => current * dimExtent.Width);
    308         var otherSize = other.box.Aggregate(1.0, (current, dimExtent) => current * dimExtent.Width);
    309         if (thisSize != otherSize) return -thisSize.CompareTo(otherSize);
    310 
    311         var thisDist = box.Sum(dimExtent => dimExtent.LowerBound * dimExtent.LowerBound);
    312         var otherDist = other.box.Sum(dimExtent => dimExtent.LowerBound * dimExtent.LowerBound);
    313         if (thisDist != otherDist) return thisDist.CompareTo(otherDist);
    314 
    315         // which is smaller first along the dimensions?
    316         for (int i = 0; i < box.Count; i++) {
    317           if (box[i].LowerBound != other.box[i].LowerBound) return box[i].LowerBound.CompareTo(other.box[i].LowerBound);
    318         }
    319 
    320         return 0;
    321       }
    322     }
    323 
    324     public static Interval EvaluateRecursive(
    325       Instruction[] instructions,
    326       IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals,
    327       IDictionary<string, Interval> variableIntervals, IList<string> variables,
    328       double minWidth, int maxDepth, ref int currIndex, ref int currDepth,
    329       ISymbolicExpressionTree tree) {
    330       Interval evaluate() {
    331         var ic = 0;
    332         IReadOnlyDictionary<string, Interval> readonlyRanges =
    333           new ReadOnlyDictionary<string, Interval>(variableIntervals);
    334         return Evaluate(instructions, ref ic, nodeIntervals, readonlyRanges);
    335       }
    336 
    337       Interval recurse(ref int idx, ref int depth) {
    338         return EvaluateRecursive(instructions, nodeIntervals, variableIntervals, variables, minWidth, maxDepth, ref idx,
    339           ref depth, tree);
    340       }
    341 
    342 
    343       var v = variables[currIndex];
    344       var x = variableIntervals[v];
    345       if (x.Width < minWidth || currDepth == maxDepth || !MultipleTimes(tree, v)) {
    346         if (currIndex + 1 < variables.Count) {
    347           currDepth = 0;
    348           currIndex++;
    349           var z = recurse(ref currIndex, ref currDepth);
    350           currIndex--;
    351           return z;
    352         }
    353 
    354         return evaluate();
    355       }
    356 
    357       var t = x.Split();
    358       var xa = t.Item1;
    359       var xb = t.Item2;
    360       var d = currDepth;
    361       currDepth = d + 1;
    362       variableIntervals[v] = xa;
    363       var ya = recurse(ref currIndex, ref currDepth);
    364       currDepth = d + 1;
    365       variableIntervals[v] = xb;
    366       var yb = recurse(ref currIndex, ref currDepth);
    367       variableIntervals[v] = x; // restore interval
    368       return ya | yb;
    369     }
    370 
     163    // Use ref parameter, because the tree will be iterated through recursively from the left-side branch to the right side
     164    // Update instructionCounter, whenever Evaluate is called
    371165    public static Interval Evaluate(
    372       Instruction[] instructions, ref int instructionCounter,
     166    Instruction[] instructions, ref int instructionCounter,
    373167      IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals = null,
    374168      IReadOnlyDictionary<string, Interval> variableIntervals = null) {
    375169      var currentInstr = instructions[instructionCounter];
    376       //Use ref parameter, because the tree will be iterated through recursively from the left-side branch to the right side
    377       //Update instructionCounter, whenever Evaluate is called
     170
    378171      instructionCounter++;
    379       Interval result = null;
     172      Interval result;
    380173
    381174      switch (currentInstr.opCode) {
    382         //Variables, Constants, ...
    383175        case OpCodes.Variable: {
    384176            var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode;
    385177            var weightInterval = new Interval(variableTreeNode.Weight, variableTreeNode.Weight);
    386             //var variableInterval = (Interval)currentInstr.data;
    387178
    388179            Interval variableInterval;
     
    402193        //Elementary arithmetic rules
    403194        case OpCodes.Add: {
    404             //result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    405             result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    406             for (var i = 1; i < currentInstr.nArguments; i++) {
    407               //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
     195            result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
     196            for (var i = 1; i < currentInstr.nArguments; i++) {
    408197              var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    409198              result = Interval.Add(result, argumentInterval);
     
    413202          }
    414203        case OpCodes.Sub: {
    415             //result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    416204            result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    417205            if (currentInstr.nArguments == 1)
     
    419207
    420208            for (var i = 1; i < currentInstr.nArguments; i++) {
    421               //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    422209              var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    423210              result = Interval.Subtract(result, argumentInterval);
     
    427214          }
    428215        case OpCodes.Mul: {
    429             //result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    430             result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    431             for (var i = 1; i < currentInstr.nArguments; i++) {
    432               var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    433               //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
     216            result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
     217            for (var i = 1; i < currentInstr.nArguments; i++) {
     218              var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    434219              result = Interval.Multiply(result, argumentInterval);
    435220            }
     
    438223          }
    439224        case OpCodes.Div: {
    440             //result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    441225            result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    442226            if (currentInstr.nArguments == 1)
     
    444228
    445229            for (var i = 1; i < currentInstr.nArguments; i++) {
    446               //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    447230              var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    448231              result = Interval.Divide(result, argumentInterval);
     
    451234            break;
    452235          }
    453         //Trigonometric functions
    454236        case OpCodes.Sin: {
    455             //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    456237            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    457238            result = Interval.Sine(argumentInterval);
     
    459240          }
    460241        case OpCodes.Cos: {
    461             //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    462242            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    463243            result = Interval.Cosine(argumentInterval);
     
    465245          }
    466246        case OpCodes.Tan: {
    467             //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    468247            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    469248            result = Interval.Tangens(argumentInterval);
     
    471250          }
    472251        case OpCodes.Tanh: {
    473             //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    474252            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    475253            result = Interval.HyperbolicTangent(argumentInterval);
    476254            break;
    477255          }
    478         //Exponential functions
    479256        case OpCodes.Log: {
    480             //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    481257            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    482258            result = Interval.Logarithm(argumentInterval);
     
    484260          }
    485261        case OpCodes.Exp: {
    486             //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    487262            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    488263            result = Interval.Exponential(argumentInterval);
     
    490265          }
    491266        case OpCodes.Square: {
    492             //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    493267            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    494268            result = Interval.Square(argumentInterval);
     
    496270          }
    497271        case OpCodes.SquareRoot: {
    498             //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    499272            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    500273            result = Interval.SquareRoot(argumentInterval);
     
    502275          }
    503276        case OpCodes.Cube: {
    504             //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    505277            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    506278            result = Interval.Cube(argumentInterval);
     
    508280          }
    509281        case OpCodes.CubeRoot: {
    510             //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    511282            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    512283            result = Interval.CubicRoot(argumentInterval);
     
    514285          }
    515286        case OpCodes.Absolute: {
    516             //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    517287            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    518288            result = Interval.Absolute(argumentInterval);
     
    520290          }
    521291        case OpCodes.AnalyticQuotient: {
    522             //result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    523             result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    524             for (var i = 1; i < currentInstr.nArguments; i++) {
    525               //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
     292            result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
     293            for (var i = 1; i < currentInstr.nArguments; i++) {
    526294              var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    527295              result = Interval.AnalyticalQuotient(result, argumentInterval);
     
    538306
    539307      return result;
    540     }
    541 
    542     private static bool MultipleTimes(ISymbolicExpressionTree tree, string variable) {
    543       var varlist = tree.IterateNodesPrefix().OfType<VariableTreeNode>().GroupBy(x => x.VariableName);
    544       var group = varlist.Select(x => x.Key == variable).Count();
    545 
    546       return group > 1;
    547     }
    548 
    549     private static bool ContainsVariableMultipleTimes(ISymbolicExpressionTree tree, out List<String> variables) {
    550       variables = new List<string>();
    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 
    558       return varlist.Any(group => group.Count() > 1);
    559308    }
    560309
  • branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/IntervalUtil.cs

    r17881 r17887  
    77  public static class IntervalUtil {
    88    public static double IntervalConstraintViolation(
    9       IntervalConstraint constraint, IBoundsEstimator estimator, IntervalCollection intervalCollection,
     9      ShapeConstraint constraint, IBoundsEstimator estimator, IntervalCollection intervalCollection,
    1010      ISymbolicExpressionTree solution) {
    1111      var variableRanges = intervalCollection.GetReadonlyDictionary();
     
    1414        throw new ArgumentException(
    1515          $"The given variable {constraint.Variable} in the constraint does not exist in the model.",
    16           nameof(IntervalConstraintsParser));
     16          nameof(ShapeConstraintsParser));
    1717      }
    1818
     
    4747
    4848    public static IEnumerable<double> IntervalConstraintsViolation(
    49       IEnumerable<IntervalConstraint> constraints, IBoundsEstimator estimator, IntervalCollection intervalCollection,
     49      IEnumerable<ShapeConstraint> constraints, IBoundsEstimator estimator, IntervalCollection intervalCollection,
    5050      ISymbolicExpressionTree solution) {
    5151      return constraints.Select(constraint => IntervalConstraintViolation(constraint, estimator, intervalCollection, solution)).ToList();
Note: See TracChangeset for help on using the changeset viewer.