Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12701


Ignore:
Timestamp:
07/09/15 23:11:18 (9 years ago)
Author:
abeham
Message:

#2319:

  • Some code cleanup in LinearLinkage and updates to the documentation
  • Fixed operator discovery in multi*operators
  • Fixed bug in MultiLLEManipulator with respect to successful offspring analysis
Location:
trunk/sources/HeuristicLab.Encodings.LinearLinkageEncoding/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Crossovers/MultiLLECrossover.cs

    r12286 r12701  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Reflection;
    2526using HeuristicLab.Collections;
    2627using HeuristicLab.Common;
     
    6162      ChildParameter.ActualName = "LLE";
    6263
    63       foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(ILinearLinkageCrossover))) {
     64      foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(ILinearLinkageCrossover), typeof(LinearLinkageEncoding).Assembly)) {
    6465        if (!typeof(MultiOperator<ILinearLinkageCrossover>).IsAssignableFrom(type))
    6566          Operators.Add((ILinearLinkageCrossover)Activator.CreateInstance(type), true);
  • trunk/sources/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/LinearLinkage.cs

    r12650 r12701  
    7777
    7878    /// <summary>
    79     /// This method parses the encoded array and gathers all items that
    80     /// belong to the same group as element <paramref name="index"/>.
    81     /// </summary>
    82     /// <param name="index">The element whose group should be returned.</param>
     79    /// This method parses the encoded array and gathers all elements
     80    /// that belong to the same group as element <paramref name="index"/>.
     81    /// </summary>
     82    /// <param name="index">The element whose group should be returned.
     83    /// </param>
    8384    /// <returns>The element at <paramref name="index"/> and all other
    8485    /// elements in the same group.</returns>
    8586    public IEnumerable<int> GetGroup(int index) {
    86       // return current element
    87       yield return index;
    88       var next = array[index];
    89       if (next == index) yield break;
    90       int prev;
    91       // return succeeding elements in group
    92       do {
    93         yield return next;
    94         prev = next;
    95         next = array[next];
    96       } while (next != prev);
    97       next = array[index];
    98       // return preceding elements in group
    99       for (prev = index - 1; prev >= 0; prev--) {
    100         if (array[prev] != next) continue;
    101         next = prev;
    102         yield return next;
    103       }
    104     }
    105 
    106     /// <summary>
    107     /// This method parses the encoded array and gathers the item itself as
    108     /// well as subsequent items that belong to the same group as element
    109     /// <paramref name="index"/>.
    110     /// </summary>
    111     /// <param name="index">The element from which items in the group should
    112     /// be returned.</param>
    113     /// <returns>The element at <paramref name="index"/> and all subsequent
     87      foreach (var n in GetGroupForward(index))
     88        yield return n;
     89      // the element index has already been yielded
     90      foreach (var n in GetGroupBackward(index).Skip(1))
     91        yield return n;
     92    }
     93
     94    /// <summary>
     95    /// This method parses the encoded array and gathers the element
     96    /// <paramref name="index"/> as well as subsequent elements that
     97    /// belong to the same group.
     98    /// </summary>
     99    /// <param name="index">The element from which subsequent (having a
     100    /// larger number) elements in the group should be returned.
     101    /// </param>
     102    /// <returns>The element <paramref name="index"/> and all subsequent
    114103    /// elements in the same group.</returns>
    115104    public IEnumerable<int> GetGroupForward(int index) {
     
    123112        next = array[next];
    124113      } while (next != prev);
     114    }
     115
     116    /// <summary>
     117    /// This method parses the encoded array and gathers the element
     118    /// given <paramref name="index"/> as well as preceeding elements that
     119    /// belong to the same group.
     120    /// </summary>
     121    /// <remarks>
     122    /// Warning, this code has performance O(index) as the array has to
     123    /// be fully traversed backwards from the given index.
     124    /// </remarks>
     125    /// <param name="index">The element from which preceeding (having a
     126    /// smaller number) elements in the group should be returned.
     127    /// </param>
     128    /// <returns>The element <paramref name="index"/> and all preceeding
     129    /// elements in the same group.</returns>
     130    public IEnumerable<int> GetGroupBackward(int index) {
     131      yield return index;
     132      var next = array[index];
     133      // return preceding elements in group
     134      for (var prev = index - 1; prev >= 0; prev--) {
     135        if (array[prev] != next) continue;
     136        next = prev;
     137        yield return next;
     138      }
    125139    }
    126140
  • trunk/sources/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Manipulators/MultiLLEManipulator.cs

    r12288 r12701  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Reflection;
    2526using HeuristicLab.Collections;
    2627using HeuristicLab.Common;
     
    5354      : base() {
    5455      Parameters.Add(new LookupParameter<LinearLinkage>("LLE", "The encoding vector that is to be manipulated."));
    55       foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(ILinearLinkageManipulator))) {
     56      foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(ILinearLinkageManipulator), typeof(LinearLinkageEncoding).Assembly)) {
    5657        if (!typeof(MultiOperator<ILinearLinkageManipulator>).IsAssignableFrom(type))
    5758          Operators.Add((ILinearLinkageManipulator)Activator.CreateInstance(type), true);
     
    5960      Operators.SetItemCheckedState(Operators.OfType<SwapItemManipulator>().First(), false);
    6061      Operators.SetItemCheckedState(Operators.OfType<GraftManipulator>().First(), false);
    61       SelectedOperatorParameter.ActualName = "SelectedManipulatorOperator";
     62      SelectedOperatorParameter.ActualName = "SelectedManipulationOperator";
    6263    }
    6364
Note: See TracChangeset for help on using the changeset viewer.