Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/03/15 11:18:07 (9 years ago)
Author:
bburlacu
Message:

#2276: Merged trunk changes.

Location:
branches/HeuristicLab.DatasetRefactor/sources
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DatasetRefactor/sources

  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Optimization

  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Optimization/3.3/Interfaces/ISimilarityBasedOperator.cs

    r12031 r12105  
    2424namespace HeuristicLab.Optimization {
    2525  public interface ISimilarityBasedOperator : IOperator {
    26     ISolutionSimilarityCalculator SimilarityCalculator { get; set; }
     26    IConstrainedValueParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { get; }
    2727  }
    2828}
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Optimization/3.3/Interfaces/ISingleObjectiveSolutionSimilarityCalculator.cs

    r12031 r12105  
    2020#endregion
    2121
     22using System;
     23
    2224namespace HeuristicLab.Optimization {
     25  // use HeuristicLab.Optimization.ISolutionSimilarityCalculator instead
     26  // BackwardsCompatibility3.3
     27  #region Backwards compatible code, remove with 3.4
    2328  /// <summary>
    2429  /// An interface which represents an operator for similarity calculation between single objective solutions.
    2530  /// </summary>
     31  [Obsolete("use HeuristicLab.Optimization.ISolutionSimilarityCalculator instead")]
    2632  public interface ISingleObjectiveSolutionSimilarityCalculator : ISolutionSimilarityCalculator, ISingleObjectiveOperator {
    27     string SolutionVariableName { get; set; }
    28     string QualityVariableName { get; set; }
     33
    2934  }
     35  #endregion
    3036}
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Optimization/3.3/Interfaces/ISolutionSimilarityCalculator.cs

    r12031 r12105  
    2828  /// </summary>
    2929  public interface ISolutionSimilarityCalculator : IItem, IEqualityComparer<IScope> {
     30    string SolutionVariableName { get; set; }
     31    string QualityVariableName { get; set; }
     32
    3033    /// <summary>
    3134    /// Calculates the similarity of two solutions.
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Optimization/3.3/RunCollectionModification/Calculator.cs

    r12031 r12105  
    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.