Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/04/13 10:18:18 (11 years ago)
Author:
ascheibe
Message:

#1886 fixed RealVectorEqualityComparer and added unit tests for caches

Location:
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/RealVectorEncoding/RealVectorEqualityComparer.cs

    r10026 r10104  
    4242
    4343    public override int GetHashCode(RealVector obj) {
    44       //compute FNV hash
    45       int h = 216613626;
    46 
    47       for (int i = 0; i < obj.Length; i++) {
    48         h = (h * 16777619) ^ obj[i].GetHashCode();
     44      unchecked {
     45        int hash = 17;
     46        for (int i = 0; i < obj.Length; i++) {
     47          hash = hash * 23 + obj[i].GetHashCode();
     48        }
     49        return hash;
    4950      }
    50       return h;
    5151    }
    5252  }
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/SolutionCache.cs

    r10090 r10104  
    2828
    2929namespace HeuristicLab.Analysis.SolutionCaching {
     30  //TODO: should implement a collection interface
    3031  [Item("SolutionCache", "Stores solutions generated by an algorithm.")]
    3132  [StorableClass]
     
    8889    }
    8990
     91    public virtual IEnumerable<TKey> Keys() {
     92      return solutionDictionary.Keys;
     93    }
     94
     95    public virtual IEnumerable<List<TValue>> Values() {
     96      return solutionDictionary.Values;
     97    }
     98
    9099    public virtual List<TKey> GetSolutionsFromGeneration(int generation) {
    91100      return solutionDictionary.Where(x => x.Value.Count(y => y.Generation == generation) != 0).Select(x => x.Key).ToList<TKey>();
Note: See TracChangeset for help on using the changeset viewer.