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.3 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("Lexicographic Binary Vector Comparer", "Compares two binary vectors lexicographically")]
|
---|
14 | [StorableClass]
|
---|
15 | public sealed class LexicographicBinaryVectorComparer : BinaryVectorComparer {
|
---|
16 |
|
---|
17 | [StorableConstructor]
|
---|
18 | protected LexicographicBinaryVectorComparer(bool deserializing) : base(deserializing) { }
|
---|
19 | protected LexicographicBinaryVectorComparer(LexicographicBinaryVectorComparer original, Cloner cloner)
|
---|
20 | : base(original, cloner) {
|
---|
21 | }
|
---|
22 | public LexicographicBinaryVectorComparer() { }
|
---|
23 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
24 | return new LexicographicBinaryVectorComparer(this, cloner);
|
---|
25 | }
|
---|
26 |
|
---|
27 | public override int Compare(BinaryVector x, BinaryVector y) {
|
---|
28 | for (int i = 0; i<Math.Min(x.Length, y.Length); i++) {
|
---|
29 | if (!x[i] && y[i])
|
---|
30 | return -1;
|
---|
31 | if (x[i] && !y[i])
|
---|
32 | return 1;
|
---|
33 | }
|
---|
34 | if (x.Length > y.Length)
|
---|
35 | return 1;
|
---|
36 | if (x.Length < y.Length)
|
---|
37 | return -1;
|
---|
38 | return 0;
|
---|
39 | }
|
---|
40 | }
|
---|
41 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.