Last change
on this file since 9760 was
8083,
checked in by mkommend, 13 years ago
|
#1877: Corrected errors detected in unit test in HeuristicLab.FitnessLandscapeAnalysis.
|
File size:
1.2 KB
|
Rev | Line | |
---|
[8083] | 1 | using System.Linq;
|
---|
| 2 | using HeuristicLab.Common;
|
---|
[7128] | 3 | using HeuristicLab.Core;
|
---|
[8083] | 4 | using HeuristicLab.Encodings.BinaryVectorEncoding;
|
---|
[7128] | 5 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 6 |
|
---|
| 7 | namespace HeuristicLab.Problems.NK {
|
---|
[8083] | 8 |
|
---|
[7128] | 9 | [Item("Average Bit Binary Vector Comparer", "Compares two binary vectors by their average positive bit location")]
|
---|
| 10 | [StorableClass]
|
---|
| 11 | public sealed class AverageBitBinaryVectorComparer : BinaryVectorComparer {
|
---|
[8083] | 12 |
|
---|
[7128] | 13 | [StorableConstructor]
|
---|
[8083] | 14 | private AverageBitBinaryVectorComparer(bool deserializing) : base(deserializing) { }
|
---|
| 15 | private AverageBitBinaryVectorComparer(AverageBitBinaryVectorComparer original, Cloner cloner)
|
---|
[7128] | 16 | : base(original, cloner) {
|
---|
| 17 | }
|
---|
| 18 | public AverageBitBinaryVectorComparer() { }
|
---|
| 19 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 20 | return new AverageBitBinaryVectorComparer(this, cloner);
|
---|
| 21 | }
|
---|
| 22 |
|
---|
[8083] | 23 | public static double AverageBit(BinaryVector x) {
|
---|
[7128] | 24 | return x.Select((b, i) => new { b, i }).Where(v => v.b).Average(v => v.i);
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | public override int Compare(BinaryVector x, BinaryVector y) {
|
---|
[8083] | 28 | return (AverageBit(x) - AverageBit(y)).CompareTo(0);
|
---|
| 29 | }
|
---|
| 30 | }
|
---|
[7128] | 31 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.