Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10864 for stable


Ignore:
Timestamp:
05/21/14 10:10:29 (11 years ago)
Author:
abeham
Message:

#2106: merged r10324, r10477, r10787 to stable

Location:
stable
Files:
9 edited
2 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Collections/3.3/HeuristicLab.Collections-3.3.csproj

    r9000 r10864  
    157157  </ItemGroup>
    158158  <ItemGroup>
     159    <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj">
     160      <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project>
     161      <Name>HeuristicLab.Common-3.3</Name>
     162    </ProjectReference>
    159163    <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">
    160164      <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>
  • stable/HeuristicLab.Collections/3.3/ObservableArray.cs

    r9456 r10864  
    2525using System.ComponentModel;
    2626using System.Linq;
     27using HeuristicLab.Common;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
     
    168169        Array.Clear(array, index, length);
    169170        OnPropertyChanged("Item[]");
    170         OnItemsReplaced(GetIndexedItems(index, length), oldItems); 
     171        OnItemsReplaced(GetIndexedItems(index, length), oldItems);
    171172      }
    172173    }
     
    205206      if (array.Length > 1) {
    206207        IndexedItem<T>[] oldItems = GetIndexedItems();
    207         Array.Sort<T>(array);
     208        array.StableSort();
    208209        OnPropertyChanged("Item[]");
    209210        OnItemsMoved(GetIndexedItems(), oldItems);
     
    213214      if (array.Length > 1) {
    214215        IndexedItem<T>[] oldItems = GetIndexedItems();
    215         Array.Sort<T>(array, comparison);
     216        array.StableSort(comparison);
    216217        OnPropertyChanged("Item[]");
    217218        OnItemsMoved(GetIndexedItems(), oldItems);
     
    221222      if (array.Length > 1) {
    222223        IndexedItem<T>[] oldItems = GetIndexedItems();
    223         Array.Sort<T>(array, comparer);
     224        array.StableSort(comparer);
    224225        OnPropertyChanged("Item[]");
    225226        OnItemsMoved(GetIndexedItems(), oldItems);
     
    229230      if (length > 1) {
    230231        IndexedItem<T>[] oldItems = GetIndexedItems(index, length);
    231         Array.Sort<T>(array, index, length);
     232        array.StableSort(index, length);
    232233        OnPropertyChanged("Item[]");
    233234        OnItemsMoved(GetIndexedItems(index, length), oldItems);
     
    237238      if (length > 1) {
    238239        IndexedItem<T>[] oldItems = GetIndexedItems(index, length);
    239         Array.Sort<T>(array, index, length, comparer);
     240        array.StableSort(index, length, comparer);
    240241        OnPropertyChanged("Item[]");
    241242        OnItemsMoved(GetIndexedItems(index, length), oldItems);
  • stable/HeuristicLab.Collections/3.3/ObservableList.cs

    r9456 r10864  
    2525using System.ComponentModel;
    2626using System.Linq;
     27using HeuristicLab.Common;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
     
    320321      if (list.Count > 1) {
    321322        IndexedItem<T>[] oldItems = GetIndexedItems();
    322         list.Sort();
     323        list.StableSort();
    323324        OnItemsMoved(GetIndexedItems(), oldItems);
    324325        OnPropertyChanged("Item[]");
     
    328329      if (list.Count > 1) {
    329330        IndexedItem<T>[] oldItems = GetIndexedItems();
    330         list.Sort(comparison);
     331        list.StableSort(comparison);
    331332        OnItemsMoved(GetIndexedItems(), oldItems);
    332333        OnPropertyChanged("Item[]");
     
    336337      if (list.Count > 1) {
    337338        IndexedItem<T>[] oldItems = GetIndexedItems();
    338         list.Sort(comparer);
     339        list.StableSort(comparer);
    339340        OnItemsMoved(GetIndexedItems(), oldItems);
    340341        OnPropertyChanged("Item[]");
     
    344345      if (count > 1) {
    345346        IndexedItem<T>[] oldItems = GetIndexedItems(index, count);
    346         list.Sort(index, count, comparer);
     347        list.StableSort(index, count, comparer);
    347348        OnItemsMoved(GetIndexedItems(index, count), oldItems);
    348349        OnPropertyChanged("Item[]");
  • stable/HeuristicLab.Collections/3.3/Plugin.cs.frame

    r10032 r10864  
    2929  [PluginFile("HeuristicLab.Collections-3.3.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.Persistence", "3.3")]
     31  [PluginDependency("HeuristicLab.Common", "3.3")]
    3132  public class HeuristicLabCollectionsPlugin : PluginBase {
    3233  }
  • stable/HeuristicLab.Common/3.3/ArrayExtensions.cs

    r10324 r10864  
    2626namespace HeuristicLab.Common {
    2727  public static class ArrayExtensions {
    28     public static void StableSort<T>(this T[] values) {
    29       values.StableSort(0, values.Length);
     28
     29    public static void StableSort<T>(this T[] values, Comparison<T> comparison) {
     30      values.StableSort(new StableSortComparer<T>(comparison));
    3031    }
    3132
    32     public static void StableSort<T>(this T[] values, int index, int count) {
    33       var sortedArray = values.Skip(index).Take(count).OrderBy(x => x).ToArray();
    34       Array.ConstrainedCopy(sortedArray, 0, values, index, count);
     33    public static void StableSort<T>(this T[] values, IComparer<T> comparer = null) {
     34      var sorted = values.OrderBy(x => x, comparer ?? Comparer<T>.Default).ToArray();
     35      Array.ConstrainedCopy(sorted, 0, values, 0, values.Length);
    3536    }
    3637
    37     public static void StableSort<T>(this T[] values, IComparer<T> comparer) {
    38       values.StableSort(0, values.Length, comparer);
     38    public static void StableSort<T>(this T[] values, int index, int length, Comparison<T> comparison) {
     39      values.StableSort(index, length, new StableSortComparer<T>(comparison));
    3940    }
    4041
    41     public static void StableSort<T>(this T[] values, int index, int count, IComparer<T> comparer) {
    42       var sortedArray = values.Skip(index).Take(count).OrderBy(x => x, comparer).ToArray();
    43       Array.ConstrainedCopy(sortedArray, 0, values, index, count);
     42    public static void StableSort<T>(this T[] values, int index, int length, IComparer<T> comparer = null) {
     43      if (index < 0) throw new ArgumentOutOfRangeException("index is less than zero.");
     44      if (length < 0) throw new ArgumentOutOfRangeException("length is less than zero.");
     45      if (index + length > values.Length) throw new ArgumentException("index and length do not specify a valid range in the array.");
     46      var sortedArray = values.Skip(index).Take(length).OrderBy(x => x, comparer ?? Comparer<T>.Default).ToArray();
     47      Array.ConstrainedCopy(sortedArray, 0, values, index, length);
    4448    }
    4549
    46     public static void StableSort<T>(this T[] values, Comparison<T> comparison) {
    47       values.StableSort(0, values.Length, comparison);
    48     }
    49 
    50     public static void StableSort<T>(this T[] values, int index, int count, Comparison<T> comparison) {
    51       var sortedArray = values.Skip(index).Take(count).OrderBy(x => x, new StableSortComparer<T>(comparison)).ToArray();
    52       Array.ConstrainedCopy(sortedArray, 0, values, index, count);
    53     }
    54 
    55     public class StableSortComparer<T> : IComparer<T> {
     50    private class StableSortComparer<T> : IComparer<T> {
    5651      public StableSortComparer(Comparison<T> comparison) {
    5752        this.comparison = comparison;
  • stable/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj

    r9079 r10864  
    124124    <Compile Include="Content\IStorableContent.cs" />
    125125    <Compile Include="Constants.cs" />
     126    <Compile Include="ArrayExtensions.cs" />
     127    <Compile Include="ListExtensions.cs" />
    126128    <Compile Include="Point2D.cs" />
    127129    <Compile Include="EnumerableExtensions.cs" />
  • stable/HeuristicLab.Common/3.3/ListExtensions.cs

    r10324 r10864  
    2626namespace HeuristicLab.Common {
    2727  public static class ListExtensions {
    28     public static void StableSort<T>(this List<T> values) {
    29       values.StableSort(0, values.Count);
     28
     29    public static void StableSort<T>(this List<T> values, Comparison<T> comparison) {
     30      values.StableSort(new StableSortComparer<T>(comparison));
    3031    }
    3132
    32     public static void StableSort<T>(this List<T> values, int index, int count) {
    33       var orderedList = values.Skip(index).Take(count).OrderBy(x => x).ToList();
    34       values.Clear();
    35       values.AddRange(orderedList);
    36     }
    37 
    38     public static void StableSort<T>(this List<T> values, IComparer<T> comparer) {
    39       values.StableSort(0, values.Count, comparer);
    40     }
    41 
    42     public static void StableSort<T>(this List<T> values, int index, int count, IComparer<T> comparer) {
    43       var orderedList = values.OrderBy(x => x, comparer).ToList();
    44       values.Clear();
    45       values.AddRange(orderedList);
    46     }
    47 
    48     public static void StableSort<T>(this List<T> values, Comparison<T> comparison) {
    49       values.StableSort(0, values.Count, comparison);
     33    public static void StableSort<T>(this List<T> values, IComparer<T> comparer = null) {
     34      int i = 0;
     35      foreach (var e in values.OrderBy(x => x, comparer ?? Comparer<T>.Default))
     36        values[i++] = e;
    5037    }
    5138
    5239    public static void StableSort<T>(this List<T> values, int index, int count, Comparison<T> comparison) {
    53       var orderedList = values.OrderBy(x => x, new StableSortComparer<T>(comparison)).ToList();
    54       values.Clear();
    55       values.AddRange(orderedList);
     40      values.StableSort(index, count, new StableSortComparer<T>(comparison));
    5641    }
    5742
    58     public class StableSortComparer<T> : IComparer<T> {
     43    public static void StableSort<T>(this List<T> values, int index, int count, IComparer<T> comparer = null) {
     44      if (index < 0) throw new ArgumentOutOfRangeException("index is less than zero.");
     45      if (count < 0) throw new ArgumentOutOfRangeException("count is less than zero.");
     46      if (index + count > values.Count) throw new ArgumentException("index and count do not specify a valid range in the List<T>.");
     47      var orderedList = values.Skip(index).Take(count).OrderBy(x => x, comparer ?? Comparer<T>.Default);
     48      int i = index;
     49      foreach (var e in orderedList)
     50        values[i++] = e;
     51    }
     52
     53    private class StableSortComparer<T> : IComparer<T> {
    5954      public StableSortComparer(Comparison<T> comparison) {
    6055        this.comparison = comparison;
  • stable/HeuristicLab.Tests

  • stable/HeuristicLab.Tests/HeuristicLab-3.3/SamplesTest.cs

    r10592 r10864  
    841841      ts.SetSeedRandomly.Value = false;
    842842      RunAlgorithm(ts);
    843       Assert.AreEqual(6441, GetDoubleResult(ts, "BestQuality"));
    844       Assert.AreEqual(7401.666666666667, GetDoubleResult(ts, "CurrentAverageQuality"));
    845       Assert.AreEqual(8418, GetDoubleResult(ts, "CurrentWorstQuality"));
     843      Assert.AreEqual(6294, GetDoubleResult(ts, "BestQuality"));
     844      Assert.AreEqual(7380.0386666666664, GetDoubleResult(ts, "CurrentAverageQuality"));
     845      Assert.AreEqual(8328, GetDoubleResult(ts, "CurrentWorstQuality"));
    846846      Assert.AreEqual(750000, GetIntResult(ts, "EvaluatedMoves"));
    847847    }
     
    912912      vrp.SetSeedRandomly.Value = false;
    913913      RunAlgorithm(vrp);
    914       Assert.AreEqual(1436, GetDoubleResult(vrp, "BestQuality"));
    915       Assert.AreEqual(2132.2478893442621, GetDoubleResult(vrp, "CurrentAverageQuality"));
    916       Assert.AreEqual(4176.0, GetDoubleResult(vrp, "CurrentWorstQuality"));
    917       Assert.AreEqual(119011, GetIntResult(vrp, "EvaluatedMoves"));
     914      Assert.AreEqual(1473, GetDoubleResult(vrp, "BestQuality"));
     915      Assert.AreEqual(2102.1192622950812, GetDoubleResult(vrp, "CurrentAverageQuality"));
     916      Assert.AreEqual(4006, GetDoubleResult(vrp, "CurrentWorstQuality"));
     917      Assert.AreEqual(119072, GetIntResult(vrp, "EvaluatedMoves"));
    918918    }
    919919
  • stable/HeuristicLab.Tests/TestRandom.cs

    r9456 r10864  
    6161
    6262    public TestRandom(int[] intNumbers, double[] doubleNumbers) {
    63       if (intNumbers == null) intNumbers = new int[0];
     63      if (intNumbers == null) this.intNumbers = new int[0];
    6464      else this.intNumbers = intNumbers;
    65       if (doubleNumbers == null) doubleNumbers = new double[0];
     65      if (doubleNumbers == null) this.doubleNumbers = new double[0];
    6666      else this.doubleNumbers = doubleNumbers;
    6767      nextIntIndex = 0;
Note: See TracChangeset for help on using the changeset viewer.