Last change
on this file since 8250 was
8083,
checked in by mkommend, 13 years ago
|
#1877: Corrected errors detected in unit test in HeuristicLab.FitnessLandscapeAnalysis.
|
File size:
1.3 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 {
|
---|
| 8 |
|
---|
| 9 | [Item("Median Bit Binary Vector Comparer", "Compares two binary vectors by the median positive bit location")]
|
---|
| 10 | [StorableClass]
|
---|
| 11 | public sealed class MedianBitBinaryVectorComparer : BinaryVectorComparer {
|
---|
| 12 |
|
---|
| 13 | [StorableConstructor]
|
---|
[8083] | 14 | private MedianBitBinaryVectorComparer(bool deserializing) : base(deserializing) { }
|
---|
| 15 | private MedianBitBinaryVectorComparer(MedianBitBinaryVectorComparer original, Cloner cloner)
|
---|
[7128] | 16 | : base(original, cloner) {
|
---|
| 17 | }
|
---|
| 18 | public MedianBitBinaryVectorComparer() { }
|
---|
| 19 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 20 | return new MedianBitBinaryVectorComparer(this, cloner);
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | public static int MedianBit(BinaryVector x) {
|
---|
[8083] | 24 | var activeIndices = x.Select((b, i) => new { b, i }).Where(v => v.b).ToList();
|
---|
| 25 | if (activeIndices.Count > 0)
|
---|
| 26 | return activeIndices[activeIndices.Count / 2].i;
|
---|
[7128] | 27 | else
|
---|
| 28 | return 0;
|
---|
| 29 | }
|
---|
| 30 | public override int Compare(BinaryVector x, BinaryVector y) {
|
---|
| 31 | return MedianBit(x) - MedianBit(y);
|
---|
| 32 | }
|
---|
[8083] | 33 | }
|
---|
[7128] | 34 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.