Index: /branches/GeneralizedQAP/GeneralizedQAP.sln
===================================================================
--- /branches/GeneralizedQAP/GeneralizedQAP.sln (revision 15490)
+++ /branches/GeneralizedQAP/GeneralizedQAP.sln (revision 15491)
@@ -17,4 +17,6 @@
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Optimization-3.3", "HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj", "{14AB8D24-25BC-400C-A846-4627AA945192}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Encodings.IntegerVectorEncoding-3.3", "HeuristicLab.Encodings.IntegerVectorEncoding\3.3\HeuristicLab.Encodings.IntegerVectorEncoding-3.3.csproj", "{DDFB14DD-2A85-493C-A52D-E69729BBAEB0}"
EndProject
Global
@@ -100,4 +102,16 @@
{14AB8D24-25BC-400C-A846-4627AA945192}.Release|x86.ActiveCfg = Release|x86
{14AB8D24-25BC-400C-A846-4627AA945192}.Release|x86.Build.0 = Release|x86
+ {DDFB14DD-2A85-493C-A52D-E69729BBAEB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DDFB14DD-2A85-493C-A52D-E69729BBAEB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DDFB14DD-2A85-493C-A52D-E69729BBAEB0}.Debug|x64.ActiveCfg = Debug|x64
+ {DDFB14DD-2A85-493C-A52D-E69729BBAEB0}.Debug|x64.Build.0 = Debug|x64
+ {DDFB14DD-2A85-493C-A52D-E69729BBAEB0}.Debug|x86.ActiveCfg = Debug|x86
+ {DDFB14DD-2A85-493C-A52D-E69729BBAEB0}.Debug|x86.Build.0 = Debug|x86
+ {DDFB14DD-2A85-493C-A52D-E69729BBAEB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DDFB14DD-2A85-493C-A52D-E69729BBAEB0}.Release|Any CPU.Build.0 = Release|Any CPU
+ {DDFB14DD-2A85-493C-A52D-E69729BBAEB0}.Release|x64.ActiveCfg = Release|x64
+ {DDFB14DD-2A85-493C-A52D-E69729BBAEB0}.Release|x64.Build.0 = Release|x64
+ {DDFB14DD-2A85-493C-A52D-E69729BBAEB0}.Release|x86.ActiveCfg = Release|x86
+ {DDFB14DD-2A85-493C-A52D-E69729BBAEB0}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/BoundedIntegerVectorCrossover.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/BoundedIntegerVectorCrossover.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/BoundedIntegerVectorCrossover.cs (revision 15491)
@@ -0,0 +1,53 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ [Item("BoundedIntegerVectorCrossover", "Base class for bounded crossovers.")]
+ [StorableClass]
+ public abstract class BoundedIntegerVectorCrossover : IntegerVectorCrossover, IBoundedIntegerVectorOperator {
+
+ public IValueLookupParameter BoundsParameter {
+ get { return (IValueLookupParameter)Parameters["Bounds"]; }
+ }
+
+ [StorableConstructor]
+ protected BoundedIntegerVectorCrossover(bool deserializing) : base(deserializing) { }
+ protected BoundedIntegerVectorCrossover(BoundedIntegerVectorCrossover original, Cloner cloner) : base(original, cloner) { }
+ public BoundedIntegerVectorCrossover()
+ : base() {
+ Parameters.Add(new ValueLookupParameter("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (exclusive), and step size. If less rows are given the matrix is cycled."));
+ }
+
+ protected sealed override IntegerVector Cross(IRandom random, ItemArray parents) {
+ if (BoundsParameter.ActualValue == null) throw new InvalidOperationException(Name + ": Bounds are not defined!");
+ return CrossBounded(random, parents, BoundsParameter.ActualValue);
+ }
+
+ protected abstract IntegerVector CrossBounded(IRandom random, ItemArray parents, IntMatrix bounds);
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/BoundedIntegerVectorManipulator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/BoundedIntegerVectorManipulator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/BoundedIntegerVectorManipulator.cs (revision 15491)
@@ -0,0 +1,53 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ [Item("BoundedIntegerVectorManipulator", "Base class for bounded integer vector manipulators.")]
+ [StorableClass]
+ public abstract class BoundedIntegerVectorManipulator : IntegerVectorManipulator, IBoundedIntegerVectorOperator {
+
+ public IValueLookupParameter BoundsParameter {
+ get { return (IValueLookupParameter)Parameters["Bounds"]; }
+ }
+
+ [StorableConstructor]
+ protected BoundedIntegerVectorManipulator(bool deserializing) : base(deserializing) { }
+ protected BoundedIntegerVectorManipulator(BoundedIntegerVectorManipulator original, Cloner cloner) : base(original, cloner) { }
+ public BoundedIntegerVectorManipulator()
+ : base() {
+ Parameters.Add(new ValueLookupParameter("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (exclusive), and step size. If less rows are given the matrix is cycled."));
+ }
+
+ protected sealed override void Manipulate(IRandom random, IntegerVector integerVector) {
+ if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("BoundedIntegerVectorManipulator: Parameter " + BoundsParameter.ActualName + " could not be found.");
+ ManipulateBounded(random, integerVector, BoundsParameter.ActualValue);
+ }
+
+ protected abstract void ManipulateBounded(IRandom random, IntegerVector integerVector, IntMatrix bounds);
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Creators/UniformRandomIntegerVectorCreator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Creators/UniformRandomIntegerVectorCreator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Creators/UniformRandomIntegerVectorCreator.cs (revision 15491)
@@ -0,0 +1,68 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// Generates a new random integer vector with each element uniformly distributed in a specified range.
+ ///
+ [Item("UniformRandomIntegerVectorCreator", "An operator which creates a new random int vector with each element uniformly distributed in a specified range.")]
+ [StorableClass]
+ public class UniformRandomIntegerVectorCreator : IntegerVectorCreator {
+ [StorableConstructor]
+ protected UniformRandomIntegerVectorCreator(bool deserializing) : base(deserializing) { }
+ protected UniformRandomIntegerVectorCreator(UniformRandomIntegerVectorCreator original, Cloner cloner) : base(original, cloner) { }
+ public UniformRandomIntegerVectorCreator() : base() { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new UniformRandomIntegerVectorCreator(this, cloner);
+ }
+
+ ///
+ /// Generates a new random integer vector with the given .
+ ///
+ /// The random number generator.
+ /// The length of the int vector.
+ /// A matrix containing the inclusive lower and inclusive upper bound in the first and second column and a step size in the third column.
+ /// Each line represents the bounds for a certain dimension. If fewer lines are given, the lines are cycled.
+ /// The newly created integer vector.
+ public static IntegerVector Apply(IRandom random, int length, IntMatrix bounds) {
+ var result = new IntegerVector(length);
+ result.Randomize(random, bounds);
+ return result;
+ }
+
+ ///
+ /// Forwards the call to .
+ ///
+ /// The pseudo random number generator to use.
+ /// The length of the int vector.
+ /// Contains in each row for each dimension minimum (inclusive), maximum (inclusive), and step size.
+ /// The newly created int vector.
+ protected override IntegerVector Create(IRandom random, IntValue length, IntMatrix bounds) {
+ return Apply(random, length.Value, bounds);
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/DiscreteCrossover.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/DiscreteCrossover.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/DiscreteCrossover.cs (revision 15491)
@@ -0,0 +1,80 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// Discrete crossover for integer vectors.
+ ///
+ ///
+ /// It is implemented as described in Gwiazda, T.D. 2006. Genetic algorithms reference Volume I Crossover for single-objective numerical optimization problems, p.17.
+ ///
+ [Item("DiscreteCrossover", "Discrete crossover for integer vectors. It is implemented as described in Gwiazda, T.D. 2006. Genetic algorithms reference Volume I Crossover for single-objective numerical optimization problems, p.17.")]
+ [StorableClass]
+ public class DiscreteCrossover : IntegerVectorCrossover {
+ [StorableConstructor]
+ protected DiscreteCrossover(bool deserializing) : base(deserializing) { }
+ protected DiscreteCrossover(DiscreteCrossover original, Cloner cloner) : base(original, cloner) { }
+ public DiscreteCrossover() : base() { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new DiscreteCrossover(this, cloner);
+ }
+
+ ///
+ /// Performs a discrete crossover operation of any number of given parents.
+ ///
+ /// Thrown when the vectors of the parents are of different length or when there are less than 2 parents.
+ /// A random number generator.
+ /// The list of parents for the crossover operation.
+ /// The newly created integer vector, resulting from the crossover operation.
+ public static IntegerVector Apply(IRandom random, ItemArray parents) {
+ if (parents.Length < 2) throw new ArgumentException("DiscreteCrossover: There are less than two parents to cross.");
+ int length = parents[0].Length;
+
+ for (int i = 0; i < parents.Length; i++) {
+ if (parents[i].Length != length)
+ throw new ArgumentException("DiscreteCrossover: The parents' vectors are of different length.", "parents");
+ }
+
+ var result = new IntegerVector(length);
+ for (int i = 0; i < length; i++) {
+ result[i] = parents[random.Next(parents.Length)][i];
+ }
+
+ return result;
+ }
+
+ ///
+ /// Performs a discrete crossover operation for any number of given parent integer vectors.
+ ///
+ /// A random number generator.
+ /// An array containing integer vectors that should be crossed.
+ /// The newly created integer vector, resulting from the crossover operation.
+ protected override IntegerVector Cross(IRandom random, ItemArray parents) {
+ return Apply(random, parents);
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/MultiIntegerVectorCrossover.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/MultiIntegerVectorCrossover.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/MultiIntegerVectorCrossover.cs (revision 15491)
@@ -0,0 +1,108 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using System.Linq;
+using HeuristicLab.Collections;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Operators;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using HeuristicLab.PluginInfrastructure;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ [Item("MultiIntegerVectorCrossover", "Randomly selects and applies one of its crossovers every time it is called.")]
+ [StorableClass]
+ public class MultiIntegerVectorCrossover : StochasticMultiBranch, IIntegerVectorCrossover, IStochasticOperator, IBoundedIntegerVectorOperator {
+ public override bool CanChangeName {
+ get { return false; }
+ }
+ protected override bool CreateChildOperation {
+ get { return true; }
+ }
+
+ public IValueLookupParameter BoundsParameter {
+ get { return (IValueLookupParameter)Parameters["Bounds"]; }
+ }
+
+ public ILookupParameter> ParentsParameter {
+ get { return (ILookupParameter>)Parameters["Parents"]; }
+ }
+
+ public ILookupParameter ChildParameter {
+ get { return (ILookupParameter)Parameters["Child"]; }
+ }
+
+ [StorableConstructor]
+ protected MultiIntegerVectorCrossover(bool deserializing) : base(deserializing) { }
+ protected MultiIntegerVectorCrossover(MultiIntegerVectorCrossover original, Cloner cloner) : base(original, cloner) { }
+ public MultiIntegerVectorCrossover()
+ : base() {
+ Parameters.Add(new ValueLookupParameter("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (exclusive), and step size. If less rows are given the matrix is cycled."));
+ Parameters.Add(new ScopeTreeLookupParameter("Parents", "The parent integer vector which should be crossed."));
+ ParentsParameter.ActualName = "IntegerVector";
+ Parameters.Add(new LookupParameter("Child", "The child integer vector resulting from the crossover."));
+ ChildParameter.ActualName = "IntegerVector";
+
+ foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(IIntegerVectorCrossover))) {
+ if (!typeof(MultiOperator).IsAssignableFrom(type))
+ Operators.Add((IIntegerVectorCrossover)Activator.CreateInstance(type), true);
+ }
+
+ SelectedOperatorParameter.ActualName = "SelectedCrossoverOperator";
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new MultiIntegerVectorCrossover(this, cloner);
+ }
+
+ protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs> e) {
+ base.Operators_ItemsReplaced(sender, e);
+ ParameterizeCrossovers();
+ }
+
+ protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs> e) {
+ base.Operators_ItemsAdded(sender, e);
+ ParameterizeCrossovers();
+ }
+
+ private void ParameterizeCrossovers() {
+ foreach (IIntegerVectorCrossover crossover in Operators.OfType()) {
+ crossover.ChildParameter.ActualName = ChildParameter.Name;
+ crossover.ParentsParameter.ActualName = ParentsParameter.Name;
+ }
+ foreach (IStochasticOperator crossover in Operators.OfType()) {
+ crossover.RandomParameter.ActualName = RandomParameter.Name;
+ }
+ foreach (IBoundedIntegerVectorOperator crossover in Operators.OfType()) {
+ crossover.BoundsParameter.ActualName = BoundsParameter.Name;
+ }
+ }
+
+ public override IOperation InstrumentedApply() {
+ if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one integer vector crossover to choose from.");
+ return base.InstrumentedApply();
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedAverageCrossover.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedAverageCrossover.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedAverageCrossover.cs (revision 15491)
@@ -0,0 +1,91 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// Rounded average crossover for integer vectors.
+ ///
+ [Item("RoundedAverageCrossover", "Average crossover for integer vectors.")]
+ [StorableClass]
+ public class RoundedAverageCrossover : BoundedIntegerVectorCrossover, IBoundedIntegerVectorOperator {
+
+ [StorableConstructor]
+ protected RoundedAverageCrossover(bool deserializing) : base(deserializing) { }
+ protected RoundedAverageCrossover(RoundedAverageCrossover original, Cloner cloner) : base(original, cloner) { }
+ public RoundedAverageCrossover() : base() { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new RoundedAverageCrossover(this, cloner);
+ }
+
+ ///
+ /// Performs an average crossover of the two given parent integer vectors.
+ /// The average is rounded and mapped to the nearest valid value (e.g. if step size is > 1)
+ ///
+ /// A random number generator.
+ /// The parents for crossover.
+ /// The bounds matrix that contains for each dimension one row with minimum (inclusive), maximum (exclusive), and step size columns.
+ /// If the number of rows is smaller than the number of dimensions the matrix is cycled.
+ /// The newly created integer vector, resulting from the single point crossover.
+ public static IntegerVector Apply(IRandom random, ItemArray parents, IntMatrix bounds) {
+ int length = parents[0].Length, parentsCount = parents.Length;
+ if (parents.Length < 2) throw new ArgumentException("RoundedAverageCrossover: The number of parents is less than 2.", "parents");
+ if (bounds == null || bounds.Rows < 1 || bounds.Columns < 2) throw new ArgumentException("AverageCrossover: Invalid bounds specified.", "bounds");
+
+ var result = new IntegerVector(length);
+ try {
+ double avg;
+ for (int i = 0; i < length; i++) {
+ avg = 0;
+ for (int j = 0; j < parentsCount; j++)
+ avg += parents[j][i];
+ avg /= parentsCount;
+ int min = bounds[i % bounds.Rows, 0], max = bounds[i % bounds.Rows, 1], step = 1;
+ if (bounds.Columns > 2) step = bounds[i % bounds.Rows, 2];
+ max = FloorFeasible(min, max, step, max - 1);
+ result[i] = RoundFeasible(min, max, step, avg);
+ }
+ } catch (IndexOutOfRangeException) {
+ throw new ArgumentException("RoundedAverageCrossover: The parents' vectors are of different length.", "parents");
+ }
+
+ return result;
+ }
+
+ ///
+ /// Performs an average crossover between two parent integer vectors.
+ ///
+ /// Thrown if there are not exactly two parents.
+ /// A random number generator.
+ /// An array containing the two integer vectors that should be crossed.
+ /// The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).
+ /// The newly created integer vector, resulting from the average crossover.
+ protected override IntegerVector CrossBounded(IRandom random, ItemArray parents, IntMatrix bounds) {
+ return Apply(random, parents, bounds);
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedBlendAlphaBetaCrossover.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedBlendAlphaBetaCrossover.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedBlendAlphaBetaCrossover.cs (revision 15491)
@@ -0,0 +1,164 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// Blend alpha-beta crossover for integer vectors (BLX-a-b). Creates a new offspring by selecting a
+ /// random value from the interval between the two alleles of the parent solutions and rounds the
+ /// result to the nearest feasible value. The interval is increased in both directions as follows:
+ /// Into the direction of the 'better' solution by the factor alpha, into the direction of the
+ /// 'worse' solution by the factor beta.
+ ///
+ [Item("RoundedBlendAlphaBetaCrossover", "The rounded blend alpha beta crossover (BLX-a-b) for integer vectors is similar to the blend alpha crossover (BLX-a), but distinguishes between the better and worse of the parents. The interval from which to choose the new offspring can be extended beyond the better parent by specifying a higher alpha value, and beyond the worse parent by specifying a higher beta value. The new offspring is sampled uniformly in the extended range and rounded to the next feasible integer.")]
+ [StorableClass]
+ public class RoundedBlendAlphaBetaCrossover : BoundedIntegerVectorCrossover, ISingleObjectiveOperator {
+ ///
+ /// Whether the problem is a maximization or minimization problem.
+ ///
+ public ValueLookupParameter MaximizationParameter {
+ get { return (ValueLookupParameter)Parameters["Maximization"]; }
+ }
+ ///
+ /// The quality of the parents.
+ ///
+ public ScopeTreeLookupParameter QualityParameter {
+ get { return (ScopeTreeLookupParameter)Parameters["Quality"]; }
+ }
+ ///
+ /// The Alpha parameter controls the extension of the range beyond the better parent. The value must be >= 0 and does not depend on Beta.
+ ///
+ public ValueLookupParameter AlphaParameter {
+ get { return (ValueLookupParameter)Parameters["Alpha"]; }
+ }
+ ///
+ /// The Beta parameter controls the extension of the range beyond the worse parent. The value must be >= 0 and does not depend on Alpha.
+ ///
+ public ValueLookupParameter BetaParameter {
+ get { return (ValueLookupParameter)Parameters["Beta"]; }
+ }
+
+ [StorableConstructor]
+ protected RoundedBlendAlphaBetaCrossover(bool deserializing) : base(deserializing) { }
+ protected RoundedBlendAlphaBetaCrossover(RoundedBlendAlphaBetaCrossover original, Cloner cloner) : base(original, cloner) { }
+ ///
+ /// Initializes a new instance of with four additional parameters
+ /// (Maximization, Quality, Alpha and Beta).
+ ///
+ public RoundedBlendAlphaBetaCrossover()
+ : base() {
+ Parameters.Add(new ValueLookupParameter("Maximization", "Whether the problem is a maximization problem or not."));
+ Parameters.Add(new ScopeTreeLookupParameter("Quality", "The quality values of the parents."));
+ Parameters.Add(new ValueLookupParameter("Alpha", "The Alpha parameter controls the extension of the range beyond the better parent. The value must be >= 0 and does not depend on Beta.", new DoubleValue(0.75)));
+ Parameters.Add(new ValueLookupParameter("Beta", "The Beta parameter controls the extension of the range beyond the worse parent. The value must be >= 0 and does not depend on Alpha.", new DoubleValue(0.25)));
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new RoundedBlendAlphaBetaCrossover(this, cloner);
+ }
+
+ ///
+ /// Performs the rounded blend alpha beta crossover (BLX-a-b) on two parent vectors.
+ ///
+ ///
+ /// Thrown when either:
+ ///
+ /// - The length of and is not equal.
+ /// - The parameter is smaller than 0.
+ /// - The parameter is smaller than 0.
+ ///
+ ///
+ /// The random number generator to use.
+ /// The better of the two parents with regard to their fitness.
+ /// The worse of the two parents with regard to their fitness.
+ /// The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).
+ /// The parameter alpha.
+ /// The parameter beta.
+ /// The integer vector that results from the crossover.
+ public static IntegerVector Apply(IRandom random, IntegerVector betterParent, IntegerVector worseParent, IntMatrix bounds, DoubleValue alpha, DoubleValue beta) {
+ if (betterParent.Length != worseParent.Length) throw new ArgumentException("RoundedBlendAlphaBetaCrossover: The parents' vectors are of different length.", "betterParent");
+ if (alpha.Value < 0) throw new ArgumentException("RoundedBlendAlphaBetaCrossover: Parameter alpha must be greater or equal to 0.", "alpha");
+ if (beta.Value < 0) throw new ArgumentException("RoundedBlendAlphaBetaCrossover: Parameter beta must be greater or equal to 0.", "beta");
+ if (bounds == null || bounds.Rows < 1 || bounds.Columns < 2) throw new ArgumentException("RoundedBlendAlphaBetaCrossover: Invalid bounds specified.", "bounds");
+
+ int length = betterParent.Length;
+ double min, max, d;
+ var result = new IntegerVector(length);
+ int minBound, maxBound, step = 1;
+ for (int i = 0; i < length; i++) {
+ minBound = bounds[i % bounds.Rows, 0];
+ maxBound = bounds[i % bounds.Rows, 1];
+ if (bounds.Columns > 2) step = bounds[i % bounds.Rows, 2];
+ maxBound = FloorFeasible(minBound, maxBound, step, maxBound - 1);
+
+ d = Math.Abs(betterParent[i] - worseParent[i]);
+ if (betterParent[i] <= worseParent[i]) {
+ min = FloorFeasible(minBound, maxBound, step, betterParent[i] - d * alpha.Value);
+ max = CeilingFeasible(minBound, maxBound, step, worseParent[i] + d * beta.Value);
+ } else {
+ min = FloorFeasible(minBound, maxBound, step, worseParent[i] - d * beta.Value);
+ max = CeilingFeasible(minBound, maxBound, step, betterParent[i] + d * alpha.Value);
+ }
+ result[i] = RoundFeasible(minBound, maxBound, step, min + random.NextDouble() * (max - min));
+ }
+ return result;
+ }
+
+ ///
+ /// Checks if the number of parents is equal to 2, if all parameters are available and forwards the call to .
+ ///
+ /// Thrown when the number of parents is not equal to 2.
+ ///
+ /// Thrown when either:
+ ///
+ /// - Maximization parameter could not be found.
+ /// - Quality parameter could not be found or the number of quality values is not equal to the number of parents.
+ /// - Alpha parameter could not be found.
+ /// - Beta parameter could not be found.
+ ///
+ ///
+ /// The random number generator to use.
+ /// The collection of parents (must be of size 2).
+ /// The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).
+ /// The integer vector that results from the crossover.
+ protected override IntegerVector CrossBounded(IRandom random, ItemArray parents, IntMatrix bounds) {
+ if (parents.Length != 2) throw new ArgumentException("RoundedBlendAlphaBetaCrossover: Number of parents is not equal to 2.", "parents");
+ if (MaximizationParameter.ActualValue == null) throw new InvalidOperationException("RoundedBlendAlphaBetaCrossover: Parameter " + MaximizationParameter.ActualName + " could not be found.");
+ if (QualityParameter.ActualValue == null || QualityParameter.ActualValue.Length != parents.Length) throw new InvalidOperationException("RoundedBlendAlphaBetaCrossover: Parameter " + QualityParameter.ActualName + " could not be found, or not in the same quantity as there are parents.");
+ if (AlphaParameter.ActualValue == null || BetaParameter.ActualValue == null) throw new InvalidOperationException("RoundedBlendAlphaBetaCrossover: Parameter " + AlphaParameter.ActualName + " or paramter " + BetaParameter.ActualName + " could not be found.");
+
+ ItemArray qualities = QualityParameter.ActualValue;
+ bool maximization = MaximizationParameter.ActualValue.Value;
+ if (maximization && qualities[0].Value >= qualities[1].Value || !maximization && qualities[0].Value <= qualities[1].Value)
+ return Apply(random, parents[0], parents[1], bounds, AlphaParameter.ActualValue, BetaParameter.ActualValue);
+ else {
+ return Apply(random, parents[1], parents[0], bounds, AlphaParameter.ActualValue, BetaParameter.ActualValue);
+ }
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedBlendAlphaCrossover.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedBlendAlphaCrossover.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedBlendAlphaCrossover.cs (revision 15491)
@@ -0,0 +1,121 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// Rounded blend alpha crossover for integer vectors (BLX-a). Creates a new offspring by selecting a random value
+ /// from the interval between the two alleles of the parent solutions and rounding the result to the next feasible
+ /// integer. The interval is increased in both directions by the factor alpha.
+ ///
+ [Item("RoundedBlendAlphaCrossover", "The rounded blend alpha crossover (BLX-a) for integer vectors creates new offspring by sampling a new value in the range [min_i - d * alpha, max_i + d * alpha) at each position i and rounding the result to the next feasible integer. Here min_i and max_i are the smaller and larger value of the two parents at position i and d is max_i - min_i.")]
+ [StorableClass]
+ public class RoundedBlendAlphaCrossover : BoundedIntegerVectorCrossover {
+ ///
+ /// The alpha parameter specifies how much the interval between the parents should be extended to the left and right.
+ /// The value of this parameter also determines the name of the operator: BLX-0.0 for example means alpha is set to 0.
+ /// When Alpha is 0, then the offspring will only be chosen in between the parents, the bigger alpha is the more it will be possible to choose
+ /// values left and right of the min and max value for each gene.
+ ///
+ public ValueLookupParameter AlphaParameter {
+ get { return (ValueLookupParameter)Parameters["Alpha"]; }
+ }
+
+ [StorableConstructor]
+ protected RoundedBlendAlphaCrossover(bool deserializing) : base(deserializing) { }
+ protected RoundedBlendAlphaCrossover(RoundedBlendAlphaCrossover original, Cloner cloner) : base(original, cloner) { }
+ ///
+ /// Initializes a new instance of with one parameter (Alpha).
+ ///
+ public RoundedBlendAlphaCrossover()
+ : base() {
+ Parameters.Add(new ValueLookupParameter("Alpha", "The Alpha parameter controls the extension of the range beyond the two parents. It must be >= 0. A value of 0.5 means that half the range is added to both sides of the intervals.", new DoubleValue(0.5)));
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new RoundedBlendAlphaCrossover(this, cloner);
+ }
+
+ ///
+ /// Performs the rounded blend alpha crossover (BLX-a) of two integer vectors.
+ /// It creates new offspring by sampling a new value in the range [min_i - d * alpha, max_i + d * alpha) at each position i
+ /// and rounding the result to the next integer.
+ /// Here min_i and max_i are the smaller and larger value of the two parents at position i and d is max_i - min_i.
+ ///
+ ///
+ /// Thrown when and are of different length or
+ /// when is less than 0.
+ ///
+ /// The random number generator.
+ /// The first parent for the crossover operation.
+ /// The second parent for the crossover operation.
+ /// The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).
+ /// The alpha value for the crossover.
+ /// The newly created integer vector resulting from the crossover operation.
+ public static IntegerVector Apply(IRandom random, IntegerVector parent1, IntegerVector parent2, IntMatrix bounds, DoubleValue alpha) {
+ if (parent1.Length != parent2.Length) throw new ArgumentException("RoundedBlendAlphaCrossover: The parents' vectors are of different length.", "parent1");
+ if (alpha.Value < 0) throw new ArgumentException("RoundedBlendAlphaCrossover: Paramter alpha must be greater or equal than 0.", "alpha");
+ if (bounds == null || bounds.Rows < 1 || bounds.Columns < 2) throw new ArgumentException("RoundedBlendAlphaCrossover: Invalid bounds specified.", "bounds");
+
+ int length = parent1.Length;
+ var result = new IntegerVector(length);
+ double max = 0, min = 0, d = 0, resMin = 0, resMax = 0;
+ int minBound, maxBound, step = 1;
+
+ for (int i = 0; i < length; i++) {
+ minBound = bounds[i % bounds.Rows, 0];
+ maxBound = bounds[i % bounds.Rows, 1];
+ if (bounds.Columns > 2) step = bounds[i % bounds.Rows, 2];
+ maxBound = FloorFeasible(minBound, maxBound, step, maxBound - 1);
+
+ max = Math.Max(parent1[i], parent2[i]);
+ min = Math.Min(parent1[i], parent2[i]);
+ d = Math.Abs(max - min);
+ resMin = FloorFeasible(minBound, maxBound, step, min - d * alpha.Value);
+ resMax = CeilingFeasible(minBound, maxBound, step, max + d * alpha.Value);
+
+ result[i] = RoundFeasible(minBound, maxBound, step, resMin + random.NextDouble() * Math.Abs(resMax - resMin));
+ }
+ return result;
+ }
+
+ ///
+ /// Checks that the number of parents is equal to 2 and forwards the call to .
+ ///
+ /// Thrown when the number of parents is not equal to 2.
+ /// Thrown when the parameter alpha could not be found.
+ /// The random number generator to use.
+ /// The collection of parents (must be of size 2).
+ /// The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).
+ /// The integer vector resulting from the crossover operation.
+ protected override IntegerVector CrossBounded(IRandom random, ItemArray parents, IntMatrix bounds) {
+ if (parents.Length != 2) throw new ArgumentException("RoundedBlendAlphaCrossover: The number of parents is not equal to 2", "parents");
+ if (AlphaParameter.ActualValue == null) throw new InvalidOperationException("RoundedBlendAlphaCrossover: Parameter " + AlphaParameter.ActualName + " could not be found.");
+ return Apply(random, parents[0], parents[1], bounds, AlphaParameter.ActualValue);
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedHeuristicCrossover.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedHeuristicCrossover.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedHeuristicCrossover.cs (revision 15491)
@@ -0,0 +1,127 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// Heuristic crossover for integer vectors: Calculates the vector from the worse to the better parent and adds that to the better parent weighted with a factor in the interval [0;1).
+ /// The result is then rounded to the next feasible integer.
+ /// The idea is that going further in direction from the worse to the better leads to even better solutions (naturally this depends on the fitness landscape).
+ ///
+ [Item("RoundedHeuristicCrossover", "The heuristic crossover produces offspring that extend the better parent in direction from the worse to the better parent.")]
+ [StorableClass]
+ public class RoundedHeuristicCrossover : BoundedIntegerVectorCrossover, ISingleObjectiveOperator {
+ ///
+ /// Whether the problem is a maximization or minimization problem.
+ ///
+ public ValueLookupParameter MaximizationParameter {
+ get { return (ValueLookupParameter)Parameters["Maximization"]; }
+ }
+ ///
+ /// The quality of the parents.
+ ///
+ public ScopeTreeLookupParameter QualityParameter {
+ get { return (ScopeTreeLookupParameter)Parameters["Quality"]; }
+ }
+
+ [StorableConstructor]
+ protected RoundedHeuristicCrossover(bool deserializing) : base(deserializing) { }
+ protected RoundedHeuristicCrossover(RoundedHeuristicCrossover original, Cloner cloner) : base(original, cloner) { }
+ ///
+ /// Initializes a new instance of with two variable infos
+ /// (Maximization and Quality).
+ ///
+ public RoundedHeuristicCrossover()
+ : base() {
+ Parameters.Add(new ValueLookupParameter("Maximization", "Whether the problem is a maximization problem or not."));
+ Parameters.Add(new ScopeTreeLookupParameter("Quality", "The quality values of the parents."));
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new RoundedHeuristicCrossover(this, cloner);
+ }
+
+ ///
+ /// Perfomrs a heuristic crossover on the two given parents.
+ ///
+ /// Thrown when two parents are not of the same length.
+ /// The random number generator.
+ /// The first parent for the crossover operation.
+ /// The second parent for the crossover operation.
+ /// The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).
+ /// The newly created integer vector, resulting from the heuristic crossover.
+ public static IntegerVector Apply(IRandom random, IntegerVector betterParent, IntegerVector worseParent, IntMatrix bounds) {
+ if (betterParent.Length != worseParent.Length)
+ throw new ArgumentException("HeuristicCrossover: the two parents are not of the same length");
+
+ int length = betterParent.Length;
+ var result = new IntegerVector(length);
+ double factor = random.NextDouble();
+
+ int min, max, step = 1;
+ for (int i = 0; i < length; i++) {
+ min = bounds[i % bounds.Rows, 0];
+ max = bounds[i % bounds.Rows, 1];
+ if (bounds.Columns > 2) step = bounds[i % bounds.Rows, 2];
+ max = FloorFeasible(min, max, step, max - 1);
+ result[i] = RoundFeasible(min, max, step, betterParent[i] + factor * (betterParent[i] - worseParent[i]));
+ }
+ return result;
+ }
+
+ ///
+ /// Performs a heuristic crossover operation for two given parent integer vectors.
+ ///
+ /// Thrown when the number of parents is not equal to 2.
+ ///
+ /// Thrown when either:
+ ///
+ /// - Maximization parameter could not be found.
+ /// - Quality parameter could not be found or the number of quality values is not equal to the number of parents.
+ ///
+ ///
+ /// A random number generator.
+ /// An array containing the two real vectors that should be crossed.
+ /// /// The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).
+ /// The newly created integer vector, resulting from the crossover operation.
+ protected override IntegerVector CrossBounded(IRandom random, ItemArray parents, IntMatrix bounds) {
+ if (parents.Length != 2) throw new ArgumentException("RoundedHeuristicCrossover: The number of parents is not equal to 2");
+
+ if (MaximizationParameter.ActualValue == null) throw new InvalidOperationException("RoundedHeuristicCrossover: Parameter " + MaximizationParameter.ActualName + " could not be found.");
+ if (QualityParameter.ActualValue == null || QualityParameter.ActualValue.Length != parents.Length) throw new InvalidOperationException("RoundedHeuristicCrossover: Parameter " + QualityParameter.ActualName + " could not be found, or not in the same quantity as there are parents.");
+
+ ItemArray qualities = QualityParameter.ActualValue;
+ bool maximization = MaximizationParameter.ActualValue.Value;
+
+ if (maximization && qualities[0].Value >= qualities[1].Value || !maximization && qualities[0].Value <= qualities[1].Value)
+ return Apply(random, parents[0], parents[1], bounds);
+ else
+ return Apply(random, parents[1], parents[0], bounds);
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedLocalCrossover.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedLocalCrossover.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedLocalCrossover.cs (revision 15491)
@@ -0,0 +1,86 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// The rounded local crossover for integer vectors is similar to the , but where the factor alpha is chosen randomly in the interval [0;1) for each position.
+ /// cribed in Dumitrescu, D. et al. (2000), Evolutionary computation, CRC Press, Boca Raton, FL, p. 194.
+ ///
+ [Item("RoundedLocalCrossover", @"The runded local crossover is similar to the arithmetic crossover, but uses a random alpha for each position x = alpha * p1 + (1-alpha) * p2.")]
+ [StorableClass]
+ public class RoundedLocalCrossover : BoundedIntegerVectorCrossover {
+ [StorableConstructor]
+ protected RoundedLocalCrossover(bool deserializing) : base(deserializing) { }
+ protected RoundedLocalCrossover(RoundedLocalCrossover original, Cloner cloner) : base(original, cloner) { }
+ public RoundedLocalCrossover() : base() { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new RoundedLocalCrossover(this, cloner);
+ }
+
+ ///
+ /// Performs a local crossover on the two given parent vectors.
+ ///
+ /// Thrown when two parents are not of the same length.
+ /// The random number generator.
+ /// The first parent for the crossover operation.
+ /// The second parent for the crossover operation.
+ /// The newly created integer vector, resulting from the local crossover.
+ public static IntegerVector Apply(IRandom random, IntegerVector parent1, IntegerVector parent2, IntMatrix bounds) {
+ if (parent1.Length != parent2.Length)
+ throw new ArgumentException("RoundedLocalCrossover: the two parents are not of the same length");
+
+ double factor;
+ int length = parent1.Length;
+ var result = new IntegerVector(length);
+
+ int min, max, step = 1;
+ for (int i = 0; i < length; i++) {
+ min = bounds[i % bounds.Rows, 0];
+ max = bounds[i % bounds.Rows, 1];
+ if (bounds.Columns > 2) step = bounds[i % bounds.Rows, 2];
+ max = FloorFeasible(min, max, step, max - 1);
+ factor = random.NextDouble();
+ result[i] = RoundFeasible(min, max, step, (factor * parent1[i]) + ((1 - factor) * parent2[i]));
+ }
+ return result;
+ }
+
+ ///
+ /// Performs a local crossover operation for two given parent integer vectors.
+ ///
+ /// Thrown if there are not exactly two parents.
+ /// A random number generator.
+ /// An array containing the two real vectors that should be crossed.
+ /// The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).
+ /// The newly created integer vector, resulting from the crossover operation.
+ protected override IntegerVector CrossBounded(IRandom random, ItemArray parents, IntMatrix bounds) {
+ if (parents.Length != 2) throw new ArgumentException("RoundedLocalCrossover: The number of parents is not equal to 2");
+ return Apply(random, parents[0], parents[1], bounds);
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedUniformArithmeticCrossover.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedUniformArithmeticCrossover.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/RoundedUniformArithmeticCrossover.cs (revision 15491)
@@ -0,0 +1,111 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// The rounded uniform arithmetic crossover (continuous recombination) constructs an offspring by calculating x = alpha * p1 + (1-alpha) * p2 for a position x in the vector with a given probability (otherwise p1 is taken at this position).
+ ///
+ [Item("RoundedUniformSomePositionsArithmeticCrossover", "The uniform some positions arithmetic crossover (continuous recombination) constructs an offspring by calculating x = alpha * p1 + (1-alpha) * p2 for a position x in the vector with a given probability (otherwise p1 is taken at this position).")]
+ [StorableClass]
+ public class RoundedUniformArithmeticCrossover : BoundedIntegerVectorCrossover, IBoundedIntegerVectorOperator {
+
+ ///
+ /// The alpha parameter needs to be in the interval (0;1) and specifies how close the resulting offspring should be either to parent1 (alpha -> 0) or parent2 (alpha -> 1).
+ ///
+ public ValueLookupParameter AlphaParameter {
+ get { return (ValueLookupParameter)Parameters["Alpha"]; }
+ }
+ ///
+ /// The probability in the range (0;1] for each position in the vector to be crossed.
+ ///
+ public ValueLookupParameter ProbabilityParameter {
+ get { return (ValueLookupParameter)Parameters["Probability"]; }
+ }
+
+ [StorableConstructor]
+ protected RoundedUniformArithmeticCrossover(bool deserializing) : base(deserializing) { }
+ protected RoundedUniformArithmeticCrossover(RoundedUniformArithmeticCrossover original, Cloner cloner) : base(original, cloner) { }
+ ///
+ /// Initializes a new instance with two parameters (Alpha and Probability).
+ ///
+ public RoundedUniformArithmeticCrossover()
+ : base() {
+ Parameters.Add(new ValueLookupParameter("Alpha", "The alpha value in the range (0;1) that defines whether the point should be close to parent1 (->1) or parent2 (->0)", new DoubleValue(0.5)));
+ Parameters.Add(new ValueLookupParameter("Probability", "The probability for crossing a position in the range (0;1]", new DoubleValue(1)));
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new RoundedUniformArithmeticCrossover(this, cloner);
+ }
+
+ ///
+ /// Performs the arithmetic crossover on some positions by taking either x = alpha * p1 + (1 - alpha) * p2 or x = p1 depending on the probability for a gene to be crossed.
+ ///
+ /// The random number generator.
+ /// The first parent vector.
+ /// The second parent vector.
+ /// The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).
+ /// The alpha parameter ().
+ /// The probability parameter ().
+ /// The vector resulting from the crossover.
+ public static IntegerVector Apply(IRandom random, IntegerVector parent1, IntegerVector parent2, IntMatrix bounds, DoubleValue alpha, DoubleValue probability) {
+ int length = parent1.Length;
+ if (length != parent2.Length) throw new ArgumentException("RoundedUniformArithmeticCrossover: The parent vectors are of different length.", "parent1");
+ if (alpha.Value < 0 || alpha.Value > 1) throw new ArgumentException("RoundedUniformArithmeticCrossover: Parameter alpha must be in the range [0;1]", "alpha");
+ if (probability.Value < 0 || probability.Value > 1) throw new ArgumentException("RoundedUniformArithmeticCrossover: Parameter probability must be in the range [0;1]", "probability");
+
+ var result = new IntegerVector(length);
+ for (int i = 0; i < length; i++) {
+ if (random.NextDouble() < probability.Value) {
+ int min = bounds[i % bounds.Rows, 0], max = bounds[i % bounds.Rows, 1], step = 1;
+ if (bounds.Columns > 2) step = bounds[i % bounds.Rows, 2];
+ max = FloorFeasible(min, max, step, max - 1);
+ double value = alpha.Value * parent1[i] + (1 - alpha.Value) * parent2[i];
+ result[i] = RoundFeasible(min, max, step, value);
+ } else result[i] = parent1[i];
+ }
+ return result;
+ }
+
+ ///
+ /// Checks that there are exactly 2 parents, that the alpha and the probability parameter are not null and fowards the call to the static Apply method.
+ ///
+ /// Thrown when there are not exactly two parents.
+ /// Thrown when either the alpha parmeter or the probability parameter could not be found.
+ /// The random number generator.
+ /// The collection of parents (must be of size 2).
+ /// /// The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).
+ /// The vector resulting from the crossover.
+ protected override IntegerVector CrossBounded(IRandom random, ItemArray parents, IntMatrix bounds) {
+ if (parents.Length != 2) throw new ArgumentException("RoundedUniformArithmeticCrossover: There must be exactly two parents.", "parents");
+ if (AlphaParameter.ActualValue == null) throw new InvalidOperationException("RoundedUniformArithmeticCrossover: Parameter " + AlphaParameter.ActualName + " could not be found.");
+ if (ProbabilityParameter.ActualValue == null) throw new InvalidOperationException("RoundedUniformArithmeticCrossover: Parameter " + ProbabilityParameter.ActualName + " could not be found.");
+ return Apply(random, parents[0], parents[1], bounds, AlphaParameter.ActualValue, ProbabilityParameter.ActualValue);
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs (revision 15491)
@@ -0,0 +1,83 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// Single point crossover for integer vectors.
+ ///
+ ///
+ /// It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.
+ ///
+ [Item("SinglePointCrossover", "Single point crossover for integer vectors. It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")]
+ [StorableClass]
+ public class SinglePointCrossover : IntegerVectorCrossover {
+ [StorableConstructor]
+ protected SinglePointCrossover(bool deserializing) : base(deserializing) { }
+ protected SinglePointCrossover(SinglePointCrossover original, Cloner cloner) : base(original, cloner) { }
+ public SinglePointCrossover() : base() { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new SinglePointCrossover(this, cloner);
+ }
+
+ ///
+ /// Performs a single point crossover at a randomly chosen position of the two
+ /// given parent integer vectors.
+ ///
+ /// A random number generator.
+ /// The first parent for crossover.
+ /// The second parent for crossover.
+ /// The newly created integer vector, resulting from the single point crossover.
+ public static IntegerVector Apply(IRandom random, IntegerVector parent1, IntegerVector parent2) {
+ if (parent1.Length != parent2.Length)
+ throw new ArgumentException("SinglePointCrossover: The parents are of different length.");
+
+ int length = parent1.Length;
+ int[] result = new int[length];
+ int breakPoint = random.Next(1, length);
+
+ for (int i = 0; i < breakPoint; i++)
+ result[i] = parent1[i];
+ for (int i = breakPoint; i < length; i++)
+ result[i] = parent2[i];
+
+ return new IntegerVector(result);
+ }
+
+ ///
+ /// Performs a single point crossover at a randomly chosen position of two
+ /// given parent integer vectors.
+ ///
+ /// Thrown if there are not exactly two parents.
+ /// A random number generator.
+ /// An array containing the two integer vectors that should be crossed.
+ /// The newly created integer vector, resulting from the single point crossover.
+ protected override IntegerVector Cross(IRandom random, ItemArray parents) {
+ if (parents.Length != 2) throw new ArgumentException("ERROR in SinglePointCrossover: The number of parents is not equal to 2");
+ return Apply(random, parents[0], parents[1]);
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/HeuristicLab.Encodings.IntegerVectorEncoding-3.3.csproj
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/HeuristicLab.Encodings.IntegerVectorEncoding-3.3.csproj (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/HeuristicLab.Encodings.IntegerVectorEncoding-3.3.csproj (revision 15491)
@@ -0,0 +1,252 @@
+
+
+
+ Debug
+ AnyCPU
+ 9.0.30729
+ 2.0
+ {DDFB14DD-2A85-493C-A52D-E69729BBAEB0}
+ Library
+ Properties
+ HeuristicLab.Encodings.IntegerVectorEncoding
+ HeuristicLab.Encodings.IntegerVectorEncoding-3.3
+ v4.5
+
+
+ 512
+ true
+ HeuristicLab.snk
+
+
+ 3.5
+
+ publish\
+ true
+ Disk
+ false
+ Foreground
+ 7
+ Days
+ false
+ false
+ true
+ 0
+ 1.0.0.%2a
+ false
+ false
+ true
+
+
+ true
+ full
+ false
+ ..\..\..\..\trunk\sources\bin\
+ DEBUG;TRACE
+ prompt
+ 4
+ AllRules.ruleset
+ false
+
+
+ pdbonly
+ true
+ ..\..\..\..\trunk\sources\bin\
+ TRACE
+ prompt
+ 4
+ AllRules.ruleset
+ false
+
+
+ true
+ ..\..\..\..\trunk\sources\bin\
+ DEBUG;TRACE
+ full
+ x64
+ prompt
+ AllRules.ruleset
+ false
+
+
+ ..\..\..\..\trunk\sources\bin\
+ TRACE
+ true
+ pdbonly
+ x64
+ prompt
+ AllRules.ruleset
+ false
+
+
+ true
+ ..\..\..\..\trunk\sources\bin\
+ DEBUG;TRACE
+ full
+ x86
+ prompt
+ AllRules.ruleset
+ false
+
+
+ ..\..\..\..\trunk\sources\bin\
+ TRACE
+ true
+ pdbonly
+ x86
+ prompt
+ AllRules.ruleset
+ false
+
+
+
+
+ 3.5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Code
+
+
+
+
+
+
+
+ Code
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Code
+
+
+
+
+
+
+
+
+
+ False
+ .NET Framework 3.5 SP1 Client Profile
+ false
+
+
+ False
+ .NET Framework 3.5 SP1
+ true
+
+
+ False
+ Windows Installer 3.1
+ true
+
+
+
+
+ ..\..\..\..\trunk\sources\bin\HeuristicLab.Collections-3.3.dll
+ False
+
+
+ ..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll
+ False
+
+
+ ..\..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll
+ False
+
+
+ ..\..\..\..\trunk\sources\bin\HeuristicLab.Data-3.3.dll
+ False
+
+
+ ..\..\..\..\trunk\sources\bin\HeuristicLab.Operators-3.3.dll
+ False
+
+
+ ..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization.Operators-3.3.dll
+ False
+
+
+ ..\..\..\..\trunk\sources\bin\HeuristicLab.Parameters-3.3.dll
+ False
+
+
+ ..\..\..\..\trunk\sources\bin\HeuristicLab.Persistence-3.3.dll
+ False
+
+
+ ..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll
+ False
+
+
+ ..\..\..\..\trunk\sources\bin\HeuristicLab.Random-3.3.dll
+ False
+
+
+
+
+ {14AB8D24-25BC-400C-A846-4627AA945192}
+ HeuristicLab.Optimization-3.3
+ False
+
+
+
+
+
+ set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
+set ProjectDir=$(ProjectDir)
+set SolutionDir=$(SolutionDir)
+set Outdir=$(Outdir)
+
+call PreBuildEvent.cmd
+
+
+export ProjectDir=$(ProjectDir)
+export SolutionDir=$(SolutionDir)
+
+$SolutionDir/PreBuildEvent.sh
+
+
+
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVector.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVector.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVector.cs (revision 15491)
@@ -0,0 +1,79 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ [StorableClass]
+ [Item("IntegerVector", "Represents a vector of integer values.")]
+ public class IntegerVector : IntArray {
+ [StorableConstructor]
+ protected IntegerVector(bool deserializing) : base(deserializing) { }
+ protected IntegerVector(IntegerVector original, Cloner cloner) : base(original, cloner) { }
+ public IntegerVector() : base() { }
+ public IntegerVector(int length) : base(length) { }
+ public IntegerVector(int length, IRandom random, int min, int max)
+ : this(length) {
+ Randomize(random, min, max);
+ }
+ public IntegerVector(int[] elements) : base(elements) { }
+ public IntegerVector(IntArray elements)
+ : this(elements.Length) {
+ for (int i = 0; i < array.Length; i++)
+ array[i] = elements[i];
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new IntegerVector(this, cloner);
+ }
+
+ public virtual void Randomize(IRandom random, int startIndex, int length, int min, int max, int step = 1) {
+ if (length > 0) {
+ int numbers = (int)Math.Floor((max - min) / (double)step);
+ for (int i = startIndex; i < startIndex + length; i++) {
+ array[i] = random.Next(numbers) * step + min;
+ }
+ OnReset();
+ }
+ }
+ public virtual void Randomize(IRandom random, int startIndex, int length, IntMatrix bounds) {
+ if (length > 0) {
+ for (int i = startIndex; i < startIndex + length; i++) {
+ int min = bounds[i % bounds.Rows, 0], max = bounds[i % bounds.Rows, 1], step = 1;
+ if (bounds.Columns > 2) step = bounds[i % bounds.Rows, 2];
+ int numbers = (int)Math.Floor((max - min) / (double)step);
+ array[i] = random.Next(numbers) * step + min;
+ }
+ OnReset();
+ }
+ }
+ public void Randomize(IRandom random, int min, int max, int step = 1) {
+ Randomize(random, 0, Length, min, max, step);
+ }
+ public void Randomize(IRandom random, IntMatrix bounds) {
+ Randomize(random, 0, Length, bounds);
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorCreator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorCreator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorCreator.cs (revision 15491)
@@ -0,0 +1,88 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Operators;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// A base class for operators creating int-valued vectors.
+ ///
+ [Item("IntegerVectorCreator", "A base class for operators creating int-valued vectors.")]
+ [StorableClass]
+ public abstract class IntegerVectorCreator : InstrumentedOperator, IIntegerVectorCreator, IStochasticOperator {
+ public override bool CanChangeName {
+ get { return false; }
+ }
+ public ILookupParameter RandomParameter {
+ get { return (LookupParameter)Parameters["Random"]; }
+ }
+ public ILookupParameter IntegerVectorParameter {
+ get { return (ILookupParameter)Parameters["IntegerVector"]; }
+ }
+ public IValueLookupParameter LengthParameter {
+ get { return (IValueLookupParameter)Parameters["Length"]; }
+ }
+ public IValueLookupParameter BoundsParameter {
+ get { return (IValueLookupParameter)Parameters["Bounds"]; }
+ }
+
+ [StorableConstructor]
+ protected IntegerVectorCreator(bool deserializing) : base(deserializing) { }
+ protected IntegerVectorCreator(IntegerVectorCreator original, Cloner cloner) : base(original, cloner) { }
+ protected IntegerVectorCreator()
+ : base() {
+ Parameters.Add(new LookupParameter("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
+ Parameters.Add(new LookupParameter("IntegerVector", "The vector which should be manipulated."));
+ Parameters.Add(new ValueLookupParameter("Length", "The length of the vector."));
+ Parameters.Add(new ValueLookupParameter("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (exclusive), and step size. If less rows are given the matrix is cycled."));
+ }
+
+ // BackwardsCompatibility3.3
+ #region Backwards compatible code, remove with 3.4
+ [StorableHook(HookType.AfterDeserialization)]
+ private void AfterDeserialization() {
+ if (!Parameters.ContainsKey("Bounds")) {
+ var min = ((IValueLookupParameter)Parameters["Minimum"]).Value as IntValue;
+ var max = ((IValueLookupParameter)Parameters["Maximum"]).Value as IntValue;
+ Parameters.Remove("Minimum");
+ Parameters.Remove("Maximum");
+ Parameters.Add(new ValueLookupParameter("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (exclusive), and step size. If less rows are given the matrix is cycled."));
+ if (min != null && max != null) {
+ BoundsParameter.Value = new IntMatrix(new int[,] { { min.Value, max.Value, 1 } });
+ }
+ }
+ }
+ #endregion
+
+ public sealed override IOperation InstrumentedApply() {
+ IntegerVectorParameter.ActualValue = Create(RandomParameter.ActualValue, LengthParameter.ActualValue, BoundsParameter.ActualValue);
+ return base.InstrumentedApply();
+ }
+
+ protected abstract IntegerVector Create(IRandom random, IntValue length, IntMatrix bounds);
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorCrossover.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorCrossover.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorCrossover.cs (revision 15491)
@@ -0,0 +1,67 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// A base class for operators that perform a crossover of int-valued vectors.
+ ///
+ [Item("IntegerVectorCrossover", "A base class for operators that perform a crossover of int-valued vectors.")]
+ [StorableClass]
+ public abstract class IntegerVectorCrossover : IntegerVectorOperator, IIntegerVectorCrossover, IStochasticOperator {
+ public override bool CanChangeName {
+ get { return false; }
+ }
+ public ILookupParameter RandomParameter {
+ get { return (LookupParameter)Parameters["Random"]; }
+ }
+ public ILookupParameter> ParentsParameter {
+ get { return (ScopeTreeLookupParameter)Parameters["Parents"]; }
+ }
+ public ILookupParameter ChildParameter {
+ get { return (ILookupParameter)Parameters["Child"]; }
+ }
+
+ [StorableConstructor]
+ protected IntegerVectorCrossover(bool deserializing) : base(deserializing) { }
+ protected IntegerVectorCrossover(IntegerVectorCrossover original, Cloner cloner) : base(original, cloner) { }
+ protected IntegerVectorCrossover()
+ : base() {
+ Parameters.Add(new LookupParameter("Random", "The pseudo random number generator which should be used for stochastic crossover operators."));
+ Parameters.Add(new ScopeTreeLookupParameter("Parents", "The parent vectors which should be crossed."));
+ ParentsParameter.ActualName = "IntegerVector";
+ Parameters.Add(new LookupParameter("Child", "The child vector resulting from the crossover."));
+ ChildParameter.ActualName = "IntegerVector";
+ }
+
+ public sealed override IOperation InstrumentedApply() {
+ ChildParameter.ActualValue = Cross(RandomParameter.ActualValue, ParentsParameter.ActualValue);
+ return base.InstrumentedApply();
+ }
+
+ protected abstract IntegerVector Cross(IRandom random, ItemArray parents);
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorEncoding.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorEncoding.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorEncoding.cs (revision 15491)
@@ -0,0 +1,283 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using HeuristicLab.PluginInfrastructure;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ [Item("IntegerVectorEncoding", "Describes an integer vector encoding.")]
+ [StorableClass]
+ public sealed class IntegerVectorEncoding : Encoding {
+ #region Encoding Parameters
+ [Storable]
+ private IFixedValueParameter lengthParameter;
+ public IFixedValueParameter LengthParameter {
+ get { return lengthParameter; }
+ set {
+ if (value == null) throw new ArgumentNullException("Length parameter must not be null.");
+ if (value.Value == null) throw new ArgumentNullException("Length parameter value must not be null.");
+ if (lengthParameter == value) return;
+
+ if (lengthParameter != null) Parameters.Remove(lengthParameter);
+ lengthParameter = value;
+ Parameters.Add(lengthParameter);
+ OnLengthParameterChanged();
+ }
+ }
+
+ [Storable]
+ private IValueParameter boundsParameter;
+ public IValueParameter BoundsParameter {
+ get { return boundsParameter; }
+ set {
+ if (value == null) throw new ArgumentNullException("Bounds parameter must not be null.");
+ if (boundsParameter == value) return;
+
+ if (boundsParameter != null) Parameters.Remove(boundsParameter);
+ boundsParameter = value;
+ Parameters.Add(boundsParameter);
+ OnBoundsParameterChanged();
+ }
+ }
+ #endregion
+
+ public int Length {
+ get { return LengthParameter.Value.Value; }
+ set { LengthParameter.Value.Value = value; }
+ }
+ public IntMatrix Bounds {
+ get { return BoundsParameter.Value; }
+ set { BoundsParameter.Value = value; }
+ }
+
+ [StorableConstructor]
+ private IntegerVectorEncoding(bool deserializing) : base(deserializing) { }
+ [StorableHook(HookType.AfterDeserialization)]
+ private void AfterDeserialization() {
+ RegisterParameterEvents();
+ DiscoverOperators();
+ }
+
+ private IntegerVectorEncoding(IntegerVectorEncoding original, Cloner cloner)
+ : base(original, cloner) {
+ lengthParameter = cloner.Clone(original.lengthParameter);
+ boundsParameter = cloner.Clone(original.boundsParameter);
+ RegisterParameterEvents();
+ }
+ public override IDeepCloneable Clone(Cloner cloner) { return new IntegerVectorEncoding(this, cloner); }
+
+
+ public IntegerVectorEncoding() : this("IntegerVector", 10) { }
+ public IntegerVectorEncoding(string name) : this(name, 10) { }
+ public IntegerVectorEncoding(int length) : this("integerVector", length) { }
+ public IntegerVectorEncoding(string name, int length, int min = int.MinValue, int max = int.MaxValue, int? step = null)
+ : base(name) {
+ if (min >= max) throw new ArgumentException("min must be less than max", "min");
+ if (step.HasValue && step.Value <= 0) throw new ArgumentException("step must be greater than zero or null", "step");
+
+ var bounds = new IntMatrix(1, step.HasValue ? 3 : 2);
+ bounds[0, 0] = min;
+ bounds[0, 1] = max;
+ if (step.HasValue) bounds[0, 2] = step.Value;
+
+ lengthParameter = new FixedValueParameter(Name + ".Length", new IntValue(length));
+ boundsParameter = new ValueParameter(Name + ".Bounds", bounds);
+ Parameters.Add(lengthParameter);
+ Parameters.Add(boundsParameter);
+
+ SolutionCreator = new UniformRandomIntegerVectorCreator();
+ RegisterParameterEvents();
+ DiscoverOperators();
+ }
+ public IntegerVectorEncoding(string name, int length, IList min, IList max, IList step = null)
+ : base(name) {
+ if (min.Count == 0) throw new ArgumentException("Bounds must be given for the integer parameters.");
+ if (min.Count != max.Count) throw new ArgumentException("min must be of the same length as max", "min");
+ if (step != null && min.Count != step.Count) throw new ArgumentException("step must be of the same length as min or null", "step");
+ if (min.Zip(max, (mi, ma) => mi >= ma).Any(x => x)) throw new ArgumentException("min must be less than max in each dimension", "min");
+
+ var bounds = new IntMatrix(min.Count, step != null ? 3 : 2);
+ for (int i = 0; i < min.Count; i++) {
+ bounds[i, 0] = min[i];
+ bounds[i, 1] = max[i];
+ if (step != null) bounds[i, 2] = step[i];
+ }
+
+ lengthParameter = new FixedValueParameter(Name + ".Length", new IntValue(length));
+ boundsParameter = new ValueParameter(Name + ".Bounds", bounds);
+ Parameters.Add(lengthParameter);
+ Parameters.Add(boundsParameter);
+
+ SolutionCreator = new UniformRandomIntegerVectorCreator();
+ RegisterParameterEvents();
+ DiscoverOperators();
+ }
+
+ private void OnLengthParameterChanged() {
+ RegisterLengthParameterEvents();
+ ConfigureOperators(Operators);
+ }
+ private void OnBoundsParameterChanged() {
+ RegisterBoundsParameterEvents();
+ ConfigureOperators(Operators);
+ }
+
+ private void RegisterParameterEvents() {
+ RegisterLengthParameterEvents();
+ RegisterBoundsParameterEvents();
+ }
+ private void RegisterLengthParameterEvents() {
+ LengthParameter.ValueChanged += (o, s) => ConfigureOperators(Operators);
+ LengthParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators);
+ }
+ private void RegisterBoundsParameterEvents() {
+ BoundsParameter.ValueChanged += (o, s) => ConfigureOperators(Operators);
+ boundsParameter.Value.ToStringChanged += (o, s) => ConfigureOperators(Operators);
+ }
+
+
+ #region Operator Discovery
+ private static readonly IEnumerable encodingSpecificOperatorTypes;
+ static IntegerVectorEncoding() {
+ encodingSpecificOperatorTypes = new List() {
+ typeof (IIntegerVectorOperator),
+ typeof (IIntegerVectorCreator),
+ typeof (IIntegerVectorCrossover),
+ typeof (IIntegerVectorManipulator),
+ typeof (IIntegerVectorStdDevStrategyParameterOperator),
+ typeof (IIntegerVectorMultiNeighborhoodShakingOperator),
+ };
+ }
+ private void DiscoverOperators() {
+ var assembly = typeof(IIntegerVectorOperator).Assembly;
+ var discoveredTypes = ApplicationManager.Manager.GetTypes(encodingSpecificOperatorTypes, assembly, true, false, false);
+ var operators = discoveredTypes.Select(t => (IOperator)Activator.CreateInstance(t));
+ var newOperators = operators.Except(Operators, new TypeEqualityComparer()).ToList();
+
+ ConfigureOperators(newOperators);
+ foreach (var @operator in newOperators)
+ AddOperator(@operator);
+ }
+ #endregion
+
+ public override void ConfigureOperators(IEnumerable operators) {
+ ConfigureBoundedOperators(operators.OfType());
+ ConfigureCreators(operators.OfType());
+ ConfigureCrossovers(operators.OfType());
+ ConfigureManipulators(operators.OfType());
+ ConfigureShakingOperators(operators.OfType());
+ ConfigureStrategyVectorOperator(operators.OfType());
+ }
+
+ #region Specific Operator Wiring
+ private void ConfigureBoundedOperators(IEnumerable boundedOperators) {
+ foreach (var boundedOperator in boundedOperators) {
+ boundedOperator.BoundsParameter.ActualName = BoundsParameter.Name;
+ }
+ }
+
+ private void ConfigureCreators(IEnumerable creators) {
+ foreach (var creator in creators) {
+ creator.IntegerVectorParameter.ActualName = Name;
+ creator.BoundsParameter.ActualName = BoundsParameter.Name;
+ creator.LengthParameter.ActualName = LengthParameter.Name;
+ }
+ }
+
+ private void ConfigureCrossovers(IEnumerable crossovers) {
+ foreach (var crossover in crossovers) {
+ crossover.ChildParameter.ActualName = Name;
+ crossover.ParentsParameter.ActualName = Name;
+ }
+ }
+
+ private void ConfigureManipulators(IEnumerable manipulators) {
+ foreach (var manipulator in manipulators) {
+ manipulator.IntegerVectorParameter.ActualName = Name;
+ manipulator.IntegerVectorParameter.Hidden = true;
+ var sm = manipulator as ISelfAdaptiveManipulator;
+ if (sm != null) {
+ var p = sm.StrategyParameterParameter as ILookupParameter;
+ if (p != null) {
+ p.ActualName = Name + "Strategy";
+ }
+ }
+ }
+ }
+
+ private void ConfigureShakingOperators(IEnumerable shakingOperators) {
+ foreach (var shakingOperator in shakingOperators) {
+ shakingOperator.IntegerVectorParameter.ActualName = Name;
+ }
+ }
+
+ private void ConfigureStrategyVectorOperator(IEnumerable strategyVectorOperators) {
+ var bounds = new DoubleMatrix(Bounds.Rows, Bounds.Columns);
+ for (var i = 0; i < bounds.Rows; i++) {
+ bounds[i, 1] = (int)Math.Ceiling(0.33 * (Bounds[i, 1] - Bounds[i, 0]));
+ bounds[i, 0] = 0;
+ if (bounds.Columns > 2) bounds[i, 2] = Bounds[i, 2];
+ }
+ foreach (var s in strategyVectorOperators) {
+ var c = s as IIntegerVectorStdDevStrategyParameterCreator;
+ if (c != null) {
+ c.BoundsParameter.Value = (DoubleMatrix)bounds.Clone();
+ c.LengthParameter.ActualName = Name;
+ c.StrategyParameterParameter.ActualName = Name + "Strategy";
+ }
+ var m = s as IIntegerVectorStdDevStrategyParameterManipulator;
+ if (m != null) {
+ m.BoundsParameter.Value = (DoubleMatrix)bounds.Clone();
+ m.StrategyParameterParameter.ActualName = Name + "Strategy";
+ }
+ var mm = s as StdDevStrategyVectorManipulator;
+ if (mm != null) {
+ mm.GeneralLearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * Length));
+ mm.LearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * Math.Sqrt(Length)));
+ }
+ var x = s as IIntegerVectorStdDevStrategyParameterCrossover;
+ if (x != null) {
+ x.ParentsParameter.ActualName = Name + "Strategy";
+ x.StrategyParameterParameter.ActualName = Name + "Strategy";
+ }
+ }
+ }
+ #endregion
+ }
+
+ public static class IndividualExtensionMethods {
+ public static IntegerVector IntegerVector(this Individual individual) {
+ var encoding = individual.GetEncoding();
+ return individual.IntegerVector(encoding.Name);
+ }
+ public static IntegerVector IntegerVector(this Individual individual, string name) {
+ return (IntegerVector)individual[name];
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorEqualityComparer.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorEqualityComparer.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorEqualityComparer.cs (revision 15491)
@@ -0,0 +1,48 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using HeuristicLab.PluginInfrastructure;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ [NonDiscoverableType]
+ public class IntegerVectorEqualityComparer : EqualityComparer {
+ public override bool Equals(IntegerVector x, IntegerVector y) {
+ if (ReferenceEquals(x, y)) return true;
+ if (x == null || y == null) return false;
+ if (x.Length != y.Length) return false;
+ for (var i = 0; i < x.Length; i++)
+ if (x[i] != y[i]) return false;
+ return true;
+ }
+
+ public override int GetHashCode(IntegerVector obj) {
+ if (obj == null) throw new ArgumentNullException("obj", "IntegerVectorEqualityComparer: Cannot compute hash value of null.");
+ unchecked {
+ int hash = 17;
+ foreach (var o in obj)
+ hash = hash * 31 + o.GetHashCode();
+ return hash;
+ }
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorManipulator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorManipulator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorManipulator.cs (revision 15491)
@@ -0,0 +1,61 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// A base class for operators that manipulate int-valued vectors.
+ ///
+ [Item("IntegerVectorManipulator", "A base class for operators that manipulate int-valued vectors.")]
+ [StorableClass]
+ public abstract class IntegerVectorManipulator : IntegerVectorOperator, IIntegerVectorManipulator, IStochasticOperator {
+ public override bool CanChangeName {
+ get { return false; }
+ }
+ public ILookupParameter RandomParameter {
+ get { return (LookupParameter)Parameters["Random"]; }
+ }
+ public ILookupParameter IntegerVectorParameter {
+ get { return (ILookupParameter)Parameters["IntegerVector"]; }
+ }
+
+ [StorableConstructor]
+ protected IntegerVectorManipulator(bool deserializing) : base(deserializing) { }
+ protected IntegerVectorManipulator(IntegerVectorManipulator original, Cloner cloner) : base(original, cloner) { }
+ protected IntegerVectorManipulator()
+ : base() {
+ Parameters.Add(new LookupParameter("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
+ Parameters.Add(new LookupParameter("IntegerVector", "The vector which should be manipulated."));
+ }
+
+ public sealed override IOperation InstrumentedApply() {
+ Manipulate(RandomParameter.ActualValue, IntegerVectorParameter.ActualValue);
+ return base.InstrumentedApply();
+ }
+
+ protected abstract void Manipulate(IRandom random, IntegerVector integerVector);
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorOperator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorOperator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorOperator.cs (revision 15491)
@@ -0,0 +1,48 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Operators;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ [Item("IntegerVectorOperator", "Base class for integer vectoro operators.")]
+ [StorableClass]
+ public abstract class IntegerVectorOperator : InstrumentedOperator, IIntegerVectorOperator {
+
+ [StorableConstructor]
+ protected IntegerVectorOperator(bool deserializing) : base(deserializing) { }
+ protected IntegerVectorOperator(IntegerVectorOperator original, Cloner cloner) : base(original, cloner) { }
+ public IntegerVectorOperator() : base() { }
+
+ public static int RoundFeasible(int min, int max, int step, double value) {
+ return Math.Max(min, Math.Min(max, (int)Math.Round((value - min) / (double)step) * step + min));
+ }
+ public static int FloorFeasible(int min, int max, int step, double value) {
+ return Math.Max(min, Math.Min(max, (int)Math.Floor((value - min) / (double)step) * step + min));
+ }
+ public static int CeilingFeasible(int min, int max, int step, double value) {
+ return Math.Max(min, Math.Min(max, (int)Math.Ceiling((value - min) / (double)step) * step + min));
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IBoundedIntegerVectorOperator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IBoundedIntegerVectorOperator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IBoundedIntegerVectorOperator.cs (revision 15491)
@@ -0,0 +1,32 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ public interface IBoundedIntegerVectorOperator : IIntegerVectorOperator {
+ ///
+ /// The bounds parameter must contain at least one row and at least two columns. The first two columns specify min and max values, the last column specifies the step size, but is optional (1 is assumed if omitted).
+ ///
+ IValueLookupParameter BoundsParameter { get; }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorCreator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorCreator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorCreator.cs (revision 15491)
@@ -0,0 +1,34 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Optimization;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// An interface which represents an operator for creating vectors of int-valued data.
+ ///
+ public interface IIntegerVectorCreator : ISolutionCreator, IBoundedIntegerVectorOperator {
+ IValueLookupParameter LengthParameter { get; }
+ ILookupParameter IntegerVectorParameter { get; }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorCrossover.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorCrossover.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorCrossover.cs (revision 15491)
@@ -0,0 +1,33 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Core;
+using HeuristicLab.Optimization;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// An interface which represents an operator for crossing vectors of int-valued data.
+ ///
+ public interface IIntegerVectorCrossover : IIntegerVectorOperator, ICrossover {
+ ILookupParameter> ParentsParameter { get; }
+ ILookupParameter ChildParameter { get; }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorManipulator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorManipulator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorManipulator.cs (revision 15491)
@@ -0,0 +1,32 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Core;
+using HeuristicLab.Optimization;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// An interface which represents an operator for manipulating vectors of int-valued data.
+ ///
+ public interface IIntegerVectorManipulator : IIntegerVectorOperator, IManipulator {
+ ILookupParameter IntegerVectorParameter { get; }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorMultiNeighborhoodShakingOperator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorMultiNeighborhoodShakingOperator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorMultiNeighborhoodShakingOperator.cs (revision 15491)
@@ -0,0 +1,28 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Core;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ public interface IIntegerVectorMultiNeighborhoodShakingOperator : IIntegerVectorOperator {
+ ILookupParameter IntegerVectorParameter { get; }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorOperator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorOperator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorOperator.cs (revision 15491)
@@ -0,0 +1,29 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Core;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// An interface which represents an operator dealing with vectors of int-valued data.
+ ///
+ public interface IIntegerVectorOperator : IOperator { }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorStdDevStrategyParameterCreator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorStdDevStrategyParameterCreator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorStdDevStrategyParameterCreator.cs (revision 15491)
@@ -0,0 +1,32 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Optimization;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ public interface IIntegerVectorStdDevStrategyParameterCreator : IIntegerVectorStdDevStrategyParameterOperator, IStrategyParameterCreator {
+ ILookupParameter StrategyParameterParameter { get; }
+ IValueLookupParameter LengthParameter { get; }
+ IValueLookupParameter BoundsParameter { get; }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorStdDevStrategyParameterCrossover.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorStdDevStrategyParameterCrossover.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorStdDevStrategyParameterCrossover.cs (revision 15491)
@@ -0,0 +1,31 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Optimization;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ public interface IIntegerVectorStdDevStrategyParameterCrossover : IIntegerVectorStdDevStrategyParameterOperator, IStrategyParameterCrossover {
+ ILookupParameter StrategyParameterParameter { get; }
+ ILookupParameter> ParentsParameter { get; }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorStdDevStrategyParameterManipulator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorStdDevStrategyParameterManipulator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorStdDevStrategyParameterManipulator.cs (revision 15491)
@@ -0,0 +1,31 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Optimization;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ public interface IIntegerVectorStdDevStrategyParameterManipulator : IIntegerVectorStdDevStrategyParameterOperator, IStrategyParameterManipulator {
+ ILookupParameter StrategyParameterParameter { get; }
+ IValueLookupParameter BoundsParameter { get; }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorStdDevStrategyParameterOperator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorStdDevStrategyParameterOperator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorStdDevStrategyParameterOperator.cs (revision 15491)
@@ -0,0 +1,27 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Core;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ public interface IIntegerVectorStdDevStrategyParameterOperator : IOperator {
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/RoundedNormalAllPositionsManipulator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/RoundedNormalAllPositionsManipulator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/RoundedNormalAllPositionsManipulator.cs (revision 15491)
@@ -0,0 +1,93 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using HeuristicLab.Random;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// Manipulates each dimension in the integer vector with the mutation strength given
+ /// in the sigma parameter vector and rounds the result to the next feasible value.
+ ///
+ [Item("RoundedNormalAllPositionsManipulator", "This manipulation operator adds a value sigma_i * N_i(0,1) to the current value in each position i given the values for sigma_i in the parameter. The result is rounded to the next feasible value. If there are less elements in Sigma than positions, then Sigma is cycled.")]
+ [StorableClass]
+ public class RoundedNormalAllPositionsManipulator : BoundedIntegerVectorManipulator {
+
+ public IValueParameter SigmaParameter {
+ get { return (IValueParameter)Parameters["Sigma"]; }
+ }
+
+ [StorableConstructor]
+ protected RoundedNormalAllPositionsManipulator(bool deserializing) : base(deserializing) { }
+ protected RoundedNormalAllPositionsManipulator(RoundedNormalAllPositionsManipulator original, Cloner cloner) : base(original, cloner) { }
+ ///
+ /// Initializes a new instance of with one
+ /// parameter (Sigma).
+ ///
+ public RoundedNormalAllPositionsManipulator()
+ : base() {
+ Parameters.Add(new ValueParameter("Sigma", "The vector containing the standard deviations used for manipulating each dimension. If it is only of length one the same sigma will be used for every dimension.", new DoubleArray(new double[] { 1 })));
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new RoundedNormalAllPositionsManipulator(this, cloner);
+ }
+
+ ///
+ /// Performs a normally distributed all position manipulation on the given
+ /// and rounds the result to the next feasible value.
+ ///
+ /// Thrown when the sigma vector is null or of length 0.
+ /// The sigma vector determining the strength of the mutation.
+ /// A random number generator.
+ /// The integer vector to manipulate.#
+ /// The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).
+ /// The manipulated integer vector.
+ public static void Apply(IRandom random, IntegerVector vector, IntMatrix bounds, DoubleArray sigma) {
+ if (sigma == null || sigma.Length == 0) throw new ArgumentException("RoundedNormalAllPositionsManipulator: Vector containing the standard deviations is not defined.", "sigma");
+ if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("RoundedNormalAllPositionsManipulator: Invalid bounds specified.", "bounds");
+ var N = new NormalDistributedRandom(random, 0.0, 1.0);
+ for (int i = 0; i < vector.Length; i++) {
+ int min = bounds[i % bounds.Rows, 0], max = bounds[i % bounds.Rows, 1], step = 1;
+ if (bounds.Columns > 2) step = bounds[i % bounds.Rows, 2];
+
+ int value = (vector[i] + (int)Math.Round((N.NextDouble() * sigma[i % sigma.Length])) - min) / step;
+ max = FloorFeasible(min, max, step, max - 1);
+ vector[i] = RoundFeasible(min, max, step, value);
+ }
+ }
+
+ ///
+ /// Retrieves the bounds and forwards the call to the static Apply method.
+ ///
+ /// The random number generator.
+ /// The vector of integer values that is manipulated.
+ /// The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).
+ protected override void ManipulateBounded(IRandom random, IntegerVector vector, IntMatrix bounds) {
+ Apply(random, vector, bounds, SigmaParameter.Value);
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/SelfAdaptiveRoundedNormalAllPositionsManipulator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/SelfAdaptiveRoundedNormalAllPositionsManipulator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/SelfAdaptiveRoundedNormalAllPositionsManipulator.cs (revision 15491)
@@ -0,0 +1,104 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using HeuristicLab.Random;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// Manipulates each dimension in the integer vector with the mutation strength given
+ /// in the strategy parameter vector.
+ ///
+ [Item("SelfAdaptiveRoundedNormalAllPositionsManipulator", "This manipulation operator adds a value sigma_i * N(0,1) to the current value in each position i. The resulting value is rounded to the next feasible value. The values for sigma_i are looked up dynamically. If there are less elements in the strategy vector than positions, then the strategy vector is cycled.")]
+ [StorableClass]
+ public class SelfAdaptiveRoundedNormalAllPositionsManipulator : BoundedIntegerVectorManipulator, ISelfAdaptiveManipulator {
+ public Type StrategyParameterType {
+ get { return typeof(IIntegerVectorStdDevStrategyParameterOperator); }
+ }
+ ///
+ /// Parameter for the strategy vector.
+ ///
+ public ILookupParameter StrategyParameterParameter {
+ get { return (ILookupParameter)Parameters["StrategyParameter"]; }
+ }
+
+ IParameter ISelfAdaptiveManipulator.StrategyParameterParameter {
+ get { return StrategyParameterParameter; }
+ }
+
+ [StorableConstructor]
+ protected SelfAdaptiveRoundedNormalAllPositionsManipulator(bool deserializing) : base(deserializing) { }
+ protected SelfAdaptiveRoundedNormalAllPositionsManipulator(SelfAdaptiveRoundedNormalAllPositionsManipulator original, Cloner cloner) : base(original, cloner) { }
+ ///
+ /// Initializes a new instance of with one.
+ ///
+ public SelfAdaptiveRoundedNormalAllPositionsManipulator()
+ : base() {
+ Parameters.Add(new LookupParameter("StrategyParameter", "The vector containing the endogenous strategy parameters."));
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new SelfAdaptiveRoundedNormalAllPositionsManipulator(this, cloner);
+ }
+
+ ///
+ /// Performs an adaptive normally distributed all position manipulation on the given
+ /// and rounding the results to the next feasible value.
+ ///
+ /// Thrown when the strategy vector is not
+ /// as long as the vector to get manipulated.
+ /// The strategy vector determining the strength of the mutation.
+ /// A random number generator.
+ /// The integer vector to manipulate.
+ /// The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).
+ public static void Apply(IRandom random, IntegerVector vector, IntMatrix bounds, DoubleArray strategyParameters) {
+ if (strategyParameters == null || strategyParameters.Length == 0) throw new ArgumentException("SelfAdaptiveRoundedNormalAllPositionsManipulator: Vector containing the standard deviations is not defined.", "sigma");
+ if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("SelfAdaptiveRoundedNormalAllPositionsManipulator: Invalid bounds specified.", "bounds");
+ var N = new NormalDistributedRandom(random, 0.0, 1.0);
+ if (strategyParameters != null) {
+ for (int i = 0; i < vector.Length; i++) {
+ int min = bounds[i % bounds.Rows, 0], max = bounds[i % bounds.Rows, 1], step = 1;
+ if (bounds.Columns > 2) step = bounds[i % bounds.Rows, 2];
+
+ int value = (vector[i] + (int)Math.Round((N.NextDouble() * strategyParameters[i % strategyParameters.Length])) - min) / step;
+ max = FloorFeasible(min, max, step, max - 1);
+ vector[i] = RoundFeasible(min, max, step, value);
+ }
+ }
+ }
+
+ ///
+ /// Checks that the strategy vector is not null and forwards the call to the static Apply method.
+ ///
+ /// The random number generator.
+ /// The vector of integer values that is manipulated.
+ /// The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).
+ protected override void ManipulateBounded(IRandom random, IntegerVector vector, IntMatrix bounds) {
+ Apply(random, vector, bounds, StrategyParameterParameter.ActualValue);
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/UniformOnePositionManipulator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/UniformOnePositionManipulator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/UniformOnePositionManipulator.cs (revision 15491)
@@ -0,0 +1,111 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// Uniformly distributed change of a single position of an integer vector.
+ ///
+ ///
+ /// It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.
+ ///
+ [Item("UniformOnePositionManipulator", " Uniformly distributed change of a single position of an integer vector. It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")]
+ [StorableClass]
+ public class UniformOnePositionManipulator : BoundedIntegerVectorManipulator {
+
+ [StorableConstructor]
+ protected UniformOnePositionManipulator(bool deserializing) : base(deserializing) { }
+ protected UniformOnePositionManipulator(UniformOnePositionManipulator original, Cloner cloner) : base(original, cloner) { }
+ ///
+ /// Initializes a new instance of with two parameters
+ /// (Minimum and Maximum).
+ ///
+ public UniformOnePositionManipulator() : base() { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new UniformOnePositionManipulator(this, cloner);
+ }
+
+ // BackwardsCompatibility3.3
+ #region Backwards compatible code, remove with 3.4
+ [StorableHook(HookType.AfterDeserialization)]
+ private void AfterDeserialization() {
+ if (!Parameters.ContainsKey("Bounds")) {
+ var min = ((IValueLookupParameter)Parameters["Minimum"]).Value as IntValue;
+ var max = ((IValueLookupParameter)Parameters["Maximum"]).Value as IntValue;
+ Parameters.Remove("Minimum");
+ Parameters.Remove("Maximum");
+ Parameters.Add(new ValueLookupParameter("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (exclusive), and step size. If less rows are given the matrix is cycled."));
+ if (min != null && max != null) {
+ BoundsParameter.Value = new IntMatrix(new int[,] { { min.Value, max.Value, 1 } });
+ }
+ }
+ }
+ #endregion
+
+ ///
+ /// Changes randomly a single position in the given integer .
+ ///
+ /// A random number generator.
+ /// The integer vector to manipulate.
+ /// The minimum value of the sampling range for
+ /// the vector element to change (inclusive).
+ /// The maximum value of the sampling range for
+ /// the vector element to change (exclusive).
+ /// The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).
+ public static void Apply(IRandom random, IntegerVector vector, IntMatrix bounds) {
+ Manipulate(random, vector, bounds, random.Next(vector.Length));
+ }
+
+ public static void Manipulate(IRandom random, IntegerVector vector, IntMatrix bounds, int index) {
+ if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("UniformOnePositionManipulator: Invalid bounds specified", "bounds");
+ int min = bounds[index % bounds.Rows, 0], max = bounds[index % bounds.Rows, 1], step = 1;
+ if (min == max) {
+ vector[index] = min;
+ } else {
+ if (bounds.Columns > 2) step = bounds[index % bounds.Rows, 2];
+ // max has to be rounded to the lower feasible value
+ // e.g. min...max / step = 0...100 / 5, max is exclusive so it would be 0..99
+ // but 99 is not a feasible value, so max needs to be adjusted => min = 0, max = 95
+ max = FloorFeasible(min, max, step, max - 1);
+ vector[index] = RoundFeasible(min, max, step, random.Next(min, max));
+ }
+ }
+
+ ///
+ /// Changes randomly a single position in the given integer .
+ ///
+ /// Calls .
+ /// A random number generator.
+ /// The integer vector to manipulate.
+ /// The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).
+ protected override void ManipulateBounded(IRandom random, IntegerVector vector, IntMatrix bounds) {
+ if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("UniformOnePositionManipulator: Parameter " + BoundsParameter.ActualName + " could not be found.");
+ Apply(random, vector, bounds);
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/UniformSomePositionsManipulator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/UniformSomePositionsManipulator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/UniformSomePositionsManipulator.cs (revision 15491)
@@ -0,0 +1,89 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// Uniformly distributed change of several, but at least one, positions of an integer vector.
+ ///
+ ///
+ /// It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.
+ ///
+ [Item("UniformSomePositionsManipulator", "Uniformly distributed change of several, but at least one, positions of an integer vector. It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")]
+ [StorableClass]
+ public class UniformSomePositionsManipulator : BoundedIntegerVectorManipulator {
+
+ public IValueLookupParameter ProbabilityParameter {
+ get { return (IValueLookupParameter)Parameters["Probability"]; }
+ }
+
+ [StorableConstructor]
+ protected UniformSomePositionsManipulator(bool deserializing) : base(deserializing) { }
+ protected UniformSomePositionsManipulator(UniformSomePositionsManipulator original, Cloner cloner) : base(original, cloner) { }
+ public UniformSomePositionsManipulator()
+ : base() {
+ Parameters.Add(new ValueLookupParameter("Probability", "The probability for each dimension to be manipulated.", new DoubleValue(0.5)));
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new UniformSomePositionsManipulator(this, cloner);
+ }
+
+ ///
+ /// Changes randomly several, but at least one, positions in the given integer , according to the given probabilities.
+ ///
+ /// A random number generator.
+ /// The integer vector to manipulate.
+ /// Contains the minimum value (inclusive), maximum value (exclusive), and step size of the sampling range for
+ /// the vector element to change.
+ /// The probability for each dimension to be manipulated..
+ public static void Apply(IRandom random, IntegerVector vector, IntMatrix bounds, double probability) {
+ if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("UniformSomePositionsManipulator: Invalid bounds specified", "bounds");
+ bool atLeastOneManipulated = false;
+ for (int index = 0; index < vector.Length; index++) {
+ if (random.NextDouble() < probability) {
+ atLeastOneManipulated = true;
+ UniformOnePositionManipulator.Manipulate(random, vector, bounds, index);
+ }
+ }
+
+ if (!atLeastOneManipulated) {
+ UniformOnePositionManipulator.Manipulate(random, vector, bounds, random.Next(vector.Length));
+ }
+ }
+
+ ///
+ /// Changes randomly several, but at least one, positions in the given integer .
+ ///
+ /// Calls .
+ /// A random number generator.
+ /// The integer vector to manipulate.
+ protected override void ManipulateBounded(IRandom random, IntegerVector vector, IntMatrix bounds) {
+ Apply(random, vector, bounds, ProbabilityParameter.ActualValue.Value);
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Plugin.cs.frame
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Plugin.cs.frame (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Plugin.cs.frame (revision 15491)
@@ -0,0 +1,42 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.PluginInfrastructure;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// Plugin class for HeuristicLab.Encodings.IntegerVectorEncoding plugin.
+ ///
+ [Plugin("HeuristicLab.Encodings.IntegerVectorEncoding", "3.3.14.$WCREV$")]
+ [PluginFile("HeuristicLab.Encodings.IntegerVectorEncoding-3.3.dll", PluginFileType.Assembly)]
+ [PluginDependency("HeuristicLab.Collections", "3.3")]
+ [PluginDependency("HeuristicLab.Common", "3.3")]
+ [PluginDependency("HeuristicLab.Core", "3.3")]
+ [PluginDependency("HeuristicLab.Data", "3.3")]
+ [PluginDependency("HeuristicLab.Operators", "3.3")]
+ [PluginDependency("HeuristicLab.Optimization", "3.3")]
+ [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")]
+ [PluginDependency("HeuristicLab.Parameters", "3.3")]
+ [PluginDependency("HeuristicLab.Persistence", "3.3")]
+ [PluginDependency("HeuristicLab.Random", "3.3")]
+ public class HeuristicLabEncodingsIntegerVectorEncodingPlugin : PluginBase {
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Properties/AssemblyInfo.cs.frame
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Properties/AssemblyInfo.cs.frame (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Properties/AssemblyInfo.cs.frame (revision 15491)
@@ -0,0 +1,56 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("HeuristicLab.Encodings.IntegerVectorEncoding")]
+[assembly: AssemblyDescription("HeuristicLab integer vector encoding and related operators")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("HeuristicLab")]
+[assembly: AssemblyCopyright("(c) 2002-2016 HEAL")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("B0F88DF0-497D-4038-BCC4-065B278C5D2A")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("3.3.0.0")]
+[assembly: AssemblyFileVersion("3.3.14.$WCREV$")]
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/ShakingOperators/IntegerVectorShakingOperator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/ShakingOperators/IntegerVectorShakingOperator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/ShakingOperators/IntegerVectorShakingOperator.cs (revision 15491)
@@ -0,0 +1,99 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System.Collections.Generic;
+using System.Linq;
+using HeuristicLab.Collections;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Optimization;
+using HeuristicLab.Optimization.Operators;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using HeuristicLab.PluginInfrastructure;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// A shaking operator for VNS.
+ ///
+ [Item("IntegerVectorShakingOperator", "A shaking operator for VNS which uses available manipulation operators to perform the shaking.")]
+ [StorableClass]
+ public class IntegerVectorShakingOperator : ShakingOperator, IIntegerVectorMultiNeighborhoodShakingOperator, IStochasticOperator, IBoundedIntegerVectorOperator {
+
+ public ILookupParameter IntegerVectorParameter {
+ get { return (ILookupParameter)Parameters["IntegerVector"]; }
+ }
+
+ public ILookupParameter RandomParameter {
+ get { return (LookupParameter)Parameters["Random"]; }
+ }
+
+ public IValueLookupParameter BoundsParameter {
+ get { return (IValueLookupParameter)Parameters["Bounds"]; }
+ }
+
+ [StorableConstructor]
+ protected IntegerVectorShakingOperator(bool deserializing) : base(deserializing) { }
+ protected IntegerVectorShakingOperator(IntegerVectorShakingOperator original, Cloner cloner) : base(original, cloner) { }
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new IntegerVectorShakingOperator(this, cloner);
+ }
+ public IntegerVectorShakingOperator()
+ : base() {
+ Parameters.Add(new LookupParameter("IntegerVector", "The integer vector to shake."));
+ Parameters.Add(new LookupParameter("Random", "The random number generator that will be used for stochastic shaking operators."));
+ Parameters.Add(new ValueLookupParameter("Bounds", "A 2 column matrix specifying the lower and upper bound for each dimension. If there are less rows than dimension the bounds vector is cycled."));
+
+ foreach (IIntegerVectorManipulator shaker in ApplicationManager.Manager.GetInstances().OrderBy(x => x.Name))
+ if (!(shaker is ISelfAdaptiveManipulator)) Operators.Add(shaker);
+ }
+
+ [StorableHook(HookType.AfterDeserialization)]
+ private void AfterDeserialization() {
+ #region Backwards compatible code, remove with 3.4
+ if (!Parameters.ContainsKey("Bounds"))
+ Parameters.Add(new ValueLookupParameter("Bounds", "A 2 column matrix specifying the lower and upper bound for each dimension. If there are less rows than dimension the bounds vector is cycled."));
+ #endregion
+ }
+
+ #region Wiring of some parameters
+ protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs> e) {
+ base.Operators_ItemsAdded(sender, e);
+ ParameterizeOperators(e.Items);
+ }
+
+ protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs> e) {
+ base.Operators_ItemsReplaced(sender, e);
+ ParameterizeOperators(e.Items);
+ }
+
+ private void ParameterizeOperators(IEnumerable> items) {
+ if (items.Any()) {
+ foreach (IStochasticOperator op in items.Select(x => x.Value).OfType())
+ op.RandomParameter.ActualName = RandomParameter.Name;
+ foreach (IIntegerVectorManipulator op in items.Select(x => x.Value).OfType())
+ op.IntegerVectorParameter.ActualName = IntegerVectorParameter.Name;
+ }
+ }
+ #endregion
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/SimilarityCalculators/EuclideanSimilarityCalculator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/SimilarityCalculators/EuclideanSimilarityCalculator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/SimilarityCalculators/EuclideanSimilarityCalculator.cs (revision 15491)
@@ -0,0 +1,87 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Optimization.Operators;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ [Item("Euclidean Similarity Calculator for IntegerVector", "Calculates the solution similarity based on the Euclidean distance and a transformation into (0;1] between two integer vectors.")]
+ [StorableClass]
+ public sealed class EuclideanSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
+ protected override bool IsCommutative {
+ get { return true; }
+ }
+
+ [Storable]
+ private double scaling;
+ ///
+ /// The higher the scaling, the higher the similarity score for solutions of larger Euclidean distance.
+ /// A value of 1 means no scaling is applied. The function for squashing the numbers into (0;1] is
+ /// 1 / (1 + x / scaling) where x is the Euclidean distance.
+ ///
+ public double Scaling {
+ get { return scaling; }
+ set { scaling = value; }
+ }
+
+ [StorableConstructor]
+ private EuclideanSimilarityCalculator(bool deserializing) : base(deserializing) { }
+ private EuclideanSimilarityCalculator(EuclideanSimilarityCalculator original, Cloner cloner)
+ : base(original, cloner) {
+ scaling = original.scaling;
+ }
+ public EuclideanSimilarityCalculator() {
+ scaling = 1;
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new EuclideanSimilarityCalculator(this, cloner);
+ }
+
+ public static double CalculateSimilarity(IntegerVector left, IntegerVector right, double scaling = 1.0) {
+ if (left == null || right == null)
+ throw new ArgumentException("Cannot calculate similarity because one or both of the provided solutions is null.");
+ if (left.Length != right.Length)
+ throw new ArgumentException("Cannot calculate similarity because the provided solutions have different lengths.");
+ if (left.Length == 0)
+ throw new ArgumentException("Cannot calculate similarity because solutions are of length 0.");
+ if (scaling <= 0)
+ throw new ArgumentException("Cannot choose a 0 or negative scaling value.");
+ if (ReferenceEquals(left, right)) return 1.0;
+
+ var distance = 0.0;
+ for (int i = 0; i < left.Length; i++)
+ distance += (left[i] - right[i]) * (left[i] - right[i]);
+ return 1.0 / (1.0 + Math.Sqrt(distance) / scaling);
+
+ }
+
+ public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) {
+ var left = leftSolution.Variables[SolutionVariableName].Value as IntegerVector;
+ var right = rightSolution.Variables[SolutionVariableName].Value as IntegerVector;
+
+ return CalculateSimilarity(left, right, Scaling);
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/SimilarityCalculators/HammingSimilarityCalculator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/SimilarityCalculators/HammingSimilarityCalculator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/SimilarityCalculators/HammingSimilarityCalculator.cs (revision 15491)
@@ -0,0 +1,68 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Optimization.Operators;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ [Item("Hamming Similarity Calculator for IntegerVector", "Calculates the solution similarity based on the Hamming distance between two integer vectors.")]
+ [StorableClass]
+ public sealed class HammingSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
+ protected override bool IsCommutative {
+ get { return true; }
+ }
+
+ [StorableConstructor]
+ private HammingSimilarityCalculator(bool deserializing) : base(deserializing) { }
+ private HammingSimilarityCalculator(HammingSimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
+ public HammingSimilarityCalculator() { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new HammingSimilarityCalculator(this, cloner);
+ }
+
+ public static double CalculateSimilarity(IntegerVector left, IntegerVector right) {
+ if (left == null || right == null)
+ throw new ArgumentException("Cannot calculate similarity because one or both of the provided solutions is null.");
+ if (left.Length != right.Length)
+ throw new ArgumentException("Cannot calculate similarity because the provided solutions have different lengths.");
+ if (left.Length == 0)
+ throw new ArgumentException("Cannot calculate similarity because solutions are of length 0.");
+ if (ReferenceEquals(left, right)) return 1.0;
+
+ double similarity = 0.0;
+ for (int i = 0; i < left.Length; i++)
+ if (left[i] == right[i]) similarity++;
+ return similarity / left.Length;
+
+ }
+
+ public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) {
+ var left = leftSolution.Variables[SolutionVariableName].Value as IntegerVector;
+ var right = rightSolution.Variables[SolutionVariableName].Value as IntegerVector;
+
+ return CalculateSimilarity(left, right);
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/StrategyParameters/StdDevStrategyVectorCreator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/StrategyParameters/StdDevStrategyVectorCreator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/StrategyParameters/StdDevStrategyVectorCreator.cs (revision 15491)
@@ -0,0 +1,78 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Operators;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ [Item("StdDevStrategyVectorCreator", "Creates the endogeneous strategy parameters.")]
+ [StorableClass]
+ public class StdDevStrategyVectorCreator : SingleSuccessorOperator, IStochasticOperator, IIntegerVectorStdDevStrategyParameterCreator {
+ public override bool CanChangeName {
+ get { return false; }
+ }
+ public ILookupParameter RandomParameter {
+ get { return (LookupParameter)Parameters["Random"]; }
+ }
+ public ILookupParameter StrategyParameterParameter {
+ get { return (ILookupParameter)Parameters["StrategyParameter"]; }
+ }
+ public IValueLookupParameter LengthParameter {
+ get { return (IValueLookupParameter)Parameters["Length"]; }
+ }
+ public IValueLookupParameter BoundsParameter {
+ get { return (IValueLookupParameter)Parameters["Bounds"]; }
+ }
+
+ [StorableConstructor]
+ protected StdDevStrategyVectorCreator(bool deserializing) : base(deserializing) { }
+ protected StdDevStrategyVectorCreator(StdDevStrategyVectorCreator original, Cloner cloner) : base(original, cloner) { }
+ public StdDevStrategyVectorCreator()
+ : base() {
+ Parameters.Add(new LookupParameter("Random", "The random number generator to use."));
+ Parameters.Add(new LookupParameter("StrategyParameter", "The crossed strategy parameter."));
+ Parameters.Add(new ValueLookupParameter("Length", "The length of the vector."));
+ Parameters.Add(new ValueLookupParameter("Bounds", "A 2 column matrix specifying the lower and upper bound for each dimension. If there are less rows than dimension the bounds vector is cycled.", new DoubleMatrix(new double[,] { { 0, 5 } })));
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new StdDevStrategyVectorCreator(this, cloner);
+ }
+
+ public override IOperation Apply() {
+ StrategyParameterParameter.ActualValue = Randomize(RandomParameter.ActualValue, LengthParameter.ActualValue.Value, BoundsParameter.ActualValue);
+ return base.Apply();
+ }
+
+ private DoubleArray Randomize(IRandom random, int length, DoubleMatrix bounds) {
+ var result = new DoubleArray(length);
+ for (int i = 0; i < length; i++) {
+ result[i] = random.NextDouble() * bounds[i % bounds.Rows, 1] - bounds[i % bounds.Rows, 0];
+ }
+ return result;
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/StrategyParameters/StdDevStrategyVectorCrossover.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/StrategyParameters/StdDevStrategyVectorCrossover.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/StrategyParameters/StdDevStrategyVectorCrossover.cs (revision 15491)
@@ -0,0 +1,79 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Operators;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ [Item("StdDevStrategyVectorCrossover", "Crosses the strategy vector by using intermediate recombination (average crossover).")]
+ [StorableClass]
+ public class StdDevStrategyVectorCrossover : SingleSuccessorOperator, IStochasticOperator, IIntegerVectorStdDevStrategyParameterCrossover {
+ public override bool CanChangeName {
+ get { return false; }
+ }
+ public ILookupParameter RandomParameter {
+ get { return (ILookupParameter)Parameters["Random"]; }
+ }
+ public ILookupParameter> ParentsParameter {
+ get { return (ILookupParameter>)Parameters["ParentStrategyParameter"]; }
+ }
+ public ILookupParameter StrategyParameterParameter {
+ get { return (ILookupParameter)Parameters["StrategyParameter"]; }
+ }
+
+ [StorableConstructor]
+ protected StdDevStrategyVectorCrossover(bool deserializing) : base(deserializing) { }
+ protected StdDevStrategyVectorCrossover(StdDevStrategyVectorCrossover original, Cloner cloner) : base(original, cloner) { }
+ public StdDevStrategyVectorCrossover()
+ : base() {
+ Parameters.Add(new LookupParameter("Random", "The random number generator to use."));
+ Parameters.Add(new ScopeTreeLookupParameter("ParentStrategyParameter", "The strategy parameters to cross."));
+ Parameters.Add(new LookupParameter("StrategyParameter", "The crossed strategy parameter."));
+ ParentsParameter.ActualName = "StrategyParameter";
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new StdDevStrategyVectorCrossover(this, cloner);
+ }
+
+ public override IOperation Apply() {
+ StrategyParameterParameter.ActualValue = Average(RandomParameter.ActualValue, ParentsParameter.ActualValue);
+ return base.Apply();
+ }
+
+ private DoubleArray Average(IRandom random, ItemArray parents) {
+ int length = parents[0].Length;
+ var result = new DoubleArray(length);
+ for (int i = 0; i < length; i++) {
+ for (int p = 0; p < parents.Length; p++) {
+ result[i] += parents[p][i];
+ }
+ result[i] /= parents.Length;
+ }
+ return result;
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/StrategyParameters/StdDevStrategyVectorManipulator.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/StrategyParameters/StdDevStrategyVectorManipulator.cs (revision 15491)
+++ /branches/GeneralizedQAP/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/StrategyParameters/StdDevStrategyVectorManipulator.cs (revision 15491)
@@ -0,0 +1,113 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Operators;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using HeuristicLab.Random;
+
+namespace HeuristicLab.Encodings.IntegerVectorEncoding {
+ ///
+ /// Mutates the endogenous strategy parameters.
+ ///
+ [Item("StdDevStrategyVectorManipulator", "Mutates the endogenous strategy parameters.")]
+ [StorableClass]
+ public class StdDevStrategyVectorManipulator : SingleSuccessorOperator, IStochasticOperator, IIntegerVectorStdDevStrategyParameterManipulator {
+ public override bool CanChangeName {
+ get { return false; }
+ }
+ public ILookupParameter RandomParameter {
+ get { return (ILookupParameter)Parameters["Random"]; }
+ }
+ public ILookupParameter StrategyParameterParameter {
+ get { return (ILookupParameter)Parameters["StrategyParameter"]; }
+ }
+ public IValueLookupParameter GeneralLearningRateParameter {
+ get { return (IValueLookupParameter)Parameters["GeneralLearningRate"]; }
+ }
+ public IValueLookupParameter LearningRateParameter {
+ get { return (IValueLookupParameter)Parameters["LearningRate"]; }
+ }
+ public IValueLookupParameter BoundsParameter {
+ get { return (IValueLookupParameter)Parameters["Bounds"]; }
+ }
+
+ [StorableConstructor]
+ protected StdDevStrategyVectorManipulator(bool deserializing) : base(deserializing) { }
+ protected StdDevStrategyVectorManipulator(StdDevStrategyVectorManipulator original, Cloner cloner) : base(original, cloner) { }
+ public StdDevStrategyVectorManipulator()
+ : base() {
+ Parameters.Add(new LookupParameter("Random", "The random number generator to use."));
+ Parameters.Add(new LookupParameter("StrategyParameter", "The strategy parameter to manipulate."));
+ Parameters.Add(new ValueLookupParameter("GeneralLearningRate", "The general learning rate (tau0)."));
+ Parameters.Add(new ValueLookupParameter("LearningRate", "The learning rate (tau)."));
+ Parameters.Add(new ValueLookupParameter("Bounds", "A 2 column matrix specifying the lower and upper bound for each dimension. If there are less rows than dimension the bounds vector is cycled.", new DoubleMatrix(new double[,] { { 0, 5 } })));
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new StdDevStrategyVectorManipulator(this, cloner);
+ }
+
+ ///
+ /// Mutates the endogenous strategy parameters.
+ ///
+ /// The random number generator to use.
+ /// The strategy vector to manipulate.
+ /// The general learning rate dampens the mutation over all dimensions.
+ /// The learning rate dampens the mutation in each dimension.
+ /// The minimal and maximal value for each component, bounds are cycled if the length of bounds is smaller than the length of vector
+ public static void Apply(IRandom random, DoubleArray vector, double generalLearningRate, double learningRate, DoubleMatrix bounds) {
+ NormalDistributedRandom N = new NormalDistributedRandom(random, 0.0, 1.0);
+ double generalMultiplier = Math.Exp(generalLearningRate * N.NextDouble());
+ for (int i = 0; i < vector.Length; i++) {
+ double change = vector[i] * generalMultiplier * Math.Exp(learningRate * N.NextDouble());
+ if (bounds != null) {
+ double min = bounds[i % bounds.Rows, 0], max = bounds[i % bounds.Rows, 1];
+ if (min == max) vector[i] = min;
+ else {
+ if (change < min || change > max) change = Math.Max(min, Math.Min(max, change));
+ vector[i] = change;
+ }
+ }
+ }
+ }
+ ///
+ /// Mutates the endogenous strategy parameters.
+ ///
+ /// Calls of base class .
+ ///
+ public override IOperation Apply() {
+ var strategyParams = StrategyParameterParameter.ActualValue;
+ if (strategyParams != null) { // only apply if there is a strategy vector
+ IRandom random = RandomParameter.ActualValue;
+ double tau0 = GeneralLearningRateParameter.ActualValue.Value;
+ double tau = LearningRateParameter.ActualValue.Value;
+ Apply(random, strategyParams, tau0, tau, BoundsParameter.ActualValue);
+ }
+ return base.Apply();
+ }
+ }
+}
Index: /branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common/3.3/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common-3.3.csproj
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common/3.3/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common-3.3.csproj (revision 15490)
+++ /branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common/3.3/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common-3.3.csproj (revision 15491)
@@ -61,8 +61,4 @@
False
-
- ..\..\..\..\trunk\sources\bin\HeuristicLab.Encodings.IntegerVectorEncoding-3.3.dll
- False
-
..\..\..\..\trunk\sources\bin\HeuristicLab.Operators-3.3.dll
@@ -99,4 +95,9 @@
+
+ {ddfb14dd-2a85-493c-a52d-e69729bbaeb0}
+ HeuristicLab.Encodings.IntegerVectorEncoding-3.3
+ False
+
{14ab8d24-25bc-400c-a846-4627aa945192}
Index: /branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views-3.3.csproj
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views-3.3.csproj (revision 15490)
+++ /branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views-3.3.csproj (revision 15491)
@@ -67,8 +67,4 @@
False
-
- ..\..\..\..\trunk\sources\bin\HeuristicLab.IntegerVectorEncoding-3.3.dll
- False
-
..\..\..\..\trunk\sources\bin\HeuristicLab.MainForm-3.3.dll
@@ -130,4 +126,9 @@
+
+ {ddfb14dd-2a85-493c-a52d-e69729bbaeb0}
+ HeuristicLab.Encodings.IntegerVectorEncoding-3.3
+ False
+
{14ab8d24-25bc-400c-a846-4627aa945192}
Index: /branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/HeuristicLab.Problems.GeneralizedQuadraticAssignment-3.3.csproj
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/HeuristicLab.Problems.GeneralizedQuadraticAssignment-3.3.csproj (revision 15490)
+++ /branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/HeuristicLab.Problems.GeneralizedQuadraticAssignment-3.3.csproj (revision 15491)
@@ -63,8 +63,4 @@
..\..\..\..\trunk\sources\bin\HeuristicLab.Data-3.3.dll
- False
-
-
- ..\..\..\..\trunk\sources\bin\HeuristicLab.Encodings.IntegerVectorEncoding-3.3.dll
False
@@ -180,4 +176,9 @@
+
+ {ddfb14dd-2a85-493c-a52d-e69729bbaeb0}
+ HeuristicLab.Encodings.IntegerVectorEncoding-3.3
+ False
+
{14ab8d24-25bc-400c-a846-4627aa945192}