Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/BinaryVectorComparers/AverageBitBinaryVectorComparer.cs @ 7624

Last change on this file since 7624 was 7128, checked in by epitzer, 13 years ago

#1696 Integrate fitness landscape analysis plugins from Heureka! repository.

File size: 1.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using HeuristicLab.Common;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9using HeuristicLab.Encodings.BinaryVectorEncoding;
10
11namespace HeuristicLab.Problems.NK {
12 
13  [Item("Average Bit Binary Vector Comparer", "Compares two binary vectors by their average positive bit location")]
14  [StorableClass]
15  public sealed class AverageBitBinaryVectorComparer : BinaryVectorComparer {
16   
17    [StorableConstructor]
18    protected AverageBitBinaryVectorComparer(bool deserializing) : base(deserializing) { }
19    protected AverageBitBinaryVectorComparer(AverageBitBinaryVectorComparer original, Cloner cloner)
20      : base(original, cloner) {
21    }
22    public AverageBitBinaryVectorComparer() { }
23    public override IDeepCloneable Clone(Cloner cloner) {
24      return new AverageBitBinaryVectorComparer(this, cloner);
25    }
26
27    public static double AverageBit(BinaryVector x) {     
28      return x.Select((b, i) => new { b, i }).Where(v => v.b).Average(v => v.i);
29    }
30
31    public override int Compare(BinaryVector x, BinaryVector y) {
32      return (AverageBit(x) - AverageBit(y)).CompareTo(0);     
33    }   
34  }
35}
Note: See TracBrowser for help on using the repository browser.