Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/06/15 22:41:24 (10 years ago)
Author:
abeham
Message:

#2319:

  • Changed encoding to represent linkages in LLE (as opposed to LLE-e)
  • Added GraftManipulator
  • Added repair procedure
  • Improved performance of some crossovers
Location:
branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Crossovers
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Crossovers/GroupCrossover.cs

    r12285 r12288  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    5354      for (var i = 0; i < length; i++) {
    5455        if (endNodes.Contains(i)) continue;
    55         if (endNodes.Contains(p1[i]) && endNodes.Contains(p2[i])) {
     56        var p1End = endNodes.Contains(p1[i]);
     57        var p2End = endNodes.Contains(p2[i]);
     58        if ((p1End && p2End) || (!p1End && !p2End)) {
    5659          child[i] = random.NextDouble() < 0.5 ? p1[i] : p2[i];
    57         } else if (endNodes.Contains(p1[i])) {
     60        } else if (p1End) {
    5861          child[i] = p1[i];
    59         } else if (endNodes.Contains(p2[i])) {
     62        } else {
    6063          child[i] = p2[i];
    61         } else {
    62           var a = p1[i];
    63           var b = p2[i];
    64           while (true) {
    65             if (endNodes.Contains(p2[a])) {
    66               child[i] = p2[a];
    67               break;
    68             }
    69             if (endNodes.Contains(p1[b])) {
    70               child[i] = p1[b];
    71               break;
    72             }
    73             var tmp = b;
    74             b = p2[a];
    75             a = p1[tmp];
    76           }
    7764        }
    7865      }
     66      child.LinearizeTreeStructures();
    7967      return child;
    8068    }
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Crossovers/LowestIndexFirstCrossover.cs

    r12285 r12288  
    4242    public static LinearLinkage Apply(IRandom random, ItemArray<LinearLinkage> parents) {
    4343      var len = parents[0].Length;
     44      var p = random.Next(parents.Length);
    4445      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));
     46      var remaining = new SortedSet<int>(Enumerable.Range(0, len));
    4847      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;
     48        var i = remaining.Min;
     49        foreach (var g in parents[p].GetGroupForward(i)) {
     50          if (!remaining.Contains(g)) continue;
     51          child[i] = g;
     52          i = g;
     53          remaining.Remove(g);
     54        }
     55        child[i] = i;
     56        remaining.Remove(i);
     57
     58        p = (p + 1) % parents.Length;
    5559      } while (remaining.Count > 0);
    5660
    57       child.SetGroups(childGroup);
    5861      return child;
    5962    }
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Crossovers/LowestIndexMaxCrossover.cs

    r12285 r12288  
    4545      var len = parents[0].Length;
    4646      var child = new LinearLinkage(len);
    47       var childGroup = new List<HashSet<int>>();
    48       var remaining = new HashSet<int>(Enumerable.Range(0, len));
     47      var remaining = new SortedSet<int>(Enumerable.Range(0, len));
    4948      do {
    50         var i = remaining.Min();
    51         var groups = parents.Select(x => new HashSet<int>(x.GetGroupForward(i))).ToList();
    52         for (var k = 0; k < groups.Count; k++)
    53           groups[k].IntersectWith(remaining);
    54 
    55         var maxGroup = groups.Select((v, idx) => Tuple.Create(idx, v)).MaxItems(x => x.Item2.Count).SampleRandom(random).Item1;
    56         childGroup.Add(groups[maxGroup]);
    57         remaining.ExceptWith(groups[maxGroup]);
     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);
    5859      } while (remaining.Count > 0);
    5960
    60       child.SetGroups(childGroup);
    6161      return child;
    6262    }
Note: See TracChangeset for help on using the changeset viewer.