Last change
on this file since 7403 was
7128,
checked in by epitzer, 13 years ago
|
#1696 Integrate fitness landscape analysis plugins from Heureka! repository.
|
File size:
1.4 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Data;
|
---|
7 | using HeuristicLab.Common;
|
---|
8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
9 | using HeuristicLab.Encodings.BinaryVectorEncoding;
|
---|
10 |
|
---|
11 | namespace HeuristicLab.Problems.NK {
|
---|
12 |
|
---|
13 | [Item("Median Bit Binary Vector Comparer", "Compares two binary vectors by the median positive bit location")]
|
---|
14 | [StorableClass]
|
---|
15 | public sealed class MedianBitBinaryVectorComparer : BinaryVectorComparer {
|
---|
16 |
|
---|
17 | [StorableConstructor]
|
---|
18 | protected MedianBitBinaryVectorComparer(bool deserializing) : base(deserializing) { }
|
---|
19 | protected MedianBitBinaryVectorComparer(MedianBitBinaryVectorComparer original, Cloner cloner)
|
---|
20 | : base(original, cloner) {
|
---|
21 | }
|
---|
22 | public MedianBitBinaryVectorComparer() { }
|
---|
23 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
24 | return new MedianBitBinaryVectorComparer(this, cloner);
|
---|
25 | }
|
---|
26 |
|
---|
27 | public static int MedianBit(BinaryVector x) {
|
---|
28 | var activeIndices = x.Select((b, i) => new { b, i }).Where(v => v.b).ToList();
|
---|
29 | if (activeIndices.Count > 0)
|
---|
30 | return activeIndices[activeIndices.Count/2].i;
|
---|
31 | else
|
---|
32 | return 0;
|
---|
33 | }
|
---|
34 | public override int Compare(BinaryVector x, BinaryVector y) {
|
---|
35 | return MedianBit(x) - MedianBit(y);
|
---|
36 | }
|
---|
37 | }
|
---|
38 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.