[12285] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17181] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[12285] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
[17097] | 27 | using HEAL.Attic;
|
---|
[12285] | 28 | using HeuristicLab.Random;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Encodings.LinearLinkageEncoding {
|
---|
| 31 | [Item("Lowest Index Max Crossover", "The Lowest Index Max Crossover (LIMX) is implemented as described in Ülker, Ö., Özcan, E., Korkmaz, E. E. 2007. Linear linkage encoding in grouping problems: applications on graph coloring and timetabling. In Practice and Theory of Automated Timetabling VI, pp. 347-363. Springer Berlin Heidelberg.")]
|
---|
[17097] | 32 | [StorableType("CDD94469-9B80-4FBB-AC40-DADE1A9462F1")]
|
---|
[12285] | 33 | public sealed class LowestIndexMaxCrossover : LinearLinkageCrossover {
|
---|
| 34 |
|
---|
| 35 | [StorableConstructor]
|
---|
[17097] | 36 | private LowestIndexMaxCrossover(StorableConstructorFlag _) : base(_) { }
|
---|
[12285] | 37 | private LowestIndexMaxCrossover(LowestIndexMaxCrossover original, Cloner cloner) : base(original, cloner) { }
|
---|
| 38 | public LowestIndexMaxCrossover() { }
|
---|
| 39 |
|
---|
| 40 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 41 | return new LowestIndexMaxCrossover(this, cloner);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | public static LinearLinkage Apply(IRandom random, ItemArray<LinearLinkage> parents) {
|
---|
| 45 | var len = parents[0].Length;
|
---|
[14475] | 46 | var child = LinearLinkage.SingleElementGroups(len);
|
---|
[12288] | 47 | var remaining = new SortedSet<int>(Enumerable.Range(0, len));
|
---|
[12285] | 48 | do {
|
---|
[12288] | 49 | var groups = parents.Select(x => x.GetGroupForward(remaining.Min).Where(y => remaining.Contains(y)).ToList()).ToList();
|
---|
| 50 | var max = groups.Select((v, idx) => Tuple.Create(idx, v.Count)).MaxItems(x => x.Item2).SampleRandom(random).Item1;
|
---|
| 51 | var i = groups[max][0];
|
---|
| 52 | for (var k = 1; k < groups[max].Count; k++) {
|
---|
| 53 | child[i] = groups[max][k];
|
---|
| 54 | remaining.Remove(i);
|
---|
| 55 | i = child[i];
|
---|
| 56 | }
|
---|
| 57 | child[i] = i;
|
---|
| 58 | remaining.Remove(i);
|
---|
[12285] | 59 | } while (remaining.Count > 0);
|
---|
| 60 |
|
---|
| 61 | return child;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | protected override LinearLinkage Cross(IRandom random, ItemArray<LinearLinkage> parents) {
|
---|
| 65 | return Apply(random, parents);
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|