Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/14/12 18:58:15 (12 years ago)
Author:
gkronber
Message:

#1847 merged r8205:8635 from trunk into branch

Location:
branches/GP-MoveOperators
Files:
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/GP-MoveOperators

  • branches/GP-MoveOperators/HeuristicLab.Common/3.3/EnumerableStatisticExtensions.cs

    r7259 r8660  
    4545        return (valuesArr[(n / 2) - 1] + valuesArr[n / 2]) / 2.0;
    4646      }
     47    }
     48
     49    /// <summary>
     50    /// Calculates the range (max - min) of the enumeration.
     51    /// </summary>
     52    /// <param name="values"></param>
     53    /// <returns></returns>
     54    public static double Range(this IEnumerable<double> values) {
     55      double min = double.PositiveInfinity;
     56      double max = double.NegativeInfinity;
     57      int i = 0;
     58      foreach (var e in values) {
     59        if (min > e) min = e;
     60        if (max < e) max = e;
     61        i++;
     62      }
     63      if (i < 1) throw new ArgumentException("The enumerable must contain at least two elements", "values");
     64      return max - min;
    4765    }
    4866
     
    105123
    106124    public static IEnumerable<double> LimitToRange(this IEnumerable<double> values, double min, double max) {
     125      if (min > max) throw new ArgumentException(string.Format("Minimum {0} is larger than maximum {1}.", min, max));
    107126      foreach (var x in values) {
    108127        if (double.IsNaN(x)) yield return (max + min) / 2.0;
  • branches/GP-MoveOperators/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj

    r8085 r8660  
    124124    <Compile Include="Content\IStorableContent.cs" />
    125125    <Compile Include="Constants.cs" />
     126    <Compile Include="Point2D.cs" />
    126127    <Compile Include="EnumerableExtensions.cs" />
    127128    <Compile Include="MatrixExtensions.cs" />
     
    179180  -->
    180181  <PropertyGroup>
    181     <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
     182   <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
    182183set ProjectDir=$(ProjectDir)
    183184set SolutionDir=$(SolutionDir)
     
    186187call PreBuildEvent.cmd
    187188</PreBuildEvent>
     189<PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
     190export ProjectDir=$(ProjectDir)
     191export SolutionDir=$(SolutionDir)
     192
     193$SolutionDir/PreBuildEvent.sh
     194</PreBuildEvent>
    188195  </PropertyGroup>
    189196</Project>
  • branches/GP-MoveOperators/HeuristicLab.Common/3.3/ObjectExtensions.cs

    r8206 r8660  
    3535    }
    3636
    37     public static IEnumerable<object> GetObjectGraphObjects(this object obj, HashSet<string> excludedMembers = null, bool excludeStaticMembers = false) {
     37    public static IEnumerable<object> GetObjectGraphObjects(this object obj, HashSet<object> excludedMembers = null, bool excludeStaticMembers = false) {
    3838      if (obj == null) return Enumerable.Empty<object>();
    39       if (excludedMembers == null) excludedMembers = new HashSet<string>();
     39      if (excludedMembers == null) excludedMembers = new HashSet<object>();
    4040
    4141      var objects = new HashSet<object>();
     
    4848
    4949        foreach (object o in GetChildObjects(current, excludedMembers, excludeStaticMembers)) {
    50           if (o != null && !objects.Contains(o) && !ExcludeType(o.GetType()))
    51             stack.Push(o);
     50          if (o == null) continue;
     51          if (ExcludeType(o.GetType())) continue;
     52          if (objects.Contains(o)) continue;
     53          stack.Push(o);
    5254        }
    5355      }
     
    6365    ///   * string, decimal, DateTime
    6466    ///   * Arrays of types not collected
    65     ///   
    66     /// Dictionaries and HashSets are treated specially, because it is cheaper to iterate over their keys and values
    67     /// compared to traverse their internal data structures.
    6867    /// </summary>
    6968    private static bool ExcludeType(Type type) {
    7069      return type.IsPrimitive ||
    7170             type == typeof(string) ||
     71             type == typeof(string[]) ||
    7272             type == typeof(decimal) ||
     73             type == typeof(decimal[]) ||
    7374             type == typeof(DateTime) ||
     75             type == typeof(DateTime[]) ||
    7476             typeof(Delegate).IsAssignableFrom(type) ||
    7577             typeof(Pointer).IsAssignableFrom(type) ||
    76              type == typeof(string[]) ||
    77              type == typeof(DateTime[]) ||
     78             type == typeof(System.Reflection.Emit.SignatureHelper) ||
    7879             (type.HasElementType && ExcludeType(type.GetElementType()));
    7980    }
    80     private static IEnumerable<object> GetChildObjects(object obj, HashSet<string> excludedMembers, bool excludeStaticMembers) {
     81
     82    private static IEnumerable<object> GetChildObjects(object obj, HashSet<object> excludedMembers, bool excludeStaticMembers) {
    8183      Type type = obj.GetType();
    8284
     
    8486        PropertyInfo info = type.GetProperty("Value");
    8587        object value = info.GetValue(obj, null);
    86         if (value != null) yield return value;
     88        if (value != null && !excludedMembers.Contains(value))
     89          yield return value;
    8790      } else if (type.IsSubclassOfRawGeneric(typeof(Dictionary<,>)) ||
    8891           type.IsSubclassOfRawGeneric(typeof(SortedDictionary<,>)) ||
     
    9396           obj is Hashtable) {
    9497        var dictionary = obj as IDictionary;
    95         foreach (object value in dictionary.Keys)
     98        foreach (object value in dictionary.Keys) {
     99          if (excludedMembers.Contains(value)) continue;
    96100          yield return value;
    97         foreach (object value in dictionary.Values)
     101        }
     102        foreach (object value in dictionary.Values) {
     103          if (excludedMembers.Contains(value)) continue;
    98104          yield return value;
     105        }
    99106      } else if (type.IsArray || type.IsSubclassOfRawGeneric(typeof(HashSet<>))) {
    100107        var enumerable = obj as IEnumerable;
    101         foreach (var value in enumerable)
     108        foreach (var value in enumerable) {
     109          if (excludedMembers.Contains(value)) continue;
    102110          yield return value;
     111        }
    103112      } else {
    104113        foreach (FieldInfo f in type.GetAllFields()) {
    105           if (excludedMembers.Contains(f.Name)) continue;
    106114          if (excludeStaticMembers && f.IsStatic) continue;
    107115          object fieldValue;
     
    112120            continue;
    113121          }
     122          if (excludedMembers.Contains(fieldValue)) continue;
    114123          yield return fieldValue;
    115124        }
  • branches/GP-MoveOperators/HeuristicLab.Common/3.3/Plugin.cs.frame

    r7259 r8660  
    2929  /// Plugin class for HeuristicLab.Common plugin.
    3030  /// </summary>
    31   [Plugin("HeuristicLab.Common", "3.3.6.$WCREV$")]
     31  [Plugin("HeuristicLab.Common", "3.3.7.$WCREV$")]
    3232  [PluginFile("HeuristicLab.Common-3.3.dll", PluginFileType.Assembly)]
    3333  public class HeuristicLabCommonPlugin : PluginBase {
  • branches/GP-MoveOperators/HeuristicLab.Common/3.3/Properties/AssemblyInfo.cs.frame

    r7259 r8660  
    5454// by using the '*' as shown below:
    5555[assembly: AssemblyVersion("3.3.0.0")]
    56 [assembly: AssemblyFileVersion("3.3.6.$WCREV$")]
     56[assembly: AssemblyFileVersion("3.3.7.$WCREV$")]
  • branches/GP-MoveOperators/HeuristicLab.Common/3.3/TypeExtensions.cs

    r7259 r8660  
    4949
    5050    public static IEnumerable<FieldInfo> GetAllFields(this Type type) {
    51       foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
     51      foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic))
    5252        yield return field;
    5353
    54       foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
     54      foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic))
    5555        yield return field;
    5656
Note: See TracChangeset for help on using the changeset viewer.