Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Crossovers/LowestIndexFirstCrossover.cs @ 12285

Last change on this file since 12285 was 12285, checked in by abeham, 9 years ago

#2319: Added branch for linear linkage encoding (LLE-e)

File size: 2.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using System.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Encodings.LinearLinkageEncoding {
29  [Item("Lowest Index First Crossover", "The Lowest Index First Crossover (LIFX) 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.")]
30  [StorableClass]
31  public sealed class LowestIndexFirstCrossover : LinearLinkageCrossover {
32
33    [StorableConstructor]
34    private LowestIndexFirstCrossover(bool deserializing) : base(deserializing) { }
35    private LowestIndexFirstCrossover(LowestIndexFirstCrossover original, Cloner cloner) : base(original, cloner) { }
36    public LowestIndexFirstCrossover() { }
37
38    public override IDeepCloneable Clone(Cloner cloner) {
39      return new LowestIndexFirstCrossover(this, cloner);
40    }
41
42    public static LinearLinkage Apply(IRandom random, ItemArray<LinearLinkage> parents) {
43      var len = parents[0].Length;
44      var child = new LinearLinkage(len);
45      var childGroup = new List<HashSet<int>>();
46      var currentParent = random.Next(parents.Length);
47      var remaining = new HashSet<int>(Enumerable.Range(0, len));
48      do {
49        var i = remaining.Min();
50        var group = new HashSet<int>(parents[currentParent].GetGroupForward(i));
51        group.IntersectWith(remaining);
52        childGroup.Add(group);
53        remaining.ExceptWith(group);
54        currentParent = (currentParent + 1) % parents.Length;
55      } while (remaining.Count > 0);
56
57      child.SetGroups(childGroup);
58      return child;
59    }
60
61    protected override LinearLinkage Cross(IRandom random, ItemArray<LinearLinkage> parents) {
62      return Apply(random, parents);
63    }
64  }
65}
Note: See TracBrowser for help on using the repository browser.