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