Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVector.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVector.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVector.cs (revision 11774)
@@ -0,0 +1,62 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.BinaryVectorEncoding {
+ [StorableClass]
+ [Item("BinaryVector", "Represents a vector of binary values.")]
+ public class BinaryVector : BoolArray {
+ [StorableConstructor]
+ protected BinaryVector(bool deserializing) : base(deserializing) { }
+ protected BinaryVector(BinaryVector original, Cloner cloner) : base(original, cloner) { }
+ public BinaryVector() : base() { }
+ public BinaryVector(int length) : base(length) { }
+ public BinaryVector(int length, IRandom random)
+ : this(length) {
+ Randomize(random);
+ }
+ public BinaryVector(bool[] elements) : base(elements) { }
+ public BinaryVector(BoolArray elements)
+ : this(elements.Length) {
+ for (int i = 0; i < array.Length; i++)
+ array[i] = elements[i];
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new BinaryVector(this, cloner);
+ }
+
+ public virtual void Randomize(IRandom random, int startIndex, int length) {
+ if (length > 0) {
+ for (int i = 0; i < length; i++)
+ array[startIndex + i] = random.Next(2) == 0;
+ OnReset();
+ }
+ }
+ public void Randomize(IRandom random) {
+ Randomize(random, 0, Length);
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorCreator.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorCreator.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorCreator.cs (revision 11774)
@@ -0,0 +1,67 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.BinaryVectorEncoding {
+ ///
+ /// A base class for operators creating bool-valued vectors.
+ ///
+ [Item("BinaryVectorCreator", "A base class for operators creating bool-valued vectors.")]
+ [StorableClass]
+ public abstract class BinaryVectorCreator : InstrumentedOperator, IBinaryVectorCreator, IStochasticOperator {
+ public override bool CanChangeName {
+ get { return false; }
+ }
+ public ILookupParameter RandomParameter {
+ get { return (LookupParameter)Parameters["Random"]; }
+ }
+ public ILookupParameter BinaryVectorParameter {
+ get { return (ILookupParameter)Parameters["BinaryVector"]; }
+ }
+ public IValueLookupParameter LengthParameter {
+ get { return (IValueLookupParameter)Parameters["Length"]; }
+ }
+
+ [StorableConstructor]
+ protected BinaryVectorCreator(bool deserializing) : base(deserializing) { }
+ protected BinaryVectorCreator(BinaryVectorCreator original, Cloner cloner) : base(original, cloner) { }
+ protected BinaryVectorCreator()
+ : base() {
+ Parameters.Add(new LookupParameter("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
+ Parameters.Add(new LookupParameter("BinaryVector", "The vector which should be manipulated."));
+ Parameters.Add(new ValueLookupParameter("Length", "The length of the vector."));
+ }
+
+ public sealed override IOperation InstrumentedApply() {
+ BinaryVectorParameter.ActualValue = Create(RandomParameter.ActualValue, LengthParameter.ActualValue);
+ return base.InstrumentedApply();
+ }
+
+ protected abstract BinaryVector Create(IRandom random, IntValue length);
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorCrossover.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorCrossover.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorCrossover.cs (revision 11774)
@@ -0,0 +1,68 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.Operators;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.BinaryVectorEncoding {
+ ///
+ /// A base class for operators that perform a crossover of bool-valued vectors.
+ ///
+ [Item("BinaryVectorCrossover", "A base class for operators that perform a crossover of bool-valued vectors.")]
+ [StorableClass]
+ public abstract class BinaryVectorCrossover : InstrumentedOperator, IBinaryVectorCrossover, 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 BinaryVectorCrossover(bool deserializing) : base(deserializing) { }
+ protected BinaryVectorCrossover(BinaryVectorCrossover original, Cloner cloner) : base(original, cloner) { }
+ protected BinaryVectorCrossover()
+ : 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 = "BinaryVector";
+ Parameters.Add(new LookupParameter("Child", "The child vector resulting from the crossover."));
+ ChildParameter.ActualName = "BinaryVector";
+ }
+
+ public sealed override IOperation InstrumentedApply() {
+ ChildParameter.ActualValue = Cross(RandomParameter.ActualValue, ParentsParameter.ActualValue);
+ return base.InstrumentedApply();
+ }
+
+ protected abstract BinaryVector Cross(IRandom random, ItemArray parents);
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorManipulator.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorManipulator.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorManipulator.cs (revision 11774)
@@ -0,0 +1,62 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.Operators;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.BinaryVectorEncoding {
+ ///
+ /// A base class for operators that manipulate bool-valued vectors.
+ ///
+ [Item("BinaryVectorManipulator", "A base class for operators that manipulate bool-valued vectors.")]
+ [StorableClass]
+ public abstract class BinaryVectorManipulator : InstrumentedOperator, IBinaryVectorManipulator, IStochasticOperator {
+ public override bool CanChangeName {
+ get { return false; }
+ }
+ public ILookupParameter RandomParameter {
+ get { return (LookupParameter)Parameters["Random"]; }
+ }
+ public ILookupParameter BinaryVectorParameter {
+ get { return (ILookupParameter)Parameters["BinaryVector"]; }
+ }
+
+ [StorableConstructor]
+ protected BinaryVectorManipulator(bool deserializing) : base(deserializing) { }
+ protected BinaryVectorManipulator(BinaryVectorManipulator original, Cloner cloner) : base(original, cloner) { }
+ protected BinaryVectorManipulator()
+ : base() {
+ Parameters.Add(new LookupParameter("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
+ Parameters.Add(new LookupParameter("BinaryVector", "The vector which should be manipulated."));
+ }
+
+ public sealed override IOperation InstrumentedApply() {
+ Manipulate(RandomParameter.ActualValue, BinaryVectorParameter.ActualValue);
+ return base.InstrumentedApply();
+ }
+
+ protected abstract void Manipulate(IRandom random, BinaryVector binaryVector);
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Creators/RandomBinaryVectorCreator.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Creators/RandomBinaryVectorCreator.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Creators/RandomBinaryVectorCreator.cs (revision 11774)
@@ -0,0 +1,90 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.BinaryVectorEncoding {
+ ///
+ /// Generates a new random binary vector with each element randomly initialized.
+ ///
+ [Item("RandomBinaryVectorCreator", "An operator which creates a new random binary vector with each element randomly initialized.")]
+ [StorableClass]
+ public sealed class RandomBinaryVectorCreator : BinaryVectorCreator {
+ private const string TrueProbabilityParameterName = "TruePropability";
+
+ private IFixedValueParameter TrueProbabilityParameter {
+ get { return (IFixedValueParameter)Parameters[TrueProbabilityParameterName]; }
+ }
+
+ public double TrueProbability {
+ get { return TrueProbabilityParameter.Value.Value; }
+ set { TrueProbabilityParameter.Value.Value = value; }
+ }
+
+ [StorableConstructor]
+ private RandomBinaryVectorCreator(bool deserializing) : base(deserializing) { }
+
+ private RandomBinaryVectorCreator(RandomBinaryVectorCreator original, Cloner cloner) : base(original, cloner) { }
+ public override IDeepCloneable Clone(Cloner cloner) { return new RandomBinaryVectorCreator(this, cloner); }
+
+ public RandomBinaryVectorCreator()
+ : base() {
+ Parameters.Add(new FixedValueParameter(TrueProbabilityParameterName, "Probability of true value", new DoubleValue(0.5)));
+ }
+
+ [StorableHook(HookType.AfterDeserialization)]
+ private void AfterDeserialization() {
+ if (!Parameters.ContainsKey(TrueProbabilityParameterName))
+ Parameters.Add(new FixedValueParameter(TrueProbabilityParameterName, "Probability of true value", new DoubleValue(0.5)));
+ }
+
+ ///
+ /// Generates a new random binary vector with the given .
+ ///
+ /// The random number generator.
+ /// The length of the binary vector.
+ /// The propability for true to occur at a certain position in the binary vector
+ /// The newly created binary vector.
+ public static BinaryVector Apply(IRandom random, int length, double trueProbability = 0.5) {
+ BinaryVector result;
+
+ //Backwards compatiblity code to ensure the same behavior for existing algorithm runs
+ //remove with HL 3.4
+ if (trueProbability.IsAlmost(0.5))
+ result = new BinaryVector(length, random);
+ else {
+ var values = new bool[length];
+ for (int i = 0; i < length; i++)
+ values[i] = random.NextDouble() < trueProbability;
+ result = new BinaryVector(values);
+ }
+ return result;
+ }
+
+ protected override BinaryVector Create(IRandom random, IntValue length) {
+ return Apply(random, length.Value, TrueProbability);
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/MultiBinaryVectorCrossover.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/MultiBinaryVectorCrossover.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/MultiBinaryVectorCrossover.cs (revision 11774)
@@ -0,0 +1,99 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.Operators;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using HeuristicLab.PluginInfrastructure;
+
+namespace HeuristicLab.Encodings.BinaryVectorEncoding {
+ [Item("MultiBinaryVectorCrossover", "Randomly selects and applies one of its crossovers every time it is called.")]
+ [StorableClass]
+ public class MultiBinaryVectorCrossover : StochasticMultiBranch, IBinaryVectorCrossover, IStochasticOperator {
+ public override bool CanChangeName {
+ get { return false; }
+ }
+ protected override bool CreateChildOperation {
+ get { return true; }
+ }
+
+ public ILookupParameter> ParentsParameter {
+ get { return (ILookupParameter>)Parameters["Parents"]; }
+ }
+
+ public ILookupParameter ChildParameter {
+ get { return (ILookupParameter)Parameters["Child"]; }
+ }
+
+ [StorableConstructor]
+ protected MultiBinaryVectorCrossover(bool deserializing) : base(deserializing) { }
+ protected MultiBinaryVectorCrossover(MultiBinaryVectorCrossover original, Cloner cloner) : base(original, cloner) { }
+ public MultiBinaryVectorCrossover()
+ : base() {
+ Parameters.Add(new ScopeTreeLookupParameter("Parents", "The parent binary vector which should be crossed."));
+ ParentsParameter.ActualName = "BinaryVector";
+ Parameters.Add(new LookupParameter("Child", "The child binary vector resulting from the crossover."));
+ ChildParameter.ActualName = "BinaryVector";
+
+ foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(IBinaryVectorCrossover))) {
+ if (!typeof(MultiOperator).IsAssignableFrom(type))
+ Operators.Add((IBinaryVectorCrossover)Activator.CreateInstance(type), true);
+ }
+
+ SelectedOperatorParameter.ActualName = "SelectedCrossoverOperator";
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new MultiBinaryVectorCrossover(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 (IBinaryVectorCrossover 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;
+ }
+ }
+
+ public override IOperation InstrumentedApply() {
+ if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one binary vector crossover to choose from.");
+ return base.InstrumentedApply();
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/NPointCrossover.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/NPointCrossover.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/NPointCrossover.cs (revision 11774)
@@ -0,0 +1,142 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.BinaryVectorEncoding {
+ ///
+ /// N point crossover for binary vectors.
+ ///
+ ///
+ /// It is implemented as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg..
+ ///
+ [Item("NPointCrossover", "N point crossover for binary vectors. It is implemented as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg.")]
+ [StorableClass]
+ public sealed class NPointCrossover : BinaryVectorCrossover {
+ ///
+ /// Number of crossover points.
+ ///
+ public ValueLookupParameter NParameter {
+ get { return (ValueLookupParameter)Parameters["N"]; }
+ }
+
+ [StorableConstructor]
+ private NPointCrossover(bool deserializing) : base(deserializing) { }
+ private NPointCrossover(NPointCrossover original, Cloner cloner) : base(original, cloner) { }
+ ///
+ /// Initializes a new instance of
+ ///
+ public NPointCrossover()
+ : base() {
+ Parameters.Add(new ValueLookupParameter("N", "Number of crossover points", new IntValue(2)));
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new NPointCrossover(this, cloner);
+ }
+
+ ///
+ /// Performs a N point crossover at randomly chosen positions of the two
+ /// given parent binary vectors.
+ ///
+ /// Thrown when the value for N is invalid or when the parent vectors are of different length.
+ /// A random number generator.
+ /// The first parent for crossover.
+ /// The second parent for crossover.
+ /// Number of crossover points.
+ /// The newly created binary vector, resulting from the N point crossover.
+ public static BinaryVector Apply(IRandom random, BinaryVector parent1, BinaryVector parent2, IntValue n) {
+ if (parent1.Length != parent2.Length)
+ throw new ArgumentException("NPointCrossover: The parents are of different length.");
+
+ if (n.Value > parent1.Length)
+ throw new ArgumentException("NPointCrossover: There cannot be more breakpoints than the size of the parents.");
+
+ if (n.Value < 1)
+ throw new ArgumentException("NPointCrossover: N cannot be < 1.");
+
+ int length = parent1.Length;
+ bool[] result = new bool[length];
+ int[] breakpoints = new int[n.Value];
+
+ //choose break points
+ List breakpointPool = new List();
+
+ for (int i = 0; i < length; i++)
+ breakpointPool.Add(i);
+
+ for (int i = 0; i < n.Value; i++) {
+ int index = random.Next(breakpointPool.Count);
+ breakpoints[i] = breakpointPool[index];
+ breakpointPool.RemoveAt(index);
+ }
+
+ Array.Sort(breakpoints);
+
+ //perform crossover
+ int arrayIndex = 0;
+ int breakPointIndex = 0;
+ bool firstParent = true;
+
+ while (arrayIndex < length) {
+ if (breakPointIndex < breakpoints.Length &&
+ arrayIndex == breakpoints[breakPointIndex]) {
+ breakPointIndex++;
+ firstParent = !firstParent;
+ }
+
+ if (firstParent)
+ result[arrayIndex] = parent1[arrayIndex];
+ else
+ result[arrayIndex] = parent2[arrayIndex];
+
+ arrayIndex++;
+ }
+
+ return new BinaryVector(result);
+ }
+
+ ///
+ /// Performs a N point crossover at a randomly chosen position of two
+ /// given parent binary vectors.
+ ///
+ /// Thrown if there are not exactly two parents.
+ ///
+ /// Thrown when the N parameter could not be found.
+ ///
+ /// A random number generator.
+ /// An array containing the two binary vectors that should be crossed.
+ /// The newly created binary vector, resulting from the N point crossover.
+ protected override BinaryVector Cross(IRandom random, ItemArray parents) {
+ if (parents.Length != 2) throw new ArgumentException("ERROR in NPointCrossover: The number of parents is not equal to 2");
+
+ if (NParameter.ActualValue == null) throw new InvalidOperationException("NPointCrossover: Parameter " + NParameter.ActualName + " could not be found.");
+
+ return Apply(random, parents[0], parents[1], NParameter.Value);
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs (revision 11774)
@@ -0,0 +1,62 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.BinaryVectorEncoding {
+ ///
+ /// Single point crossover for binary vectors.
+ ///
+ ///
+ /// It is implemented based on the NPointCrossover
+ ///
+ [Item("SinglePointCrossover", "Single point crossover for binary vectors. It is implemented based on the NPointCrossover.")]
+ [StorableClass]
+ public sealed class SinglePointCrossover : BinaryVectorCrossover {
+
+ [StorableConstructor]
+ private SinglePointCrossover(bool deserializing) : base(deserializing) { }
+ private 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 two
+ /// given parent binary vectors.
+ ///
+ /// Thrown if there are not exactly two parents.
+ /// A random number generator.
+ /// An array containing the two binary vectors that should be crossed.
+ /// The newly created binary vector, resulting from the single point crossover.
+ protected override BinaryVector 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 NPointCrossover.Apply(random, parents[0], parents[1], new IntValue(1));
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/UniformCrossover.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/UniformCrossover.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/UniformCrossover.cs (revision 11774)
@@ -0,0 +1,85 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.BinaryVectorEncoding {
+ ///
+ /// Uniform crossover for binary vectors.
+ ///
+ ///
+ /// It is implemented as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg.
+ ///
+ [Item("UniformCrossover", "Uniform crossover for binary vectors. It is implemented as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg.")]
+ [StorableClass]
+ public sealed class UniformCrossover : BinaryVectorCrossover {
+
+ [StorableConstructor]
+ private UniformCrossover(bool deserializing) : base(deserializing) { }
+ private UniformCrossover(UniformCrossover original, Cloner cloner) : base(original, cloner) { }
+ public UniformCrossover() : base() { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new UniformCrossover(this, cloner);
+ }
+
+ ///
+ /// Performs a uniform crossover between two binary vectors.
+ ///
+ /// A random number generator.
+ /// The first parent for crossover.
+ /// The second parent for crossover.
+ /// The newly created binary vector, resulting from the uniform crossover.
+ public static BinaryVector Apply(IRandom random, BinaryVector parent1, BinaryVector parent2) {
+ if (parent1.Length != parent2.Length)
+ throw new ArgumentException("UniformCrossover: The parents are of different length.");
+
+ int length = parent1.Length;
+ bool[] result = new bool[length];
+
+ for (int i = 0; i < length; i++) {
+ if (random.NextDouble() < 0.5)
+ result[i] = parent1[i];
+ else
+ result[i] = parent2[i];
+ }
+
+ return new BinaryVector(result);
+ }
+
+ ///
+ /// Performs a uniform crossover at a randomly chosen position of two
+ /// given parent binary vectors.
+ ///
+ /// Thrown if there are not exactly two parents.
+ /// A random number generator.
+ /// An array containing the two binary vectors that should be crossed.
+ /// The newly created binary vector, resulting from the uniform crossover.
+ protected override BinaryVector Cross(IRandom random, ItemArray parents) {
+ if (parents.Length != 2) throw new ArgumentException("ERROR in UniformCrossover: The number of parents is not equal to 2");
+
+ return Apply(random, parents[0], parents[1]);
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/HeuristicLab.Encodings.BinaryVectorEncoding-3.3.csproj
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/HeuristicLab.Encodings.BinaryVectorEncoding-3.3.csproj (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/HeuristicLab.Encodings.BinaryVectorEncoding-3.3.csproj (revision 11774)
@@ -0,0 +1,246 @@
+
+
+
+ Debug
+ AnyCPU
+ 9.0.30729
+ 2.0
+ {66D249C3-A01D-42A8-82A2-919BC8EC3D83}
+ Library
+ Properties
+ HeuristicLab.Encodings.BinaryVectorEncoding
+ HeuristicLab.Encodings.BinaryVectorEncoding-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
+ $(SolutionDir)\bin\
+ DEBUG;TRACE
+ prompt
+ 4
+ AllRules.ruleset
+ false
+
+
+ pdbonly
+ true
+ $(SolutionDir)\bin\
+ TRACE
+ prompt
+ 4
+ AllRules.ruleset
+ false
+
+
+ true
+ $(SolutionDir)\bin\
+ DEBUG;TRACE
+ full
+ x64
+ prompt
+ AllRules.ruleset
+ false
+
+
+ $(SolutionDir)\bin\
+ TRACE
+ true
+ pdbonly
+ x64
+ prompt
+ AllRules.ruleset
+ false
+
+
+ true
+ $(SolutionDir)\bin\
+ DEBUG;TRACE
+ full
+ x86
+ prompt
+ AllRules.ruleset
+ false
+
+
+ $(SolutionDir)\bin\
+ TRACE
+ true
+ pdbonly
+ x86
+ prompt
+ AllRules.ruleset
+ false
+
+
+
+
+ 3.5
+
+
+
+ 3.5
+
+
+ 3.5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {958B43BC-CC5C-4FA2-8628-2B3B01D890B6}
+ HeuristicLab.Collections-3.3
+ False
+
+
+ {A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}
+ HeuristicLab.Common-3.3
+ False
+
+
+ {C36BD924-A541-4A00-AFA8-41701378DDC5}
+ HeuristicLab.Core-3.3
+ False
+
+
+ {BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}
+ HeuristicLab.Data-3.3
+ False
+
+
+ {23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}
+ HeuristicLab.Operators-3.3
+ False
+
+
+ {25087811-F74C-4128-BC86-8324271DA13E}
+ HeuristicLab.Optimization.Operators-3.3
+ False
+
+
+ {14AB8D24-25BC-400C-A846-4627AA945192}
+ HeuristicLab.Optimization-3.3
+ False
+
+
+ {56F9106A-079F-4C61-92F6-86A84C2D84B7}
+ HeuristicLab.Parameters-3.3
+ False
+
+
+ {102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}
+ HeuristicLab.Persistence-3.3
+ False
+
+
+ {94186A6A-5176-4402-AE83-886557B53CCA}
+ HeuristicLab.PluginInfrastructure-3.3
+ False
+
+
+
+
+ False
+ .NET Framework 3.5 SP1 Client Profile
+ false
+
+
+ False
+ .NET Framework 3.5 SP1
+ true
+
+
+ False
+ Windows Installer 3.1
+ true
+
+
+
+
+
+
+ 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/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorCreator.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorCreator.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorCreator.cs (revision 11774)
@@ -0,0 +1,34 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.BinaryVectorEncoding {
+ ///
+ /// An interface which represents an operator for creating vectors of bool-valued data.
+ ///
+ public interface IBinaryVectorCreator : IBinaryVectorOperator, ISolutionCreator {
+ IValueLookupParameter LengthParameter { get; }
+ ILookupParameter BinaryVectorParameter { get; }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorCrossover.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorCrossover.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorCrossover.cs (revision 11774)
@@ -0,0 +1,33 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.BinaryVectorEncoding {
+ ///
+ /// An interface which represents an operator for crossing vectors of bool-valued data.
+ ///
+ public interface IBinaryVectorCrossover : IBinaryVectorOperator, ICrossover {
+ ILookupParameter> ParentsParameter { get; }
+ ILookupParameter ChildParameter { get; }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorManipulator.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorManipulator.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorManipulator.cs (revision 11774)
@@ -0,0 +1,32 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.BinaryVectorEncoding {
+ ///
+ /// An interface which represents an operator for manipulating vectors of bool-valued data.
+ ///
+ public interface IBinaryVectorManipulator : IBinaryVectorOperator, IManipulator {
+ ILookupParameter BinaryVectorParameter { get; }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorMoveOperator.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorMoveOperator.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorMoveOperator.cs (revision 11774)
@@ -0,0 +1,29 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.BinaryVectorEncoding {
+ public interface IBinaryVectorMoveOperator : IBinaryVectorOperator, IMoveOperator {
+ ILookupParameter BinaryVectorParameter { get; }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorMultiNeighborhoodShakingOperator.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorMultiNeighborhoodShakingOperator.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorMultiNeighborhoodShakingOperator.cs (revision 11774)
@@ -0,0 +1,28 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.BinaryVectorEncoding {
+ public interface IBinaryVectorMultiNeighborhoodShakingOperator : IBinaryVectorOperator {
+ ILookupParameter BinaryVectorParameter { get; }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorOperator.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorOperator.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorOperator.cs (revision 11774)
@@ -0,0 +1,29 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.BinaryVectorEncoding {
+ ///
+ /// An interface which represents an operator dealing with vectors of bool-valued data.
+ ///
+ public interface IBinaryVectorOperator : IOperator { }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IOneBitflipMoveOperator.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IOneBitflipMoveOperator.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IOneBitflipMoveOperator.cs (revision 11774)
@@ -0,0 +1,28 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.BinaryVectorEncoding {
+ public interface IOneBitflipMoveOperator : IBinaryVectorMoveOperator {
+ ILookupParameter OneBitflipMoveParameter { get; }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Manipulators/SinglePositionBitflipManipulator.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Manipulators/SinglePositionBitflipManipulator.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Manipulators/SinglePositionBitflipManipulator.cs (revision 11774)
@@ -0,0 +1,66 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.BinaryVectorEncoding {
+ ///
+ /// Flips exactly one bit of a binary 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("SinglePositionBitflipManipulator", "Flips exactly one bit of a binary 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 sealed class SinglePositionBitflipManipulator : BinaryVectorManipulator {
+
+ [StorableConstructor]
+ private SinglePositionBitflipManipulator(bool deserializing) : base(deserializing) { }
+ private SinglePositionBitflipManipulator(SinglePositionBitflipManipulator original, Cloner cloner) : base(original, cloner) { }
+ public SinglePositionBitflipManipulator() : base() { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new SinglePositionBitflipManipulator(this, cloner);
+ }
+
+ ///
+ /// Performs the single position bitflip mutation on a binary vector.
+ ///
+ /// The random number generator to use.
+ /// The vector that should be manipulated.
+ public static void Apply(IRandom random, BinaryVector vector) {
+ int position = random.Next(vector.Length);
+
+ vector[position] = !vector[position];
+ }
+
+ ///
+ /// Forwards the call to .
+ ///
+ /// The random number generator to use.
+ /// The vector of binary values to manipulate.
+ protected override void Manipulate(IRandom random, BinaryVector binaryVector) {
+ Apply(random, binaryVector);
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Manipulators/SomePositionsBitflipManipulator.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Manipulators/SomePositionsBitflipManipulator.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Manipulators/SomePositionsBitflipManipulator.cs (revision 11774)
@@ -0,0 +1,83 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.BinaryVectorEncoding {
+ ///
+ /// Flips some bits of a binary vector.
+ ///
+ ///
+ /// It is implemented as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg, p. 43.
+ ///
+ [Item("SomePositionsBitflipManipulator", "Flips some bits of a binary vector, each position is flipped with a probability of pm. It is implemented as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg, p. 43.")]
+ [StorableClass]
+ public sealed class SomePositionsBitflipManipulator : BinaryVectorManipulator {
+ ///
+ /// Mmutation probability for each position.
+ ///
+ public ValueLookupParameter MutationProbabilityParameter {
+ get { return (ValueLookupParameter)Parameters["MutationProbability"]; }
+ }
+
+ [StorableConstructor]
+ private SomePositionsBitflipManipulator(bool deserializing) : base(deserializing) { }
+ private SomePositionsBitflipManipulator(SomePositionsBitflipManipulator original, Cloner cloner) : base(original, cloner) { }
+ ///
+ /// Initializes a new instance of
+ ///
+ public SomePositionsBitflipManipulator()
+ : base() {
+ Parameters.Add(new ValueLookupParameter("MutationProbability", "The mutation probability for each position", new DoubleValue(0.2)));
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new SomePositionsBitflipManipulator(this, cloner);
+ }
+
+ ///
+ /// Performs the some positions bitflip mutation on a binary vector.
+ ///
+ /// The random number generator to use.
+ /// The vector that should be manipulated.
+ /// The probability a bit is flipped.
+ public static void Apply(IRandom random, BinaryVector vector, DoubleValue pm) {
+ for (int i = 0; i < vector.Length; i++) {
+ if (random.NextDouble() < pm.Value) {
+ vector[i] = !vector[i];
+ }
+ }
+ }
+
+ ///
+ /// Forwards the call to .
+ ///
+ /// The random number generator to use.
+ /// The vector of binary values to manipulate.
+ protected override void Manipulate(IRandom random, BinaryVector binaryVector) {
+ Apply(random, binaryVector, MutationProbabilityParameter.Value);
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/ExhaustiveOneBitflipMoveGenerator.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/ExhaustiveOneBitflipMoveGenerator.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/ExhaustiveOneBitflipMoveGenerator.cs (revision 11774)
@@ -0,0 +1,54 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.BinaryVectorEncoding {
+ [Item("ExhaustiveBitflipMoveGenerator", "Generates all possible one bitflip moves from a given binaryVector.")]
+ [StorableClass]
+ public sealed class ExhaustiveOneBitflipMoveGenerator : OneBitflipMoveGenerator, IExhaustiveMoveGenerator {
+ [StorableConstructor]
+ private ExhaustiveOneBitflipMoveGenerator(bool deserializing) : base(deserializing) { }
+ private ExhaustiveOneBitflipMoveGenerator(ExhaustiveOneBitflipMoveGenerator original, Cloner cloner) : base(original, cloner) { }
+ public ExhaustiveOneBitflipMoveGenerator() : base() { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new ExhaustiveOneBitflipMoveGenerator(this, cloner);
+ }
+
+ public static OneBitflipMove[] Apply(BinaryVector binaryVector) {
+ int length = binaryVector.Length;
+ int totalMoves = length;
+ OneBitflipMove[] moves = new OneBitflipMove[totalMoves];
+ for (int i = 0; i < length; i++)
+ moves[i] = new OneBitflipMove(i);
+
+ return moves;
+ }
+
+ protected override OneBitflipMove[] GenerateMoves(BinaryVector binaryVector) {
+ return Apply(binaryVector);
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMove.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMove.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMove.cs (revision 11774)
@@ -0,0 +1,41 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.BinaryVectorEncoding {
+ [Item("OneBitflipMove", "Item that describes a one bitflip move.")]
+ [StorableClass]
+ public class OneBitflipMove : OneIndexMove {
+ [StorableConstructor]
+ protected OneBitflipMove(bool deserializing) : base(deserializing) { }
+ protected OneBitflipMove(OneBitflipMove original, Cloner cloner) : base(original, cloner) { }
+ public OneBitflipMove() : base() { }
+ public OneBitflipMove(int index) : this(index, null) { }
+ public OneBitflipMove(int index, BinaryVector binaryVector) : base(index, binaryVector) { }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new OneBitflipMove(this, cloner);
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMoveAttribute.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMoveAttribute.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMoveAttribute.cs (revision 11774)
@@ -0,0 +1,53 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.BinaryVectorEncoding {
+ [Item("OneBitflipMoveAttribute", "Describes the attributes (move quality and index) of a single bitflip move.")]
+ [StorableClass]
+ public class OneBitflipMoveAttribute : Item {
+ [Storable]
+ public double MoveQuality { get; protected set; }
+ [Storable]
+ public int Index { get; protected set; }
+
+ [StorableConstructor]
+ protected OneBitflipMoveAttribute(bool deserializing) : base(deserializing) { }
+ protected OneBitflipMoveAttribute(OneBitflipMoveAttribute original, Cloner cloner)
+ : base(original, cloner) {
+ this.MoveQuality = original.MoveQuality;
+ this.Index = original.Index;
+ }
+ public OneBitflipMoveAttribute() : this(-1, 0) { }
+ public OneBitflipMoveAttribute(int index, double moveQuality)
+ : base() {
+ Index = index;
+ MoveQuality = moveQuality;
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new OneBitflipMoveAttribute(this, cloner);
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMoveGenerator.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMoveGenerator.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMoveGenerator.cs (revision 11774)
@@ -0,0 +1,70 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.Operators;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.BinaryVectorEncoding {
+ [Item("OneBitflipMoveGenerator", "Base class for all one bitflip move generators.")]
+ [StorableClass]
+ public abstract class OneBitflipMoveGenerator : SingleSuccessorOperator, IOneBitflipMoveOperator, IMoveGenerator {
+ public override bool CanChangeName {
+ get { return false; }
+ }
+ public ILookupParameter BinaryVectorParameter {
+ get { return (ILookupParameter)Parameters["BinaryVector"]; }
+ }
+ public ILookupParameter OneBitflipMoveParameter {
+ get { return (LookupParameter)Parameters["OneBitflipMove"]; }
+ }
+ protected ScopeParameter CurrentScopeParameter {
+ get { return (ScopeParameter)Parameters["CurrentScope"]; }
+ }
+
+ [StorableConstructor]
+ protected OneBitflipMoveGenerator(bool deserializing) : base(deserializing) { }
+ protected OneBitflipMoveGenerator(OneBitflipMoveGenerator original, Cloner cloner) : base(original, cloner) { }
+ public OneBitflipMoveGenerator()
+ : base() {
+ Parameters.Add(new LookupParameter("BinaryVector", "The BinaryVector for which moves should be generated."));
+ Parameters.Add(new LookupParameter("OneBitflipMove", "The moves that should be generated in subscopes."));
+ Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes."));
+ }
+
+ public override IOperation Apply() {
+ BinaryVector v = BinaryVectorParameter.ActualValue;
+ OneBitflipMove[] moves = GenerateMoves(v);
+ Scope[] moveScopes = new Scope[moves.Length];
+ for (int i = 0; i < moveScopes.Length; i++) {
+ moveScopes[i] = new Scope(i.ToString());
+ moveScopes[i].Variables.Add(new Variable(OneBitflipMoveParameter.ActualName, moves[i]));
+ }
+ CurrentScopeParameter.ActualValue.SubScopes.AddRange(moveScopes);
+ return base.Apply();
+ }
+
+ protected abstract OneBitflipMove[] GenerateMoves(BinaryVector binaryVector);
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMoveMaker.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMoveMaker.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMoveMaker.cs (revision 11774)
@@ -0,0 +1,78 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.BinaryVectorEncoding {
+ [Item("OneBitflipMoveMaker", "Peforms a one bitflip move on a given BitVector and updates the quality.")]
+ [StorableClass]
+ public class OneBitflipMoveMaker : SingleSuccessorOperator, IOneBitflipMoveOperator, IMoveMaker {
+ public override bool CanChangeName {
+ get { return false; }
+ }
+ public ILookupParameter QualityParameter {
+ get { return (ILookupParameter)Parameters["Quality"]; }
+ }
+ public ILookupParameter MoveQualityParameter {
+ get { return (ILookupParameter)Parameters["MoveQuality"]; }
+ }
+ public ILookupParameter OneBitflipMoveParameter {
+ get { return (ILookupParameter)Parameters["OneBitflipMove"]; }
+ }
+ public ILookupParameter BinaryVectorParameter {
+ get { return (ILookupParameter)Parameters["BinaryVector"]; }
+ }
+
+ [StorableConstructor]
+ protected OneBitflipMoveMaker(bool deserializing) : base(deserializing) { }
+ protected OneBitflipMoveMaker(OneBitflipMoveMaker original, Cloner cloner) : base(original, cloner) { }
+ public OneBitflipMoveMaker()
+ : base() {
+ Parameters.Add(new LookupParameter("Quality", "The quality of the solution."));
+ Parameters.Add(new LookupParameter("MoveQuality", "The relative quality of the move."));
+ Parameters.Add(new LookupParameter("OneBitflipMove", "The move to evaluate."));
+ Parameters.Add(new LookupParameter("BinaryVector", "The solution as BinaryVector."));
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new OneBitflipMoveMaker(this, cloner);
+ }
+
+ public override IOperation Apply() {
+ OneBitflipMove move = OneBitflipMoveParameter.ActualValue;
+ BinaryVector binaryVector = BinaryVectorParameter.ActualValue;
+ DoubleValue moveQuality = MoveQualityParameter.ActualValue;
+ DoubleValue quality = QualityParameter.ActualValue;
+
+ binaryVector[move.Index] = !binaryVector[move.Index];
+
+ quality.Value = moveQuality.Value;
+
+ return base.Apply();
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMoveTabuChecker.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMoveTabuChecker.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMoveTabuChecker.cs (revision 11774)
@@ -0,0 +1,106 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.BinaryVectorEncoding {
+ [Item("OneBitflipMoveTabuChecker", "Prevents peforming a one bitflip move again.")]
+ [StorableClass]
+ public class OneBitflipMoveTabuChecker : SingleSuccessorOperator, IOneBitflipMoveOperator, ITabuChecker {
+ public override bool CanChangeName {
+ get { return false; }
+ }
+ public ILookupParameter OneBitflipMoveParameter {
+ get { return (LookupParameter)Parameters["OneBitflipMove"]; }
+ }
+ public ILookupParameter BinaryVectorParameter {
+ get { return (LookupParameter)Parameters["BinaryVector"]; }
+ }
+ public ILookupParameter> TabuListParameter {
+ get { return (ILookupParameter>)Parameters["TabuList"]; }
+ }
+ public ILookupParameter MoveTabuParameter {
+ get { return (ILookupParameter)Parameters["MoveTabu"]; }
+ }
+ public IValueLookupParameter MaximizationParameter {
+ get { return (IValueLookupParameter)Parameters["Maximization"]; }
+ }
+ public ILookupParameter MoveQualityParameter {
+ get { return (ILookupParameter)Parameters["MoveQuality"]; }
+ }
+ public ValueParameter UseAspirationCriterionParameter {
+ get { return (ValueParameter)Parameters["UseAspirationCriterion"]; }
+ }
+
+ public BoolValue UseAspirationCriterion {
+ get { return UseAspirationCriterionParameter.Value; }
+ set { UseAspirationCriterionParameter.Value = value; }
+ }
+
+ [StorableConstructor]
+ protected OneBitflipMoveTabuChecker(bool deserializing) : base(deserializing) { }
+ protected OneBitflipMoveTabuChecker(OneBitflipMoveTabuChecker original, Cloner cloner) : base(original, cloner) { }
+ public OneBitflipMoveTabuChecker()
+ : base() {
+ Parameters.Add(new LookupParameter("OneBitflipMove", "The move to evaluate."));
+ Parameters.Add(new LookupParameter("MoveTabu", "The variable to store if a move was tabu."));
+ Parameters.Add(new LookupParameter("BinaryVector", "The solution as permutation."));
+ Parameters.Add(new LookupParameter>("TabuList", "The tabu list."));
+ Parameters.Add(new ValueParameter("UseAspirationCriterion", "Whether to use the aspiration criterion or not.", new BoolValue(true)));
+ Parameters.Add(new ValueLookupParameter("Maximization", "True if the problem is a maximization problem, else if it is a minimization problem."));
+ Parameters.Add(new LookupParameter("MoveQuality", "The quality of the current move."));
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new OneBitflipMoveTabuChecker(this, cloner);
+ }
+
+ public override IOperation Apply() {
+ ItemList tabuList = TabuListParameter.ActualValue;
+ OneBitflipMove move = OneBitflipMoveParameter.ActualValue;
+ double moveQuality = MoveQualityParameter.ActualValue.Value;
+ bool maximization = MaximizationParameter.ActualValue.Value;
+ bool useAspiration = UseAspirationCriterion.Value;
+ bool isTabu = false;
+ foreach (IItem tabuMove in tabuList) {
+ OneBitflipMoveAttribute attribute = (tabuMove as OneBitflipMoveAttribute);
+ if (attribute != null) {
+ if (!useAspiration
+ || maximization && moveQuality <= attribute.MoveQuality
+ || !maximization && moveQuality >= attribute.MoveQuality) {
+ if (attribute.Index == move.Index) {
+ isTabu = true;
+ break;
+ }
+ }
+ }
+ }
+ MoveTabuParameter.ActualValue = new BoolValue(isTabu);
+ return base.Apply();
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMoveTabuMaker.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMoveTabuMaker.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMoveTabuMaker.cs (revision 11774)
@@ -0,0 +1,58 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.Operators;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.BinaryVectorEncoding {
+ [Item("OneBitflipMoveTabuMaker", "Declares a given one bitflip move as tabu, by adding its attributes to the tabu list. It also removes the oldest entry in the tabu list when its size is greater than tenure.")]
+ [StorableClass]
+ public class OneBitflipMoveTabuMaker : TabuMaker, IOneBitflipMoveOperator {
+ public ILookupParameter BinaryVectorParameter {
+ get { return (ILookupParameter)Parameters["BinaryVector"]; }
+ }
+ public ILookupParameter OneBitflipMoveParameter {
+ get { return (LookupParameter)Parameters["OneBitflipMove"]; }
+ }
+
+ [StorableConstructor]
+ protected OneBitflipMoveTabuMaker(bool deserializing) : base(deserializing) { }
+ protected OneBitflipMoveTabuMaker(OneBitflipMoveTabuMaker original, Cloner cloner) : base(original, cloner) { }
+ public OneBitflipMoveTabuMaker()
+ : base() {
+ Parameters.Add(new LookupParameter("BinaryVector", "The solution as BinaryVector."));
+ Parameters.Add(new LookupParameter("OneBitflipMove", "The move that was made."));
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new OneBitflipMoveTabuMaker(this, cloner);
+ }
+
+ protected override IItem GetTabuAttribute(bool maximization, double quality, double moveQuality) {
+ double baseQuality = moveQuality;
+ if (maximization && quality > moveQuality || !maximization && quality < moveQuality) baseQuality = quality;
+ return new OneBitflipMoveAttribute(OneBitflipMoveParameter.ActualValue.Index, baseQuality);
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/StochasticOneBitflipMultiMoveGenerator.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/StochasticOneBitflipMultiMoveGenerator.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/StochasticOneBitflipMultiMoveGenerator.cs (revision 11774)
@@ -0,0 +1,71 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.BinaryVectorEncoding {
+ [Item("StochasticOneBitflipMultiMoveGenerator", "Randomly samples n from all possible one bitflip moves from a given BinaryVector.")]
+ [StorableClass]
+ public class StochasticOneBitflipMultiMoveGenerator : OneBitflipMoveGenerator, IMultiMoveGenerator {
+ public ILookupParameter RandomParameter {
+ get { return (ILookupParameter)Parameters["Random"]; }
+ }
+ public IValueLookupParameter SampleSizeParameter {
+ get { return (IValueLookupParameter)Parameters["SampleSize"]; }
+ }
+
+ public IntValue SampleSize {
+ get { return SampleSizeParameter.Value; }
+ set { SampleSizeParameter.Value = value; }
+ }
+
+ [StorableConstructor]
+ protected StochasticOneBitflipMultiMoveGenerator(bool deserializing) : base(deserializing) { }
+ protected StochasticOneBitflipMultiMoveGenerator(StochasticOneBitflipMultiMoveGenerator original, Cloner cloner) : base(original, cloner) { }
+ public StochasticOneBitflipMultiMoveGenerator()
+ : base() {
+ Parameters.Add(new LookupParameter("Random", "The random number generator."));
+ Parameters.Add(new ValueLookupParameter("SampleSize", "The number of moves to generate."));
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new StochasticOneBitflipMultiMoveGenerator(this, cloner);
+ }
+
+ public static OneBitflipMove[] Apply(BinaryVector binaryVector, IRandom random, int sampleSize) {
+ OneBitflipMove[] moves = new OneBitflipMove[sampleSize];
+ for (int i = 0; i < sampleSize; i++) {
+ moves[i] = StochasticOneBitflipSingleMoveGenerator.Apply(binaryVector, random);
+ }
+ return moves;
+ }
+
+ protected override OneBitflipMove[] GenerateMoves(BinaryVector binaryVector) {
+ IRandom random = RandomParameter.ActualValue;
+ return Apply(binaryVector, random, SampleSizeParameter.ActualValue.Value);
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/StochasticOneBitflipSingleMoveGenerator.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/StochasticOneBitflipSingleMoveGenerator.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/StochasticOneBitflipSingleMoveGenerator.cs (revision 11774)
@@ -0,0 +1,59 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.BinaryVectorEncoding {
+ [Item("StochasticOneBitflipSingleMoveGenerator", "Randomly samples a single from all possible one bitflip moves from a given BinaryVector.")]
+ [StorableClass]
+ public class StochasticOneBitflipSingleMoveGenerator : OneBitflipMoveGenerator, IStochasticOperator, ISingleMoveGenerator {
+ public ILookupParameter RandomParameter {
+ get { return (ILookupParameter)Parameters["Random"]; }
+ }
+
+ [StorableConstructor]
+ protected StochasticOneBitflipSingleMoveGenerator(bool deserializing) : base(deserializing) { }
+ protected StochasticOneBitflipSingleMoveGenerator(StochasticOneBitflipSingleMoveGenerator original, Cloner cloner) : base(original, cloner) { }
+ public StochasticOneBitflipSingleMoveGenerator()
+ : base() {
+ Parameters.Add(new LookupParameter("Random", "The random number generator."));
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new StochasticOneBitflipSingleMoveGenerator(this, cloner);
+ }
+
+ public static OneBitflipMove Apply(BinaryVector binaryVector, IRandom random) {
+ int length = binaryVector.Length;
+ int index = random.Next(length);
+ return new OneBitflipMove(index);
+ }
+
+ protected override OneBitflipMove[] GenerateMoves(BinaryVector binaryVector) {
+ IRandom random = RandomParameter.ActualValue;
+ return new OneBitflipMove[] { Apply(binaryVector, random) };
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneIndexMove.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneIndexMove.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneIndexMove.cs (revision 11774)
@@ -0,0 +1,54 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Encodings.BinaryVectorEncoding {
+ [Item("OneIndexMove", "A move on a binary vector that is specified by 1 index")]
+ [StorableClass]
+ public class OneIndexMove : Item {
+ [Storable]
+ public int Index { get; protected set; }
+ [Storable]
+ public BinaryVector BinaryVector { get; protected set; }
+
+ [StorableConstructor]
+ protected OneIndexMove(bool deserializing) : base(deserializing) { }
+ protected OneIndexMove(OneIndexMove original, Cloner cloner)
+ : base(original, cloner) {
+ this.Index = original.Index;
+ if (original.BinaryVector != null)
+ this.BinaryVector = cloner.Clone(original.BinaryVector);
+ }
+ public OneIndexMove() : this(-1, null) { }
+ public OneIndexMove(int index, BinaryVector binaryVector)
+ : base() {
+ Index = index;
+ BinaryVector = binaryVector;
+ }
+
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new OneIndexMove(this, cloner);
+ }
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Plugin.cs.frame
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Plugin.cs.frame (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Plugin.cs.frame (revision 11774)
@@ -0,0 +1,41 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.BinaryVectorEncoding {
+ ///
+ /// Plugin class for HeuristicLab.Encodings.BinaryVectorEncoding plugin.
+ ///
+ [Plugin("HeuristicLab.Encodings.BinaryVectorEncoding", "3.3.10.$WCREV$")]
+ [PluginFile("HeuristicLab.Encodings.BinaryVectorEncoding-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")]
+ public class HeuristicLabEncodingsBinaryVectorEncodingPlugin : PluginBase {
+ }
+}
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Properties/AssemblyInfo.cs.frame
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Properties/AssemblyInfo.cs.frame (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Properties/AssemblyInfo.cs.frame (revision 11774)
@@ -0,0 +1,56 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.BinaryVectorEncoding")]
+[assembly: AssemblyDescription("HeuristicLab binary vector encoding and related operators")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("HeuristicLab")]
+[assembly: AssemblyCopyright("(c) 2002-2014 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("FA3481EF-21E0-4474-9AAE-B74F27D95AEA")]
+
+// 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.10.$WCREV$")]
Index: /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/ShakingOperators/BinaryVectorShakingOperator.cs
===================================================================
--- /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/ShakingOperators/BinaryVectorShakingOperator.cs (revision 11774)
+++ /branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/ShakingOperators/BinaryVectorShakingOperator.cs (revision 11774)
@@ -0,0 +1,84 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 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.Optimization;
+using HeuristicLab.Optimization.Operators;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using HeuristicLab.PluginInfrastructure;
+
+namespace HeuristicLab.Encodings.BinaryVectorEncoding {
+ ///
+ /// A shaking operator for VNS.
+ ///
+ [Item("BinaryVectorShakingOperator", "A shaking operator for VNS which uses available manipulation operators to perform the shaking.")]
+ [StorableClass]
+ public class BinaryVectorShakingOperator : ShakingOperator, IBinaryVectorMultiNeighborhoodShakingOperator, IStochasticOperator {
+
+ public ILookupParameter BinaryVectorParameter {
+ get { return (ILookupParameter)Parameters["BinaryVector"]; }
+ }
+
+ public ILookupParameter RandomParameter {
+ get { return (LookupParameter)Parameters["Random"]; }
+ }
+
+ [StorableConstructor]
+ protected BinaryVectorShakingOperator(bool deserializing) : base(deserializing) { }
+ protected BinaryVectorShakingOperator(BinaryVectorShakingOperator original, Cloner cloner) : base(original, cloner) { }
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new BinaryVectorShakingOperator(this, cloner);
+ }
+ public BinaryVectorShakingOperator()
+ : base() {
+ Parameters.Add(new LookupParameter("BinaryVector", "The binary vector to shake."));
+ Parameters.Add(new LookupParameter("Random", "The random number generator that will be used for stochastic shaking operators."));
+ foreach (IBinaryVectorManipulator shaker in ApplicationManager.Manager.GetInstances().OrderBy(x => x.Name))
+ Operators.Add(shaker);
+ }
+
+ #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 (IBinaryVectorManipulator op in items.Select(x => x.Value).OfType())
+ op.BinaryVectorParameter.ActualName = BinaryVectorParameter.Name;
+ }
+ }
+ #endregion
+ }
+}