Changeset 12643
- Timestamp:
- 07/07/15 13:52:18 (9 years ago)
- 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 20 20 #endregion 21 21 22 using System ;22 using System.Collections.Generic; 23 23 using System.Linq; 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 27 using HeuristicLab.Parameters; 26 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Random; 27 30 28 namespace HeuristicLab.Encodings.LinearLinkageEncoding .Creators{29 [Item(" Random Linear Linkage Creator", "Creates a random linear linkage LLE encoded solution.")]31 namespace 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.")] 30 33 [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 } 32 44 33 45 [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 } 37 52 38 53 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; 40 67 } 41 68 42 69 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); 49 72 } 50 73 } -
branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Creators/MaxGroupsLinearLinkageCreator.cs
r12628 r12643 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 27 using HeuristicLab.Parameters; 26 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 29 28 namespace HeuristicLab.Encodings.LinearLinkageEncoding .Creators{29 [Item(" Random Linear Linkage Creator", "Creates a random linear linkage LLE encoded solution.")]30 namespace HeuristicLab.Encodings.LinearLinkageEncoding { 31 [Item("Maxgroups Linear Linkage Creator", "Creates a random linear linkage LLE encoded solution with a given maximum number of groups.")] 30 32 [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 } 32 43 33 44 [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 } 37 51 38 52 public override IDeepCloneable Clone(Cloner cloner) { 39 return new RandomLinearLinkageCreator(this, cloner);53 return new MaxGroupsLinearLinkageCreator(this, cloner); 40 54 } 41 55 42 p rotected override LinearLinkage Create(IRandom random, int length) {56 public static LinearLinkage Apply(IRandom random, int length, int maxGroups) { 43 57 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))) 45 59 .GroupBy(x => x.Item2) 46 60 .Select(x => x.Select(y => y.Item1).ToList()); … … 48 62 return solution; 49 63 } 64 65 protected override LinearLinkage Create(IRandom random, int length) { 66 var maxGroups = MaxGroupsParameter.ActualValue.Value; 67 return Apply(random, length, maxGroups); 68 } 50 69 } 51 70 } -
branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Creators/RandomLinearLinkageCreator.cs
r12288 r12643 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 27 28 namespace HeuristicLab.Encodings.LinearLinkageEncoding .Creators{29 [Item("Random Linear Linkage Creator", "Creates a random linear linkage LLE encoded solution .")]28 namespace HeuristicLab.Encodings.LinearLinkageEncoding { 29 [Item("Random Linear Linkage Creator", "Creates a random linear linkage LLE encoded solution (similar to MaxGroups set to N).")] 30 30 [StorableClass] 31 31 public sealed class RandomLinearLinkageCreator : LinearLinkageCreator { … … 40 40 } 41 41 42 p rotected override LinearLinkage Create(IRandom random, int length) {42 public static LinearLinkage Apply(IRandom random, int length) { 43 43 var solution = new LinearLinkage(length); 44 44 var groups = Enumerable.Range(0, length).Select(x => Tuple.Create(x, random.Next(length))) … … 48 48 return solution; 49 49 } 50 51 protected override LinearLinkage Create(IRandom random, int length) { 52 return Apply(random, length); 53 } 50 54 } 51 55 } -
branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Crossovers/GroupCrossover.cs
r12288 r12643 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; -
branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/HeuristicLab.Encodings.LinearLinkageEncoding-3.3.csproj
r12396 r12643 102 102 </ItemGroup> 103 103 <ItemGroup> 104 <Compile Include="Creators\ExactGroupsLinearLinkageCreator.cs" /> 105 <Compile Include="Creators\MaxGroupsLinearLinkageCreator.cs" /> 104 106 <Compile Include="Creators\RandomLinearLinkageCreator.cs" /> 105 107 <Compile Include="Crossovers\GreedyPartitionCrossover.cs" /> … … 108 110 <Compile Include="Crossovers\MultiLLECrossover.cs" /> 109 111 <Compile Include="Crossovers\SinglePointCrossover.cs" /> 112 <Compile Include="Interfaces\ILinearLinkageMoveOperator.cs" /> 113 <Compile Include="Interfaces\ILinearLinkageSwap2MoveOperator.cs" /> 110 114 <Compile Include="Interfaces\ILinearLinkageCreator.cs" /> 111 115 <Compile Include="LinearLinkage.cs" /> … … 118 122 <Compile Include="Manipulators\MergeGroupManipulator.cs" /> 119 123 <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" /> 120 130 <Compile Include="ShakingOperators\LLEShakingOperator.cs" /> 121 131 <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 22 using HeuristicLab.Core; 2 23 using HeuristicLab.Optimization; 3 24 -
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 22 using HeuristicLab.Core; 2 23 using HeuristicLab.Optimization; 3 24 -
branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Interfaces/ILinearLinkageMoveOperator.cs
r12628 r12643 21 21 22 22 using HeuristicLab.Core; 23 using HeuristicLab.Data;24 23 using HeuristicLab.Optimization; 25 24 26 25 namespace 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 { 29 34 ILookupParameter<LinearLinkage> LLEParameter { get; } 30 35 } -
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 2 22 using HeuristicLab.Core; 3 23 -
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 22 using HeuristicLab.Core; 2 23 3 24 namespace HeuristicLab.Encodings.LinearLinkageEncoding { -
branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Interfaces/ILinearLinkageSwap2MoveOperator.cs
r12628 r12643 21 21 22 22 using HeuristicLab.Core; 23 using HeuristicLab.Data;24 using HeuristicLab.Optimization;25 23 26 24 namespace 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; } 30 27 } 31 28 } -
branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/LinearLinkage.cs
r12396 r12643 131 131 /// <remarks> 132 132 /// Throws an ArgumentException when there is an element assigned to 133 /// multiple groups or elements that 133 /// multiple groups or elements that are not assigned to any group. 134 134 /// </remarks> 135 135 /// <param name="grouping">The grouping of the elements, each element must -
branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/LinearLinkageEncoding.cs
r12288 r12643 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.LinearLinkageEncoding.Creators;29 28 using HeuristicLab.Optimization; 30 29 using HeuristicLab.Parameters; … … 108 107 typeof (ILinearLinkageCrossover), 109 108 typeof (ILinearLinkageManipulator), 110 typeof (ILinearLinkageShakingOperator) 109 typeof (ILinearLinkageShakingOperator), 110 typeof (ILinearLinkageMoveOperator) 111 111 }; 112 112 } … … 128 128 ConfigureManipulators(operators.OfType<ILinearLinkageManipulator>()); 129 129 ConfigureShakingOperators(operators.OfType<ILinearLinkageShakingOperator>()); 130 ConfigureMoveOperators(operators.OfType<ILinearLinkageMoveOperator>()); 131 ConfigureSwap2MoveOperators(operators.OfType<ILinearLinkageSwap2MoveOperator>()); 130 132 } 131 133 … … 153 155 } 154 156 } 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 } 155 167 #endregion 156 168 } -
branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/ShakingOperators/LLEShakingOperator.cs
r12288 r12643 31 31 32 32 namespace HeuristicLab.Encodings.LinearLinkageEncoding { 33 /// <summary>34 /// A shaking operator for VNS.35 /// </summary>36 33 [Item("LLE Shaking Operator", "A shaking operator for VNS which uses LLE manipulators to perform the shaking.")] 37 34 [StorableClass]
Note: See TracChangeset
for help on using the changeset viewer.