Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12643


Ignore:
Timestamp:
07/07/15 13:52:18 (9 years ago)
Author:
abeham
Message:

#2319:

  • Added two new solution creators
  • Added swap2 neighborhood
  • Added license headers
  • Pruned usings
  • Fixed namespaces
Location:
branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3
Files:
8 added
10 edited
4 copied

Legend:

Unmodified
Added
Removed
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Creators/ExactGroupsLinearLinkageCreator.cs

    r12628 r12643  
    2020#endregion
    2121
    22 using System;
     22using System.Collections.Generic;
    2323using System.Linq;
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
     26using HeuristicLab.Data;
     27using HeuristicLab.Parameters;
    2628using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Random;
    2730
    28 namespace HeuristicLab.Encodings.LinearLinkageEncoding.Creators {
    29   [Item("Random Linear Linkage Creator", "Creates a random linear linkage LLE encoded solution.")]
     31namespace HeuristicLab.Encodings.LinearLinkageEncoding {
     32  [Item("Exactgroups Linear Linkage Creator", "Creates a random linear linkage LLE encoded solution with a given number of equal-sized groups.")]
    3033  [StorableClass]
    31   public sealed class RandomLinearLinkageCreator : LinearLinkageCreator {
     34  public sealed class ExactGroupsLinearLinkageCreator : LinearLinkageCreator {
     35
     36    public IValueLookupParameter<IntValue> ExactGroupsParameter {
     37      get { return (IValueLookupParameter<IntValue>)Parameters["ExactGroups"]; }
     38    }
     39
     40    public IntValue ExactGroups {
     41      get { return ExactGroupsParameter.Value; }
     42      set { ExactGroupsParameter.Value = value; }
     43    }
    3244
    3345    [StorableConstructor]
    34     private RandomLinearLinkageCreator(bool deserializing) : base(deserializing) { }
    35     private RandomLinearLinkageCreator(RandomLinearLinkageCreator original, Cloner cloner) : base(original, cloner) { }
    36     public RandomLinearLinkageCreator() { }
     46    private ExactGroupsLinearLinkageCreator(bool deserializing) : base(deserializing) { }
     47    private ExactGroupsLinearLinkageCreator(ExactGroupsLinearLinkageCreator original, Cloner cloner) : base(original, cloner) { }
     48
     49    public ExactGroupsLinearLinkageCreator() {
     50      Parameters.Add(new ValueLookupParameter<IntValue>("ExactGroups", "The exact number of equal-sized groups to create.", new IntValue(3)));
     51    }
    3752
    3853    public override IDeepCloneable Clone(Cloner cloner) {
    39       return new RandomLinearLinkageCreator(this, cloner);
     54      return new ExactGroupsLinearLinkageCreator(this, cloner);
     55    }
     56
     57    public static LinearLinkage Apply(IRandom random, int length, int groups) {
     58      var solution = new LinearLinkage(length);
     59      var groupNumbers = Enumerable.Range(0, length).Select(x => x % groups).Shuffle(random);
     60      var grouping = Enumerable.Range(0, groups).Select(x => new List<int>()).ToList();
     61      var idx = 0;
     62      foreach (var g in groupNumbers)
     63        grouping[g].Add(idx++);
     64
     65      solution.SetGroups(grouping);
     66      return solution;
    4067    }
    4168
    4269    protected override LinearLinkage Create(IRandom random, int length) {
    43       var solution = new LinearLinkage(length);
    44       var groups = Enumerable.Range(0, length).Select(x => Tuple.Create(x, random.Next(length)))
    45                                               .GroupBy(x => x.Item2)
    46                                               .Select(x => x.Select(y => y.Item1).ToList());
    47       solution.SetGroups(groups);
    48       return solution;
     70      var groups = ExactGroupsParameter.ActualValue.Value;
     71      return Apply(random, length, groups);
    4972    }
    5073  }
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Creators/MaxGroupsLinearLinkageCreator.cs

    r12628 r12643  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
     26using HeuristicLab.Data;
     27using HeuristicLab.Parameters;
    2628using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729
    28 namespace HeuristicLab.Encodings.LinearLinkageEncoding.Creators {
    29   [Item("Random Linear Linkage Creator", "Creates a random linear linkage LLE encoded solution.")]
     30namespace HeuristicLab.Encodings.LinearLinkageEncoding {
     31  [Item("Maxgroups Linear Linkage Creator", "Creates a random linear linkage LLE encoded solution with a given maximum number of groups.")]
    3032  [StorableClass]
    31   public sealed class RandomLinearLinkageCreator : LinearLinkageCreator {
     33  public sealed class MaxGroupsLinearLinkageCreator : LinearLinkageCreator {
     34
     35    public IValueLookupParameter<IntValue> MaxGroupsParameter {
     36      get { return (IValueLookupParameter<IntValue>)Parameters["MaxGroups"]; }
     37    }
     38
     39    public IntValue MaxGroups {
     40      get { return MaxGroupsParameter.Value; }
     41      set { MaxGroupsParameter.Value = value; }
     42    }
    3243
    3344    [StorableConstructor]
    34     private RandomLinearLinkageCreator(bool deserializing) : base(deserializing) { }
    35     private RandomLinearLinkageCreator(RandomLinearLinkageCreator original, Cloner cloner) : base(original, cloner) { }
    36     public RandomLinearLinkageCreator() { }
     45    private MaxGroupsLinearLinkageCreator(bool deserializing) : base(deserializing) { }
     46    private MaxGroupsLinearLinkageCreator(MaxGroupsLinearLinkageCreator original, Cloner cloner) : base(original, cloner) { }
     47
     48    public MaxGroupsLinearLinkageCreator() {
     49      Parameters.Add(new ValueLookupParameter<IntValue>("MaxGroups", "The maximum number of groups to create.", new IntValue(3)));
     50    }
    3751
    3852    public override IDeepCloneable Clone(Cloner cloner) {
    39       return new RandomLinearLinkageCreator(this, cloner);
     53      return new MaxGroupsLinearLinkageCreator(this, cloner);
    4054    }
    4155
    42     protected override LinearLinkage Create(IRandom random, int length) {
     56    public static LinearLinkage Apply(IRandom random, int length, int maxGroups) {
    4357      var solution = new LinearLinkage(length);
    44       var groups = Enumerable.Range(0, length).Select(x => Tuple.Create(x, random.Next(length)))
     58      var groups = Enumerable.Range(0, length).Select(x => Tuple.Create(x, random.Next(maxGroups)))
    4559                                              .GroupBy(x => x.Item2)
    4660                                              .Select(x => x.Select(y => y.Item1).ToList());
     
    4862      return solution;
    4963    }
     64
     65    protected override LinearLinkage Create(IRandom random, int length) {
     66      var maxGroups = MaxGroupsParameter.ActualValue.Value;
     67      return Apply(random, length, maxGroups);
     68    }
    5069  }
    5170}
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Creators/RandomLinearLinkageCreator.cs

    r12288 r12643  
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2727
    28 namespace HeuristicLab.Encodings.LinearLinkageEncoding.Creators {
    29   [Item("Random Linear Linkage Creator", "Creates a random linear linkage LLE encoded solution.")]
     28namespace HeuristicLab.Encodings.LinearLinkageEncoding {
     29  [Item("Random Linear Linkage Creator", "Creates a random linear linkage LLE encoded solution (similar to MaxGroups set to N).")]
    3030  [StorableClass]
    3131  public sealed class RandomLinearLinkageCreator : LinearLinkageCreator {
     
    4040    }
    4141
    42     protected override LinearLinkage Create(IRandom random, int length) {
     42    public static LinearLinkage Apply(IRandom random, int length) {
    4343      var solution = new LinearLinkage(length);
    4444      var groups = Enumerable.Range(0, length).Select(x => Tuple.Create(x, random.Next(length)))
     
    4848      return solution;
    4949    }
     50
     51    protected override LinearLinkage Create(IRandom random, int length) {
     52      return Apply(random, length);
     53    }
    5054  }
    5155}
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Crossovers/GroupCrossover.cs

    r12288 r12643  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/HeuristicLab.Encodings.LinearLinkageEncoding-3.3.csproj

    r12396 r12643  
    102102  </ItemGroup>
    103103  <ItemGroup>
     104    <Compile Include="Creators\ExactGroupsLinearLinkageCreator.cs" />
     105    <Compile Include="Creators\MaxGroupsLinearLinkageCreator.cs" />
    104106    <Compile Include="Creators\RandomLinearLinkageCreator.cs" />
    105107    <Compile Include="Crossovers\GreedyPartitionCrossover.cs" />
     
    108110    <Compile Include="Crossovers\MultiLLECrossover.cs" />
    109111    <Compile Include="Crossovers\SinglePointCrossover.cs" />
     112    <Compile Include="Interfaces\ILinearLinkageMoveOperator.cs" />
     113    <Compile Include="Interfaces\ILinearLinkageSwap2MoveOperator.cs" />
    110114    <Compile Include="Interfaces\ILinearLinkageCreator.cs" />
    111115    <Compile Include="LinearLinkage.cs" />
     
    118122    <Compile Include="Manipulators\MergeGroupManipulator.cs" />
    119123    <Compile Include="Manipulators\MultiLLEManipulator.cs" />
     124    <Compile Include="Moves\Swap\ExhaustiveSwap2MoveGenerator.cs" />
     125    <Compile Include="Moves\Swap\StochasticSwap2MultiMoveGenerator.cs" />
     126    <Compile Include="Moves\Swap\StochasticSwap2SingleMoveGenerator.cs" />
     127    <Compile Include="Moves\Swap\Swap2Move.cs" />
     128    <Compile Include="Moves\Swap\Swap2MoveGenerator.cs" />
     129    <Compile Include="Moves\Swap\Swap2MoveMaker.cs" />
    120130    <Compile Include="ShakingOperators\LLEShakingOperator.cs" />
    121131    <None Include="HeuristicLab.snk" />
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Interfaces/ILinearLinkageCrossover.cs

    r12285 r12643  
    1 using HeuristicLab.Core;
     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 HeuristicLab.Core;
    223using HeuristicLab.Optimization;
    324
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Interfaces/ILinearLinkageManipulator.cs

    r12285 r12643  
    1 using HeuristicLab.Core;
     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 HeuristicLab.Core;
    223using HeuristicLab.Optimization;
    324
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Interfaces/ILinearLinkageMoveOperator.cs

    r12628 r12643  
    2121
    2222using HeuristicLab.Core;
    23 using HeuristicLab.Data;
    2423using HeuristicLab.Optimization;
    2524
    2625namespace HeuristicLab.Encodings.LinearLinkageEncoding {
    27   public interface ILinearLinkageCreator : ISolutionCreator, ILinearLinkageOperator {
    28     IValueLookupParameter<IntValue> LengthParameter { get; }
     26  /// <summary>
     27  /// Move operators can be extended by deriving a new interface from this interface
     28  /// and implementing that derived interface in all move operators that belong to
     29  /// the same group of move operators.
     30  ///
     31  /// See <see cref="ILinearLinkageSwap2MoveOperator"/> for a reference implementation.
     32  /// </summary>
     33  public interface ILinearLinkageMoveOperator : IMoveOperator, ILinearLinkageOperator {
    2934    ILookupParameter<LinearLinkage> LLEParameter { get; }
    3035  }
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Interfaces/ILinearLinkageOperator.cs

    r12285 r12643  
    1 
     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
    222using HeuristicLab.Core;
    323
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Interfaces/ILinearLinkageShakingOperator.cs

    r12285 r12643  
    1 using HeuristicLab.Core;
     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 HeuristicLab.Core;
    223
    324namespace HeuristicLab.Encodings.LinearLinkageEncoding {
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Interfaces/ILinearLinkageSwap2MoveOperator.cs

    r12628 r12643  
    2121
    2222using HeuristicLab.Core;
    23 using HeuristicLab.Data;
    24 using HeuristicLab.Optimization;
    2523
    2624namespace HeuristicLab.Encodings.LinearLinkageEncoding {
    27   public interface ILinearLinkageCreator : ISolutionCreator, ILinearLinkageOperator {
    28     IValueLookupParameter<IntValue> LengthParameter { get; }
    29     ILookupParameter<LinearLinkage> LLEParameter { get; }
     25  public interface ILinearLinkageSwap2MoveOperator : ILinearLinkageMoveOperator {
     26    ILookupParameter<Swap2Move> Swap2MoveParameter { get; }
    3027  }
    3128}
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/LinearLinkage.cs

    r12396 r12643  
    131131    /// <remarks>
    132132    /// Throws an ArgumentException when there is an element assigned to
    133     /// multiple groups or elements that  are not assigned to any group.
     133    /// multiple groups or elements that are not assigned to any group.
    134134    /// </remarks>
    135135    /// <param name="grouping">The grouping of the elements, each element must
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/LinearLinkageEncoding.cs

    r12288 r12643  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Data;
    28 using HeuristicLab.Encodings.LinearLinkageEncoding.Creators;
    2928using HeuristicLab.Optimization;
    3029using HeuristicLab.Parameters;
     
    108107          typeof (ILinearLinkageCrossover),
    109108          typeof (ILinearLinkageManipulator),
    110           typeof (ILinearLinkageShakingOperator)
     109          typeof (ILinearLinkageShakingOperator),
     110          typeof (ILinearLinkageMoveOperator)
    111111      };
    112112    }
     
    128128      ConfigureManipulators(operators.OfType<ILinearLinkageManipulator>());
    129129      ConfigureShakingOperators(operators.OfType<ILinearLinkageShakingOperator>());
     130      ConfigureMoveOperators(operators.OfType<ILinearLinkageMoveOperator>());
     131      ConfigureSwap2MoveOperators(operators.OfType<ILinearLinkageSwap2MoveOperator>());
    130132    }
    131133
     
    153155      }
    154156    }
     157    private void ConfigureMoveOperators(IEnumerable<ILinearLinkageMoveOperator> moveOperators) {
     158      foreach (var moveOperator in moveOperators) {
     159        moveOperator.LLEParameter.ActualName = Name;
     160      }
     161    }
     162    private void ConfigureSwap2MoveOperators(IEnumerable<ILinearLinkageSwap2MoveOperator> swap2MoveOperators) {
     163      foreach (var swap2MoveOperator in swap2MoveOperators) {
     164        swap2MoveOperator.Swap2MoveParameter.ActualName = Name + ".Swap2Move";
     165      }
     166    }
    155167    #endregion
    156168  }
  • branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/ShakingOperators/LLEShakingOperator.cs

    r12288 r12643  
    3131
    3232namespace HeuristicLab.Encodings.LinearLinkageEncoding {
    33   /// <summary>
    34   /// A shaking operator for VNS.
    35   /// </summary>
    3633  [Item("LLE Shaking Operator", "A shaking operator for VNS which uses LLE manipulators to perform the shaking.")]
    3734  [StorableClass]
Note: See TracChangeset for help on using the changeset viewer.