Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/04/15 10:18:39 (10 years ago)
Author:
abeham
Message:

#1985:

  • Restored compilable state of TimeLimitRunOptimizer branch
  • Updated changes from trunk
Location:
branches/TimeLimitRunOptimizer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/TimeLimitRunOptimizer

    • Property svn:ignore set to
      *.suo
  • branches/TimeLimitRunOptimizer/HeuristicLab.Optimization

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/HLScript/HeuristicLab.Optimizationmergedeligible
      /stable/HeuristicLab.Optimizationmergedeligible
      /trunk/sources/HeuristicLab.Optimizationmergedeligible
      /branches/1721-RandomForestPersistence/HeuristicLab.Optimization10321-10322
      /branches/Algorithms.GradientDescent/HeuristicLab.Optimization5516-5520
      /branches/Benchmarking/sources/HeuristicLab.Optimization6917-7005
      /branches/Classification-Extensions/HeuristicLab.Optimization11687-11761
      /branches/CloningRefactoring/HeuristicLab.Optimization4656-4721
      /branches/DataAnalysis Refactoring/HeuristicLab.Optimization5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Optimization5815-6180
      /branches/DataAnalysis/HeuristicLab.Optimization4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.Optimization10085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.Optimization6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Optimization5060
      /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Optimization6123-9799
      /branches/LogResidualEvaluator/HeuristicLab.Optimization10202-10483
      /branches/NET40/sources/HeuristicLab.Optimization5138-5162
      /branches/ParallelEngine/HeuristicLab.Optimization5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Optimization7568-7810
      /branches/ProgrammableProblem/HeuristicLab.Optimization11573-11959
      /branches/QAPAlgorithms/HeuristicLab.Optimization6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Optimization6828
      /branches/RuntimeOptimizer/HeuristicLab.Optimization8943-9078
      /branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization7787-8333
      /branches/SlaveShutdown/HeuristicLab.Optimization8944-8956
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Optimization10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.Optimization5370-5682
      /branches/Trunk/HeuristicLab.Optimization6829-6865
      /branches/UnloadJobs/HeuristicLab.Optimization9168-9215
      /branches/VNS/HeuristicLab.Optimization5594-5752
      /branches/histogram/HeuristicLab.Optimization5959-6341
  • branches/TimeLimitRunOptimizer/HeuristicLab.Optimization/3.3/RunCollectionModification/Calculator.cs

    r8924 r12118  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    9090          }
    9191        }
    92       }
    93       catch (Exception x) {
     92      } catch (Exception x) {
    9493        throw new Exception(string.Format(
    9594          "Calculation of '{1}'{0}failed at token #{2}: {3} {0}current stack is: {0}{4}", Environment.NewLine,
     
    104103      var result = stack.Pop();
    105104      if (result is string) return new StringValue((string)result);
     105      if (result is int) return new IntValue((int)result);
    106106      if (result is double) return new DoubleValue((double)result);
    107107      if (result is bool) return new BoolValue((bool)result);
     
    139139          break;
    140140
    141         case "log": Apply(stack, x => Math.Log((double)x)); break;
    142         case "+": Apply(stack, (x, y) => (double)x + (double)y); break;
    143         case "-": Apply(stack, (x, y) => (double)x - (double)y); break;
    144         case "*": Apply(stack, (x, y) => (double)x * (double)y); break;
    145         case "/": Apply(stack, (x, y) => (double)x / (double)y); break;
    146         case "^": Apply(stack, (x, y) => Math.Pow((double)x, (double)y)); break;
    147         case "<": Apply(stack, (x, y) => (double)x < (double)y); break;
    148         case ">": Apply(stack, (x, y) => (double)x > (double)y); break;
     141        case "log": Apply(stack, x => Math.Log(Convert.ToDouble(x))); break;
     142        case "+": Apply(stack, (x, y) => Convert.ToDouble(x) + Convert.ToDouble(y)); break;
     143        case "-": Apply(stack, (x, y) => Convert.ToDouble(x) - Convert.ToDouble(y)); break;
     144        case "*": Apply(stack, (x, y) => Convert.ToDouble(x) * Convert.ToDouble(y)); break;
     145        case "/": Apply(stack, (x, y) => Convert.ToDouble(x) / Convert.ToDouble(y)); break;
     146        case "^": Apply(stack, (x, y) => Math.Pow(Convert.ToDouble(x), Convert.ToDouble(y))); break;
     147        case "<": Apply(stack, (x, y) => Convert.ToDouble(x) < Convert.ToDouble(y)); break;
     148        case ">": Apply(stack, (x, y) => Convert.ToDouble(x) > Convert.ToDouble(y)); break;
     149
     150        case "toint": Apply(stack, x => Convert.ToInt32(x)); break;
     151        case "todouble": Apply(stack, x => Convert.ToDouble(x)); break;
     152
     153        case "[]": Apply(stack, (a, i) => GetArrayValueAtIndex(a, Convert.ToInt32(i))); break;
    149154
    150155        case "==": Apply(stack, (x, y) => Equal(x, y)); break;
    151         case "not": Apply(stack, x => !(bool)x); break;
     156        case "not": Apply(stack, x => !Convert.ToBoolean(x)); break;
    152157        case "isnull": Apply(stack, x => x == null); break;
    153         case "if": Apply(stack, (then, else_, cond) => (bool)cond ? then : else_); break;
    154 
    155         case "ismatch": Apply(stack, (s, p) => new Regex((string)p).IsMatch((string)s)); break;
    156         case "rename": Apply(stack, (s, p, r) => new Regex((string)p).Replace((string)s, (string)r)); break;
     158        case "if": Apply(stack, (then, else_, cond) => Convert.ToBoolean(cond) ? then : else_); break;
     159
     160        case "ismatch": Apply(stack, (s, p) => new Regex(Convert.ToString(p)).IsMatch(Convert.ToString(s))); break;
     161        case "rename": Apply(stack, (s, p, r) => new Regex(Convert.ToString(p)).Replace(Convert.ToString(s), Convert.ToString(r))); break;
    157162
    158163        default: stack.Push(GetVariableValue(variables, token)); break;
     
    178183      var v = value as BoolValue;
    179184      if (v != null) return v.Value;
     185      return null;
     186    }
     187
     188    private static object GetArrayValue(IItem value) {
     189      if (value is IntArray || value is DoubleArray || value is BoolArray || value is StringArray)
     190        return value;
    180191      return null;
    181192    }
     
    188199          GetDoubleValue(item) ??
    189200          GetBoolValue(item) ??
     201          GetArrayValue(item) ??
    190202          item.ToString();
    191203      }
    192204      return null;
    193205    }
     206
     207    private static object GetArrayValueAtIndex(object array, int index) {
     208      if (array is IntArray)
     209        return ((IntArray)array)[index];
     210      if (array is DoubleArray)
     211        return ((DoubleArray)array)[index];
     212      if (array is BoolArray)
     213        return ((BoolArray)array)[index];
     214      if (array is StringArray)
     215        return ((StringArray)array)[index];
     216      throw new NotSupportedException(string.Format("Type {0} is not a supported array type", array.GetType().Name));
     217    }
    194218    #endregion
    195219
    196220    #region variadic equality
    197     private static bool Equal(object a, object b) { return EqualNumber(a, b) || EqualBool(a, b) || EqualString(a, b) || a == b; }
    198     private static bool EqualNumber(object a, object b) { return a is double && b is double && (double)a == (double)b; }
     221    private static bool Equal(object a, object b) { return EqualIntegerNumber(a, b) || EqualFloatingNumber(a, b) || EqualBool(a, b) || EqualString(a, b) || a == b; }
     222    private static bool EqualIntegerNumber(object a, object b) { return a is int && b is int && (int)a == (int)b; }
     223    private static bool EqualFloatingNumber(object a, object b) { return a is double && b is double && (double)a == (double)b; }
    199224    private static bool EqualBool(object a, object b) { return a is bool && b is bool && (bool)a == (bool)b; }
    200225    private static bool EqualString(object a, object b) { return a is string && b is string && ((string)a).Equals((string)b); }
     
    208233      try {
    209234        stack.Push(func(a));
    210       }
    211       catch (Exception) {
     235      } catch (Exception) {
    212236        stack.Push(a);
    213237        throw;
     
    222246      try {
    223247        stack.Push(func(a, b));
    224       }
    225       catch (Exception) {
     248      } catch (Exception) {
    226249        stack.Push(b);
    227250        stack.Push(a);
     
    238261      try {
    239262        stack.Push(func(a, b, c));
    240       }
    241       catch (Exception) {
     263      } catch (Exception) {
    242264        stack.Push(a);
    243265        stack.Push(b);
Note: See TracChangeset for help on using the changeset viewer.