- Timestamp:
- 10/21/14 18:49:05 (10 years ago)
- Location:
- branches/ProgrammableProblem
- Files:
-
- 20 added
- 14 deleted
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable.Views/3.3/ProblemDefinitionScriptView.cs
r11397 r11484 25 25 namespace HeuristicLab.Problems.Programmable.Views { 26 26 [View("ProblemDefinitionScriptView")] 27 [Content(typeof(Problem DefinitionScript), IsDefaultView = true)]27 [Content(typeof(ProblemScript), IsDefaultView = true)] 28 28 public partial class ProblemDefinitionScriptView : ScriptView { 29 29 30 public new Problem DefinitionScript Content {31 get { return (Problem DefinitionScript)base.Content; }30 public new ProblemScript Content { 31 get { return (ProblemScript)base.Content; } 32 32 set { base.Content = value; } 33 33 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Helper.cs
r11405 r11484 30 30 namespace HeuristicLab.Problems.Programmable { 31 31 internal static class Helper { 32 internal static ParameterVector Extract(IScope scope, Configuration config) { 33 var binDict = new Dictionary<string, BinaryVector>(); 34 var intDict = new Dictionary<string, IntegerVector>(); 35 var realDict = new Dictionary<string, RealVector>(); 36 var permDict = new Dictionary<string, Permutation>(); 37 foreach (var param in config.Parameters) { 38 var binConfig = param.Value as BinaryParameterConfiguration; 39 if (binConfig != null) { 40 binDict.Add(param.Key, (BinaryVector)scope.Variables[param.Key].Value); 41 continue; 32 internal static Individual Extract(IScope scope, Encoding encoding) { 33 Dictionary<string, BinaryVector> binDict = null; 34 Dictionary<string, IntegerVector> intDict = null; 35 Dictionary<string, RealVector> realDict = null; 36 Dictionary<string, Permutation> permDict = null; 37 var multiEncoding = encoding as MultiEncoding; 38 if (multiEncoding != null) { 39 foreach (var enc in multiEncoding.Encodings) { 40 var binConfig = enc as BinaryEncoding; 41 if (binConfig != null) { 42 if (binDict == null) binDict = new Dictionary<string, BinaryVector>(); 43 binDict.Add(enc.Name, (BinaryVector)scope.Variables[enc.Name].Value); 44 continue; 45 } 46 var intConfig = enc as IntegerEncoding; 47 if (intConfig != null) { 48 if (intDict == null) intDict = new Dictionary<string, IntegerVector>(); 49 intDict.Add(enc.Name, (IntegerVector)scope.Variables[enc.Name].Value); 50 continue; 51 } 52 var realConfig = enc as RealEncoding; 53 if (realConfig != null) { 54 if (realDict == null) realDict = new Dictionary<string, RealVector>(); 55 realDict.Add(enc.Name, (RealVector)scope.Variables[enc.Name].Value); 56 continue; 57 } 58 var permConfig = enc as PermutationEncoding; 59 if (permConfig != null) { 60 if (permDict == null) permDict = new Dictionary<string, Permutation>(); 61 permDict.Add(enc.Name, (Permutation)scope.Variables[enc.Name].Value); 62 continue; 63 } 64 throw new InvalidOperationException("Encoding for variable " + enc.Name + " not recognized."); 42 65 } 43 var intConfig = param.Value as IntegerParameterConfiguration; 44 if (intConfig != null) { 45 intDict.Add(param.Key, (IntegerVector)scope.Variables[param.Key].Value); 46 continue; 47 } 48 var realConfig = param.Value as RealParameterConfiguration; 49 if (realConfig != null) { 50 realDict.Add(param.Key, (RealVector)scope.Variables[param.Key].Value); 51 continue; 52 } 53 var permConfig = param.Value as PermutationParameterConfiguration; 54 if (permConfig != null) { 55 permDict.Add(param.Key, (Permutation)scope.Variables[param.Key].Value); 56 continue; 57 } 58 throw new InvalidOperationException("Parameter " + param.Key + " not found."); 66 } else { 67 var binaryEncoding = encoding as BinaryEncoding; 68 var handled = binaryEncoding != null; 69 if (binaryEncoding != null) binDict = new Dictionary<string, BinaryVector>(capacity: 1) { 70 {binaryEncoding.Name, (BinaryVector)scope.Variables[binaryEncoding.Name].Value} 71 }; 72 var integerEncoding = encoding as IntegerEncoding; 73 handled = handled || integerEncoding != null; 74 if (integerEncoding != null) intDict = new Dictionary<string, IntegerVector>(capacity: 1) { 75 {integerEncoding.Name, (IntegerVector)scope.Variables[integerEncoding.Name].Value} 76 }; 77 var realEncoding = encoding as RealEncoding; 78 handled = handled || realEncoding != null; 79 if (realEncoding != null) realDict = new Dictionary<string, RealVector>(capacity: 1) { 80 {realEncoding.Name, (RealVector)scope.Variables[realEncoding.Name].Value} 81 }; 82 var permEncoding = encoding as PermutationEncoding; 83 handled = handled || permEncoding != null; 84 if (permEncoding != null) permDict = new Dictionary<string, Permutation>(capacity: 1) { 85 {permEncoding.ItemName, (Permutation)scope.Variables[permEncoding.ItemName].Value} 86 }; 87 if (!handled) throw new InvalidOperationException("Encoding for variable " + encoding.Name + " not recognized."); 59 88 } 60 return new ParameterVector( 61 binaryVectors: binDict.Count > 0 ? binDict : null, 62 integerVectors: intDict.Count > 0 ? intDict : null, 63 realVectors: realDict.Count > 0 ? realDict : null, 64 permutations: permDict.Count > 0 ? permDict : null); 89 return new Individual(binDict, intDict, realDict, permDict); 65 90 } 66 91 67 internal static void Write(IScope scope, ParameterVectorvector) {92 internal static void Write(IScope scope, Individual vector) { 68 93 foreach (var param in vector.BinaryNames) { 69 94 if (scope.Variables.ContainsKey(param)) -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj
r11405 r11484 131 131 </ItemGroup> 132 132 <ItemGroup> 133 <Compile Include=" Datastructures\PermutationParameterConfiguration.cs" />134 <Compile Include=" Datastructures\RealParameterConfiguration.cs" />135 <Compile Include=" Datastructures\IntegerParameterConfiguration.cs" />136 <Compile Include=" Datastructures\BinaryParameterConfiguration.cs" />137 <Compile Include=" Datastructures\Configuration.cs" />138 <Compile Include=" Datastructures\ParameterConfiguration.cs" />139 <Compile Include=" Datastructures\ParameterVector.cs" />133 <Compile Include="Encodings\PermutationEncoding.cs" /> 134 <Compile Include="Encodings\RealEncoding.cs" /> 135 <Compile Include="Encodings\IntegerEncoding.cs" /> 136 <Compile Include="Encodings\BinaryEncoding.cs" /> 137 <Compile Include="Encodings\MultiEncoding.cs" /> 138 <Compile Include="Encodings\Encoding.cs" /> 139 <Compile Include="Encodings\Individual.cs" /> 140 140 <Compile Include="Helper.cs" /> 141 <Compile Include="Interfaces\IParameterVectorMoveOperator.cs" /> 142 <Compile Include="Interfaces\IMultiObjectiveProblemDefinitionHost.cs" /> 141 <Compile Include="Interfaces\ISingleObjectiveMoveOperator.cs" /> 143 142 <Compile Include="Interfaces\IMultiObjectiveProblemDefinition.cs" /> 144 <Compile Include="Interfaces\ISingleObjectiveProblemDefinitionHost.cs" />145 143 <Compile Include="Interfaces\IMultiObjectiveProgrammableProblemAnalyzer.cs" /> 146 144 <Compile Include="Interfaces\ISingleObjectiveProgrammableProblemAnalyzer.cs" /> 147 145 <Compile Include="Interfaces\IMultiObjectiveProgrammableProblemEvaluator.cs" /> 148 146 <Compile Include="Interfaces\ISingleObjectiveProgrammableProblemEvaluator.cs" /> 149 <Compile Include="Operators\ ParameterVectorManipulator.cs" />150 <Compile Include="Operators\ ParameterVectorCrossover.cs" />151 <Compile Include="Operators\ ParameterVectorMoveEvaluator.cs" />152 <Compile Include="Operators\ ParameterVectorMoveGenerator.cs" />153 <Compile Include="Operators\ ParameterVectorMoveMaker.cs" />147 <Compile Include="Operators\MultiEncodingManipulator.cs" /> 148 <Compile Include="Operators\MultiEncodingCrossover.cs" /> 149 <Compile Include="Operators\SingleObjectiveMoveEvaluator.cs" /> 150 <Compile Include="Operators\SingleObjectiveMoveGenerator.cs" /> 151 <Compile Include="Operators\SingleObjectiveMoveMaker.cs" /> 154 152 <Compile Include="Operators\MultiObjectiveAnalyzer.cs" /> 155 153 <Compile Include="Operators\SingleObjectiveAnalyzer.cs" /> 156 154 <Compile Include="Operators\MultiObjectiveEvaluator.cs" /> 157 155 <Compile Include="Operators\SingleObjectiveEvaluator.cs" /> 158 <Compile Include="Operators\ ParameterVectorCreater.cs" />156 <Compile Include="Operators\MultiEncodingCreator.cs" /> 159 157 <Compile Include="Interfaces\IProblemDefinition.cs" /> 160 158 <Compile Include="Interfaces\ISingleObjectiveProblemDefinition.cs" /> 161 <Compile Include="Operators\SingleObjective ParameterVectorImprover.cs" />159 <Compile Include="Operators\SingleObjectiveImprover.cs" /> 162 160 <Compile Include="ProblemDefinition.cs" /> 163 <Compile Include="ProblemDefinitionScript.cs" /> 161 <Compile Include="ProblemScriptBase.cs" /> 162 <Compile Include="ProblemScript.cs" /> 164 163 <Compile Include="MultiObjectiveProblemDefinition.cs" /> 165 164 <Compile Include="SingleObjectiveProblemDefinition.cs" /> 166 <Compile Include="MultiObjectiveProblem DefinitionScript.cs" />167 <Compile Include="SingleObjectiveProblem DefinitionScript.cs" />165 <Compile Include="MultiObjectiveProblemScript.cs" /> 166 <Compile Include="SingleObjectiveProblemScript.cs" /> 168 167 <Compile Include="MultiObjectiveProgrammableProblem.cs" /> 169 168 <Compile Include="SingleObjectiveProgrammableProblem.cs" /> -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/IMultiObjectiveProblemDefinition.cs
r11400 r11484 20 20 #endregion 21 21 22 using System.Collections.Generic;23 22 using HeuristicLab.Core; 24 23 using HeuristicLab.Optimization; … … 27 26 public interface IMultiObjectiveProblemDefinition : IProblemDefinition { 28 27 bool[] Maximization { get; } 29 double[] Evaluate(IRandom random, ParameterVector vector); 30 void Analyze(ParameterVector[] vectors, double[][] qualities, ResultCollection results); 31 IEnumerable<ParameterVector> GetNeighbors(IRandom random, ParameterVector vector); 28 double[] Evaluate(IRandom random, Individual individual); 29 void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results); 32 30 } 33 31 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/IMultiObjectiveProgrammableProblemAnalyzer.cs
r11400 r11484 26 26 namespace HeuristicLab.Problems.Programmable { 27 27 public interface IMultiObjectiveProgrammableProblemAnalyzer : IAnalyzer { 28 ILookupParameter<IMultiObjectiveProblemDefinition Host> ProblemDefinitionParameter { get; }29 ILookupParameter< Configuration> ConfigurationParameter { get; }28 ILookupParameter<IMultiObjectiveProblemDefinition> ProblemDefinitionParameter { get; } 29 ILookupParameter<Encoding> EncodingParameter { get; } 30 30 IScopeTreeLookupParameter<DoubleArray> QualitiesParameter { get; } 31 31 ILookupParameter<ResultCollection> ResultsParameter { get; } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/IMultiObjectiveProgrammableProblemEvaluator.cs
r11400 r11484 25 25 namespace HeuristicLab.Problems.Programmable { 26 26 public interface IMultiObjectiveProgrammableProblemEvaluator : IMultiObjectiveEvaluator { 27 ILookupParameter<IMultiObjectiveProblemDefinition Host> ProblemDefinitionParameter { get; }28 ILookupParameter< Configuration> ConfigurationParameter { get; }27 ILookupParameter<IMultiObjectiveProblemDefinition> ProblemDefinitionParameter { get; } 28 ILookupParameter<Encoding> EncodingParameter { get; } 29 29 } 30 30 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/IProblemDefinition.cs
r11402 r11484 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using HeuristicLab.Core; 22 25 23 26 namespace HeuristicLab.Problems.Programmable { 24 public interface IProblemDefinition { 25 Configuration GetConfiguration(); 27 public interface IProblemDefinition : INamedItem { 28 Encoding Encoding { get; } 29 IEnumerable<Individual> GetNeighbors(IRandom random, Individual individual); 30 31 event EventHandler ProblemDefinitionChanged; 26 32 } 27 33 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/ISingleObjectiveProblemDefinition.cs
r11393 r11484 20 20 #endregion 21 21 22 using System.Collections.Generic;23 22 using HeuristicLab.Core; 24 23 using HeuristicLab.Optimization; … … 27 26 public interface ISingleObjectiveProblemDefinition : IProblemDefinition { 28 27 bool IsMaximizationProblem { get; } 29 double Evaluate(IRandom random, ParameterVector vector); 30 void Analyze(ParameterVector[] vectors, double[] qualities, ResultCollection results); 31 IEnumerable<ParameterVector> GetNeighbors(IRandom random, ParameterVector vector); 28 double Evaluate(IRandom random, Individual individual); 29 void Analyze(Individual[] individuals, double[] qualities, ResultCollection results); 32 30 } 33 31 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/ISingleObjectiveProgrammableProblemAnalyzer.cs
r11396 r11484 26 26 namespace HeuristicLab.Problems.Programmable { 27 27 public interface ISingleObjectiveProgrammableProblemAnalyzer : IAnalyzer { 28 ILookupParameter<ISingleObjectiveProblemDefinition Host> ProblemDefinitionParameter { get; }29 ILookupParameter< Configuration> ConfigurationParameter { get; }28 ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter { get; } 29 ILookupParameter<Encoding> EncodingParameter { get; } 30 30 IScopeTreeLookupParameter<DoubleValue> QualityParameter { get; } 31 31 ILookupParameter<ResultCollection> ResultsParameter { get; } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/ISingleObjectiveProgrammableProblemEvaluator.cs
r11396 r11484 25 25 namespace HeuristicLab.Problems.Programmable { 26 26 public interface ISingleObjectiveProgrammableProblemEvaluator : ISingleObjectiveEvaluator { 27 ILookupParameter<ISingleObjectiveProblemDefinition Host> ProblemDefinitionParameter { get; }28 ILookupParameter< Configuration> ConfigurationParameter { get; }27 ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter { get; } 28 ILookupParameter<Encoding> EncodingParameter { get; } 29 29 } 30 30 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProblemDefinition.cs
r11402 r11484 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Drawing; 22 using System.Linq; 25 23 using HeuristicLab.Common; 26 24 using HeuristicLab.Core; 27 25 using HeuristicLab.Optimization; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 27 29 28 namespace HeuristicLab.Problems.Programmable { 30 [Item("Multi-objective Problem Definition", "This definition can be dynamically created through code and assigned to the problem.")] 31 public class MultiObjectiveProblemDefinition : IMultiObjectiveProblemDefinitionHost, IMultiObjectiveProblemDefinition { 29 [Item("Multi-objective Problem Definition", "Base class for custom multi-objective problem definitions.")] 30 public abstract class MultiObjectiveProblemDefinition : ProblemDefinition, IMultiObjectiveProblemDefinition { 31 [Storable(Name = "Storable")] 32 32 private bool[] maximization; 33 33 public bool[] Maximization { 34 34 get { return maximization; } 35 35 set { 36 if (maximization.SequenceEqual(value)) return; 36 37 maximization = value; 37 On InstanceChanged();38 OnProblemDefinitionChanged(); 38 39 } 39 40 } 40 41 41 private Func<Configuration> configuration; 42 public Func<Configuration> Configuration { 43 get { return configuration; } 44 set { 45 configuration = value; 46 OnInstanceChanged(); 47 } 42 public abstract double[] Evaluate(IRandom random, Individual vector); 43 44 public abstract void Analyze(Individual[] vectors, double[][] qualities, ResultCollection results); 45 46 [StorableConstructor] 47 protected MultiObjectiveProblemDefinition(bool deserializing) : base(deserializing) { } 48 protected MultiObjectiveProblemDefinition(MultiObjectiveProblemDefinition original, Cloner cloner) 49 : base(original, cloner) { 50 this.maximization = (bool[])original.maximization.Clone(); 48 51 } 49 50 private Func<IRandom, ParameterVector, double[]> evaluate; 51 public Func<IRandom, ParameterVector, double[]> Evaluate { 52 get { return evaluate; } 53 set { 54 evaluate = value; 55 OnInstanceChanged(); 56 } 57 } 58 59 private Action<ParameterVector[], double[][], ResultCollection> analyze; 60 public Action<ParameterVector[], double[][], ResultCollection> Analyze { 61 get { return analyze; } 62 set { 63 analyze = value; 64 OnInstanceChanged(); 65 } 66 } 67 68 private Func<IRandom, ParameterVector, IEnumerable<ParameterVector>> neighbors; 69 public Func<IRandom, ParameterVector, IEnumerable<ParameterVector>> Neighbors { 70 get { return neighbors; } 71 set { 72 neighbors = value; 73 OnInstanceChanged(); 74 } 75 } 76 77 protected MultiObjectiveProblemDefinition(MultiObjectiveProblemDefinition original, Cloner cloner) { 78 cloner.RegisterClonedObject(original, this); 79 name = original.name; 80 description = original.description; 81 maximization = original.maximization; 82 configuration = original.configuration; 83 evaluate = original.evaluate; 84 analyze = original.analyze; 85 neighbors = original.neighbors; 86 } 87 88 public MultiObjectiveProblemDefinition() : this((string)null, null) { } 89 public MultiObjectiveProblemDefinition(string name) : this(name, null) { } 90 public MultiObjectiveProblemDefinition(string name, string description) { 91 this.name = name ?? ItemName; 92 this.description = description ?? ItemDescription; 93 configuration = () => new Configuration(); 94 evaluate = (random, vector) => new[] { 0.0, 0.0 }; 95 analyze = (vectors, doubles, results) => { }; 96 neighbors = (random, vector) => new[] { (ParameterVector)vector.Clone() }; 97 } 98 99 100 public IDeepCloneable Clone(Cloner cloner) { 101 return new MultiObjectiveProblemDefinition(this, cloner); 102 } 103 104 public IMultiObjectiveProblemDefinition Instance { 105 get { return this; } 106 } 107 108 public event EventHandler InstanceChanged; 109 protected void OnInstanceChanged() { 110 var handler = InstanceChanged; 111 if (handler != null) handler(this, EventArgs.Empty); 112 } 113 114 #region Problem definition explicit interface implementations 115 Configuration IProblemDefinition.GetConfiguration() { 116 return Configuration(); 117 } 118 119 bool[] IMultiObjectiveProblemDefinition.Maximization { 120 get { return Maximization; } 121 } 122 123 double[] IMultiObjectiveProblemDefinition.Evaluate(IRandom random, ParameterVector vector) { 124 return Evaluate(random, vector); 125 } 126 127 void IMultiObjectiveProblemDefinition.Analyze(ParameterVector[] vectors, double[][] qualities, ResultCollection results) { 128 Analyze(vectors, qualities, results); 129 } 130 131 IEnumerable<ParameterVector> IMultiObjectiveProblemDefinition.GetNeighbors(IRandom random, ParameterVector vector) { 132 return Neighbors(random, vector); 133 } 134 #endregion 135 136 #region INamedItem 137 protected string name; 138 /// <inheritdoc/> 139 /// <remarks>Calls <see cref="OnNameChanging"/> and also <see cref="OnNameChanged"/> 140 /// eventually in the setter.</remarks> 141 public string Name { 142 get { return name; } 143 set { 144 if (!CanChangeName) throw new NotSupportedException("Name cannot be changed."); 145 if (!(name.Equals(value) || (value == null) && (name == string.Empty))) { 146 CancelEventArgs<string> e = value == null ? new CancelEventArgs<string>(string.Empty) : new CancelEventArgs<string>(value); 147 OnNameChanging(e); 148 if (!e.Cancel) { 149 name = value == null ? string.Empty : value; 150 OnNameChanged(); 151 } 152 } 153 } 154 } 155 public virtual bool CanChangeName { 156 get { return true; } 157 } 158 protected string description; 159 public string Description { 160 get { return description; } 161 set { 162 if (!CanChangeDescription) throw new NotSupportedException("Description cannot be changed."); 163 if (!(description.Equals(value) || (value == null) && (description == string.Empty))) { 164 description = value == null ? string.Empty : value; 165 OnDescriptionChanged(); 166 } 167 } 168 } 169 public virtual bool CanChangeDescription { 170 get { return true; } 171 } 172 173 /// <summary> 174 /// Gets the string representation of the current instance in the format: <c>Name: [null|Value]</c>. 175 /// </summary> 176 /// <returns>The current instance as a string.</returns> 177 public override string ToString() { 178 return Name; 179 } 180 181 /// <inheritdoc/> 182 public event EventHandler<CancelEventArgs<string>> NameChanging; 183 /// <summary> 184 /// Fires a new <c>NameChanging</c> event. 185 /// </summary> 186 /// <param name="e">The event arguments of the changing.</param> 187 protected virtual void OnNameChanging(CancelEventArgs<string> e) { 188 var handler = NameChanging; 189 if (handler != null) handler(this, e); 190 } 191 /// <inheritdoc/> 192 public event EventHandler NameChanged; 193 /// <summary> 194 /// Fires a new <c>NameChanged</c> event. 195 /// </summary> 196 /// <remarks>Calls <see cref="ItemBase.OnChanged"/>.</remarks> 197 protected virtual void OnNameChanged() { 198 var handler = NameChanged; 199 if (handler != null) handler(this, EventArgs.Empty); 200 OnToStringChanged(); 201 } 202 /// <inheritdoc/> 203 public event EventHandler DescriptionChanged; 204 /// <summary> 205 /// Fires a new <c>DescriptionChanged</c> event. 206 /// </summary> 207 /// <remarks>Calls <see cref="ItemBase.OnChanged"/>.</remarks> 208 protected virtual void OnDescriptionChanged() { 209 var handler = DescriptionChanged; 210 if (handler != null) handler(this, EventArgs.Empty); 211 } 212 #endregion 213 #region IItem 214 public virtual string ItemName { 215 get { return ItemAttribute.GetName(this.GetType()); } 216 } 217 public virtual string ItemDescription { 218 get { return ItemAttribute.GetDescription(this.GetType()); } 219 } 220 public Version ItemVersion { 221 get { return ItemAttribute.GetVersion(this.GetType()); } 222 } 223 public static Image StaticItemImage { 224 get { return HeuristicLab.Common.Resources.VSImageLibrary.Class; } 225 } 226 public virtual Image ItemImage { 227 get { return ItemAttribute.GetImage(this.GetType()); } 228 } 229 public object Clone() { 230 return Clone(new Cloner()); 231 } 232 233 public event EventHandler ItemImageChanged; 234 protected virtual void OnItemImageChanged() { 235 var handler = ItemImageChanged; 236 if (handler != null) handler(this, EventArgs.Empty); 237 } 238 public event EventHandler ToStringChanged; 239 protected virtual void OnToStringChanged() { 240 var handler = ToStringChanged; 241 if (handler != null) handler(this, EventArgs.Empty); 242 } 243 #endregion 52 protected MultiObjectiveProblemDefinition(Encoding encoding) : this(encoding, "MultiObjectiveProblemDefinition", null) { } 53 protected MultiObjectiveProblemDefinition(Encoding encoding, string name) : this(encoding, name, null) { } 54 protected MultiObjectiveProblemDefinition(Encoding encoding, string name, string description) 55 : base(encoding) { } 244 56 } 245 57 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProgrammableProblem.cs
r11400 r11484 54 54 } 55 55 56 public IValueParameter<IMultiObjectiveProblemDefinition Host> ProblemDefinitionParameter {57 get { return (IValueParameter<IMultiObjectiveProblemDefinition Host>)Parameters["ProblemDefinition"]; }58 } 59 60 protected IValueParameter< Configuration> ConfigurationParameter {61 get { return (IValueParameter< Configuration>)Parameters["Configuration"]; }62 } 63 64 public IMultiObjectiveProblemDefinition HostProblemDefinition {56 public IValueParameter<IMultiObjectiveProblemDefinition> ProblemDefinitionParameter { 57 get { return (IValueParameter<IMultiObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; } 58 } 59 60 protected IValueParameter<Encoding> EncodingParameter { 61 get { return (IValueParameter<Encoding>)Parameters["Encoding"]; } 62 } 63 64 public IMultiObjectiveProblemDefinition ProblemDefinition { 65 65 get { return ProblemDefinitionParameter.Value; } 66 66 set { ProblemDefinitionParameter.Value = value; } … … 68 68 69 69 [Storable] 70 protected List<IParameter> Dynamic ConfigurationParameters;70 protected List<IParameter> DynamicEncodingParameters; 71 71 72 72 [StorableConstructor] … … 74 74 protected MultiObjectiveProgrammableProblem(MultiObjectiveProgrammableProblem original, Cloner cloner) 75 75 : base(original, cloner) { 76 Dynamic ConfigurationParameters = original.DynamicConfigurationParameters.Select(cloner.Clone).ToList();76 DynamicEncodingParameters = original.DynamicEncodingParameters.Select(cloner.Clone).ToList(); 77 77 RegisterEventHandlers(); 78 78 } 79 79 public MultiObjectiveProgrammableProblem() 80 : base(new MultiObjectiveEvaluator(), new ParameterVectorCreater()) {81 Parameters.Add(new ValueParameter<IMultiObjectiveProblemDefinition Host>("ProblemDefinition", "Defines the problem.", new MultiObjectiveProblemDefinitionScript() { Name = Name }));82 Parameters.Add(new ValueParameter< Configuration>("Configuration", "Describes which parameters exist, what they're called, what type they are and their bounds if any."));83 84 Dynamic ConfigurationParameters = new List<IParameter>();80 : base(new MultiObjectiveEvaluator(), new MultiEncodingCreator()) { 81 Parameters.Add(new ValueParameter<IMultiObjectiveProblemDefinition>("ProblemDefinition", "Defines the problem.", new MultiObjectiveProblemScript() { Name = Name })); 82 Parameters.Add(new ValueParameter<Encoding>("Encoding", "Describes which parameters exist, what they're called, what type they are and their bounds if any.")); 83 84 DynamicEncodingParameters = new List<IParameter>(); 85 85 86 86 Operators.Add(new MultiObjectiveAnalyzer()); … … 113 113 114 114 private void RegisterHostInstanceChanges() { 115 ProblemDefinitionParameter.Value. InstanceChanged += ProblemDefinitionHostOnInstanceChanged;115 ProblemDefinitionParameter.Value.ProblemDefinitionChanged += ProblemDefinitionChanged; 116 116 ProblemDefinitionParameter.Value.NameChanged += ProblemDefinitionHostOnNameChanged; 117 117 } … … 132 132 } 133 133 134 protected virtual void ProblemDefinition HostOnInstanceChanged(object sender, EventArgs eventArgs) {134 protected virtual void ProblemDefinitionChanged(object sender, EventArgs eventArgs) { 135 135 Parameterize(); 136 136 } 137 137 138 138 protected virtual void Parameterize() { 139 var instance = ProblemDefinitionParameter.Value.Instance;140 if ( instance== null) return;141 142 Configuration configuration;139 var definition = ProblemDefinitionParameter.Value; 140 if (definition == null) return; 141 142 Encoding encoding; 143 143 try { 144 configuration = instance.GetConfiguration();144 encoding = definition.Encoding; 145 145 } catch { return; } 146 ConfigurationParameter.Value = configuration;147 Maximization = new BoolArray( instance.Maximization);148 149 Evaluator. ConfigurationParameter.ActualName = ConfigurationParameter.Name;146 EncodingParameter.Value = encoding; 147 Maximization = new BoolArray(definition.Maximization); 148 149 Evaluator.EncodingParameter.ActualName = EncodingParameter.Name; 150 150 Evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 151 151 foreach (var evalOp in Operators.OfType<IMultiObjectiveProgrammableProblemEvaluator>()) { 152 evalOp. ConfigurationParameter.ActualName = ConfigurationParameter.Name;152 evalOp.EncodingParameter.ActualName = EncodingParameter.Name; 153 153 evalOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 154 154 } 155 155 foreach (var analyzeOp in Operators.OfType<IMultiObjectiveProgrammableProblemAnalyzer>()) { 156 analyzeOp. ConfigurationParameter.ActualName = ConfigurationParameter.Name;156 analyzeOp.EncodingParameter.ActualName = EncodingParameter.Name; 157 157 analyzeOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 158 158 analyzeOp.QualitiesParameter.ActualName = Evaluator.QualitiesParameter.ActualName; 159 159 } 160 160 161 var solutionCreators = UpdateDynamicConfigurationParameters(configuration); 162 163 if (solutionCreators.Count == 1) { 164 Operators.RemoveAll(x => x is ParameterVectorCrossover 165 || x is ParameterVectorManipulator); 166 UpdateSingleVectorEncodingOperators(solutionCreators, configuration); 167 } else { 168 UpdateMultiVectorEncodingOperators(solutionCreators, configuration); 169 } 170 UpdateMoveOperators(); 171 } 172 173 protected virtual List<ISolutionCreator> UpdateDynamicConfigurationParameters(Configuration configuration) { 174 foreach (var param in DynamicConfigurationParameters) 161 foreach (var param in DynamicEncodingParameters) 175 162 if (Parameters.Contains(param)) Parameters.Remove(param); 176 DynamicConfigurationParameters.Clear(); 177 178 var solutionCreators = new List<ISolutionCreator>(); 179 foreach (var param in configuration.Parameters) { 180 #region Configure BinaryVector Creator 181 var binConfig = param.Value as BinaryParameterConfiguration; 182 if (binConfig != null) { 183 var p = new ValueParameter<IntValue>(param.Key + "Length", binConfig.Length); 184 DynamicConfigurationParameters.Add(p); 185 186 var creator = new RandomBinaryVectorCreator(); 187 creator.BinaryVectorParameter.ActualName = param.Key; 188 creator.LengthParameter.ActualName = p.Name; 189 solutionCreators.Add(creator); 190 } 191 #endregion 192 #region Configure IntegerVector Creator 193 var intConfig = param.Value as IntegerParameterConfiguration; 194 if (intConfig != null) { 195 var l = new ValueParameter<IntValue>(param.Key + "Length", intConfig.Length); 196 var b = new ValueParameter<IntMatrix>(param.Key + "Bounds", intConfig.Bounds); 197 DynamicConfigurationParameters.Add(l); 198 DynamicConfigurationParameters.Add(b); 199 200 var creator = new UniformRandomIntegerVectorCreator(); 201 creator.IntegerVectorParameter.ActualName = param.Key; 202 creator.LengthParameter.ActualName = l.Name; 203 creator.BoundsParameter.ActualName = b.Name; 204 solutionCreators.Add(creator); 205 } 206 #endregion 207 #region Configure RealVector Creator 208 var realConfig = param.Value as RealParameterConfiguration; 209 if (realConfig != null) { 210 var l = new ValueParameter<IntValue>(param.Key + "Length", realConfig.Length); 211 var b = new ValueParameter<DoubleMatrix>(param.Key + "Bounds", realConfig.Bounds); 212 DynamicConfigurationParameters.Add(l); 213 DynamicConfigurationParameters.Add(b); 214 215 var creator = new UniformRandomRealVectorCreator(); 216 creator.RealVectorParameter.ActualName = param.Key; 217 creator.LengthParameter.ActualName = l.Name; 218 creator.BoundsParameter.ActualName = b.Name; 219 solutionCreators.Add(creator); 220 } 221 #endregion 222 #region Configure Permutation Creator 223 var permConfig = param.Value as PermutationParameterConfiguration; 224 if (permConfig != null) { 225 var l = new ValueParameter<IntValue>(param.Key + "Length", permConfig.Length); 226 DynamicConfigurationParameters.Add(l); 227 228 var creator = new RandomPermutationCreator(); 229 creator.PermutationParameter.ActualName = param.Key; 230 creator.LengthParameter.ActualName = l.Name; 231 creator.PermutationTypeParameter.Value = permConfig.Type; 232 solutionCreators.Add(creator); 233 } 234 #endregion 235 } 236 237 foreach (var param in DynamicConfigurationParameters) { 163 DynamicEncodingParameters.Clear(); 164 165 var creator = ConfigureCreator(encoding); 166 167 foreach (var param in DynamicEncodingParameters) { 238 168 param.Hidden = true; 239 169 Parameters.Add(param); 240 170 } 241 return solutionCreators; 242 } 243 244 protected virtual void UpdateSingleVectorEncodingOperators(List<ISolutionCreator> solutionCreators, Configuration configuration) { 245 var newCreator = solutionCreators.Single(); 171 172 var multiEncoding = encoding as MultiEncoding; 173 if (multiEncoding != null) { 174 ConfigureMultiVectorEncodingOperators((MultiEncodingCreator)creator, multiEncoding); 175 } else { 176 ConfigureSingleEncodingOperators(creator, encoding); 177 } 178 } 179 180 protected virtual ISolutionCreator ConfigureCreator(Encoding encoding) { 181 #region Configure MultiEncoding Creator 182 var multiEncoding = encoding as MultiEncoding; 183 if (multiEncoding != null) { 184 var creator = new MultiEncodingCreator(); 185 foreach (var enc in multiEncoding.Encodings) { 186 if (enc is MultiEncoding) throw new InvalidOperationException("MultiEncoding within a MultiEncoding is not supported."); 187 creator.Operators.Add(ConfigureCreator(enc)); 188 } 189 return creator; 190 } 191 #endregion 192 #region Configure BinaryVector Creator 193 var binEnc = encoding as BinaryEncoding; 194 if (binEnc != null) { 195 var p = new ValueParameter<IntValue>(binEnc.Name + "Length", binEnc.Length); 196 DynamicEncodingParameters.Add(p); 197 198 var creator = new RandomBinaryVectorCreator(); 199 creator.BinaryVectorParameter.ActualName = binEnc.Name; 200 creator.LengthParameter.ActualName = p.Name; 201 return creator; 202 } 203 #endregion 204 #region Configure IntegerVector Creator 205 var intEnc = encoding as IntegerEncoding; 206 if (intEnc != null) { 207 var l = new ValueParameter<IntValue>(intEnc.Name + "Length", intEnc.Length); 208 var b = new ValueParameter<IntMatrix>(intEnc.Name + "Bounds", intEnc.Bounds); 209 DynamicEncodingParameters.Add(l); 210 DynamicEncodingParameters.Add(b); 211 212 var creator = new UniformRandomIntegerVectorCreator(); 213 creator.IntegerVectorParameter.ActualName = intEnc.Name; 214 creator.LengthParameter.ActualName = l.Name; 215 creator.BoundsParameter.ActualName = b.Name; 216 return creator; 217 } 218 #endregion 219 #region Configure RealVector Creator 220 var realEnc = encoding as RealEncoding; 221 if (realEnc != null) { 222 var l = new ValueParameter<IntValue>(realEnc.Name + "Length", realEnc.Length); 223 var b = new ValueParameter<DoubleMatrix>(realEnc.Name + "Bounds", realEnc.Bounds); 224 DynamicEncodingParameters.Add(l); 225 DynamicEncodingParameters.Add(b); 226 227 var creator = new UniformRandomRealVectorCreator(); 228 creator.RealVectorParameter.ActualName = realEnc.Name; 229 creator.LengthParameter.ActualName = l.Name; 230 creator.BoundsParameter.ActualName = b.Name; 231 return creator; 232 } 233 #endregion 234 #region Configure Permutation Creator 235 var permEnc = encoding as PermutationEncoding; 236 if (permEnc != null) { 237 var l = new ValueParameter<IntValue>(permEnc.Name + "Length", permEnc.Length); 238 DynamicEncodingParameters.Add(l); 239 240 var creator = new RandomPermutationCreator(); 241 creator.PermutationParameter.ActualName = permEnc.Name; 242 creator.LengthParameter.ActualName = l.Name; 243 creator.PermutationTypeParameter.Value = permEnc.Type; 244 return creator; 245 } 246 #endregion 247 throw new ArgumentException(string.Format("Encoding {0} is unknown.", encoding != null ? encoding.GetType().FullName : "(null)")); 248 } 249 250 protected virtual void ConfigureSingleEncodingOperators(ISolutionCreator newCreator, Encoding encoding) { 251 // remove all multiencoding operators 252 Operators.RemoveAll(x => x is MultiEncodingCrossover 253 || x is MultiEncodingManipulator 254 || x is MultiEncodingCreator); 255 246 256 #region Configure Operators for BinaryVectorEncoding 247 257 var binCreator = newCreator as IBinaryVectorCreator; … … 256 266 257 267 #region Wire BinaryVector Crossovers 258 Operators.RemoveAll(x => x is IBinaryVectorCrossover && ((IBinaryVectorCrossover)x).ChildParameter.ActualName != paramName); 259 var crossovers = ApplicationManager.Manager.GetInstances<IBinaryVectorCrossover>().ToList(); 268 var crossovers = Operators.OfType<IBinaryVectorCrossover>() 269 .Union(ApplicationManager.Manager.GetInstances<IBinaryVectorCrossover>(), new TypeEqualityComparer<IBinaryVectorCrossover>()) 270 .ToList(); 260 271 foreach (var xo in crossovers) { 261 272 xo.ChildParameter.ActualName = binCreator.BinaryVectorParameter.ActualName; … … 264 275 xo.ParentsParameter.Hidden = true; 265 276 } 266 Operators.AddRange(crossovers. Where(x => Operators.All(y => x.GetType() != y.GetType())));277 Operators.AddRange(crossovers.Except(Operators.OfType<IBinaryVectorCrossover>())); 267 278 #endregion 268 279 #region Wire BinaryVector Manipulators 269 Operators.RemoveAll(x => x is IBinaryVectorManipulator && ((IBinaryVectorManipulator)x).BinaryVectorParameter.ActualName != paramName); 270 var manipulators = ApplicationManager.Manager.GetInstances<IBinaryVectorManipulator>().ToList(); 280 var manipulators = Operators.OfType<IBinaryVectorManipulator>() 281 .Union(ApplicationManager.Manager.GetInstances<IBinaryVectorManipulator>(), new TypeEqualityComparer<IBinaryVectorManipulator>()) 282 .ToList(); 271 283 foreach (var m in manipulators) { 272 284 m.BinaryVectorParameter.ActualName = binCreator.BinaryVectorParameter.ActualName; 273 285 m.BinaryVectorParameter.Hidden = true; 274 286 } 275 Operators.AddRange(manipulators. Where(x => Operators.All(y => x.GetType() != y.GetType())));287 Operators.AddRange(manipulators.Except(Operators.OfType<IBinaryVectorManipulator>())); 276 288 #endregion 277 289 #region Wire BinaryVector ShakingOperators 278 Operators.RemoveAll(x => x is IBinaryVectorMultiNeighborhoodShakingOperator && ((IBinaryVectorManipulator)x).BinaryVectorParameter.ActualName != paramName); 279 var shakingOperators = ApplicationManager.Manager.GetInstances<IBinaryVectorMultiNeighborhoodShakingOperator>().ToList(); 290 var shakingOperators = Operators.OfType<IBinaryVectorMultiNeighborhoodShakingOperator>() 291 .Union(ApplicationManager.Manager.GetInstances<IBinaryVectorMultiNeighborhoodShakingOperator>(), new TypeEqualityComparer<IBinaryVectorMultiNeighborhoodShakingOperator>()) 292 .ToList(); 280 293 foreach (var so in shakingOperators) { 281 294 so.BinaryVectorParameter.ActualName = paramName; 282 295 so.BinaryVectorParameter.Hidden = true; 283 296 } 284 Operators.AddRange(shakingOperators. Where(x => Operators.All(y => x.GetType() != y.GetType())));297 Operators.AddRange(shakingOperators.Except(Operators.OfType<IBinaryVectorMultiNeighborhoodShakingOperator>())); 285 298 #endregion 286 299 } else { … … 303 316 304 317 #region Wire IntegerVector Crossovers 305 Operators.RemoveAll(x => x is IIntegerVectorCrossover && ((IIntegerVectorCrossover)x).ChildParameter.ActualName != paramName); 306 var crossovers = ApplicationManager.Manager.GetInstances<IIntegerVectorCrossover>().ToList(); 318 var crossovers = Operators.OfType<IIntegerVectorCrossover>() 319 .Union(ApplicationManager.Manager.GetInstances<IIntegerVectorCrossover>(), new TypeEqualityComparer<IIntegerVectorCrossover>()) 320 .ToList(); 307 321 foreach (var xo in crossovers) { 308 322 xo.ChildParameter.ActualName = intCreator.IntegerVectorParameter.ActualName; … … 316 330 } 317 331 } 318 Operators.AddRange(crossovers. Where(x => Operators.All(y => x.GetType() != y.GetType())));332 Operators.AddRange(crossovers.Except(Operators.OfType<IIntegerVectorCrossover>())); 319 333 #endregion 320 334 #region Wire IntegerVector Manipulators 321 Operators.RemoveAll(x => x is IIntegerVectorManipulator && ((IIntegerVectorManipulator)x).IntegerVectorParameter.ActualName != paramName); 322 var manipulators = ApplicationManager.Manager.GetInstances<IIntegerVectorManipulator>().ToList(); 335 var manipulators = Operators.OfType<IIntegerVectorManipulator>() 336 .Union(ApplicationManager.Manager.GetInstances<IIntegerVectorManipulator>(), new TypeEqualityComparer<IIntegerVectorManipulator>()) 337 .ToList(); 323 338 foreach (var m in manipulators) { 324 339 m.IntegerVectorParameter.ActualName = intCreator.IntegerVectorParameter.ActualName; … … 338 353 } 339 354 } 340 Operators.AddRange(manipulators. Where(x => Operators.All(y => x.GetType() != y.GetType())));355 Operators.AddRange(manipulators.Except(Operators.OfType<IIntegerVectorManipulator>())); 341 356 #region Wire IntegerVector StrategyParameters for SelfAdaptiveManipulators 342 Operators.RemoveAll(x => x is IStrategyParameterCreator && !(x is IIntegerVectorStdDevStrategyParameterCreator) || x is IIntegerVectorStdDevStrategyParameterCreator && ((IIntegerVectorStdDevStrategyParameterCreator)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 343 Operators.RemoveAll(x => x is IStrategyParameterManipulator && !(x is IIntegerVectorStdDevStrategyParameterManipulator) || x is IIntegerVectorStdDevStrategyParameterManipulator && ((IIntegerVectorStdDevStrategyParameterManipulator)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 344 Operators.RemoveAll(x => x is IStrategyParameterCrossover && !(x is IIntegerVectorStdDevStrategyParameterCrossover) || x is IIntegerVectorStdDevStrategyParameterCrossover && ((IIntegerVectorStdDevStrategyParameterCrossover)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 345 var strategyOperators = ApplicationManager.Manager.GetInstances<IIntegerVectorStdDevStrategyParameterOperator>().ToList(); 346 if (!(configuration.Parameters.First().Value is IntegerParameterConfiguration)) throw new InvalidOperationException("Single-encoded problem with integervector creator that is not an integer-coded problem."); 347 var problemSize = ((IntegerParameterConfiguration)configuration.Parameters.First().Value).Length.Value; 348 var b = ((IntegerParameterConfiguration)configuration.Parameters.First().Value).Bounds; 357 var strategyOperators = Operators.OfType<IIntegerVectorStdDevStrategyParameterOperator>() 358 .Union(ApplicationManager.Manager.GetInstances<IIntegerVectorStdDevStrategyParameterOperator>(), new TypeEqualityComparer<IIntegerVectorStdDevStrategyParameterOperator>()) 359 .ToList(); 360 var problemSize = ((IntegerEncoding)encoding).Length.Value; 361 var b = ((IntegerEncoding)encoding).Bounds; 349 362 var bounds = new DoubleMatrix(b.Rows, b.Columns); 350 363 for (var i = 0; i < bounds.Rows; i++) { … … 376 389 } 377 390 } 378 Operators.AddRange(strategyOperators. Where(x => Operators.All(y => x.GetType() != y.GetType())));391 Operators.AddRange(strategyOperators.Except(Operators.OfType<IIntegerVectorStdDevStrategyParameterOperator>())); 379 392 #endregion 380 393 #endregion 381 394 #region Wire IntegerVector ShakingOperators 382 Operators.RemoveAll(x => x is IIntegerVectorMultiNeighborhoodShakingOperator && ((IIntegerVectorMultiNeighborhoodShakingOperator)x).IntegerVectorParameter.ActualName != paramName); 383 var shakingOperators = ApplicationManager.Manager.GetInstances<IIntegerVectorMultiNeighborhoodShakingOperator>().ToList(); 395 var shakingOperators = Operators.OfType<IIntegerVectorMultiNeighborhoodShakingOperator>() 396 .Union(ApplicationManager.Manager.GetInstances<IIntegerVectorMultiNeighborhoodShakingOperator>(), new TypeEqualityComparer<IIntegerVectorMultiNeighborhoodShakingOperator>()) 397 .ToList(); 384 398 foreach (var so in shakingOperators) { 385 399 so.IntegerVectorParameter.ActualName = paramName; 386 400 so.IntegerVectorParameter.Hidden = true; 387 401 } 388 Operators.AddRange(shakingOperators. Where(x => Operators.All(y => x.GetType() != y.GetType())));402 Operators.AddRange(shakingOperators.Except(Operators.OfType<IIntegerVectorMultiNeighborhoodShakingOperator>())); 389 403 #endregion 390 404 } else { … … 408 422 409 423 #region Wire RealVector Crossovers 410 Operators.RemoveAll(x => x is IRealVectorCrossover && ((IRealVectorCrossover)x).ChildParameter.ActualName != paramName); 411 var crossovers = ApplicationManager.Manager.GetInstances<IRealVectorCrossover>().ToList(); 424 var crossovers = Operators.OfType<IRealVectorCrossover>() 425 .Union(ApplicationManager.Manager.GetInstances<IRealVectorCrossover>(), new TypeEqualityComparer<IRealVectorCrossover>()) 426 .ToList(); 412 427 foreach (var xo in crossovers) { 413 428 xo.ChildParameter.ActualName = paramName; … … 418 433 xo.BoundsParameter.Hidden = true; 419 434 } 420 Operators.AddRange(crossovers. Where(x => Operators.All(y => x.GetType() != y.GetType())));435 Operators.AddRange(crossovers.Except(Operators.OfType<IRealVectorCrossover>())); 421 436 #endregion 422 437 #region Wire RealVector Manipulators 423 Operators.RemoveAll(x => x is IRealVectorManipulator && ((IRealVectorManipulator)x).RealVectorParameter.ActualName != paramName); 424 var manipulators = ApplicationManager.Manager.GetInstances<IRealVectorManipulator>().ToList(); 438 var manipulators = Operators.OfType<IRealVectorManipulator>() 439 .Union(ApplicationManager.Manager.GetInstances<IRealVectorManipulator>(), new TypeEqualityComparer<IRealVectorManipulator>()) 440 .ToList(); 425 441 foreach (var m in manipulators) { 426 442 m.RealVectorParameter.ActualName = paramName; … … 437 453 } 438 454 } 439 Operators.AddRange(manipulators. Where(x => Operators.All(y => x.GetType() != y.GetType())));455 Operators.AddRange(manipulators.Except(Operators.OfType<IRealVectorManipulator>())); 440 456 #region Wire RealVector Strategy Parameters for SelfAdaptiveManipulators 441 442 Operators.RemoveAll(x => x is IStrategyParameterCreator && !(x is IRealVectorStdDevStrategyParameterCreator) || x is IRealVectorStdDevStrategyParameterCreator && ((IRealVectorStdDevStrategyParameterCreator)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 443 Operators.RemoveAll(x => x is IStrategyParameterManipulator && !(x is IRealVectorStdDevStrategyParameterManipulator) || x is IRealVectorStdDevStrategyParameterManipulator && ((IRealVectorStdDevStrategyParameterManipulator)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 444 Operators.RemoveAll(x => x is IStrategyParameterCrossover && !(x is IRealVectorStdDevStrategyParameterCrossover) || x is IRealVectorStdDevStrategyParameterCrossover && ((IRealVectorStdDevStrategyParameterCrossover)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 445 var strategyOperators = ApplicationManager.Manager.GetInstances<IRealVectorStdDevStrategyParameterOperator>().ToList(); 446 if (!(configuration.Parameters.First().Value is RealParameterConfiguration)) throw new InvalidOperationException("Single-encoded problem with realvector creator that is not a real-coded problem."); 447 var problemSize = ((RealParameterConfiguration)configuration.Parameters.First().Value).Length.Value; 448 var bounds = (DoubleMatrix)((RealParameterConfiguration)configuration.Parameters.First().Value).Bounds.Clone(); 457 var strategyOperators = Operators.OfType<IRealVectorStdDevStrategyParameterOperator>() 458 .Union(ApplicationManager.Manager.GetInstances<IRealVectorStdDevStrategyParameterOperator>(), new TypeEqualityComparer<IRealVectorStdDevStrategyParameterOperator>()) 459 .ToList(); 460 var problemSize = ((RealEncoding)encoding).Length.Value; 461 var bounds = (DoubleMatrix)((RealEncoding)encoding).Bounds.Clone(); 449 462 for (var i = 0; i < bounds.Rows; i++) { 450 463 bounds[i, 1] = 0.1 * (bounds[i, 1] - bounds[i, 0]); … … 474 487 } 475 488 } 476 Operators.AddRange(strategyOperators. Where(x => Operators.All(y => x.GetType() != y.GetType())));489 Operators.AddRange(strategyOperators.Except(Operators.OfType<IRealVectorStdDevStrategyParameterOperator>())); 477 490 #endregion 478 491 #endregion 479 492 #region Wire RealVector ParticleCreators 480 Operators.RemoveAll(x => x is IRealVectorParticleCreator && ((IRealVectorParticleCreator)x).RealVectorParameter.ActualName != paramName); 481 var particleCreators = ApplicationManager.Manager.GetInstances<IRealVectorParticleCreator>().ToList(); 493 var particleCreators = Operators.OfType<IRealVectorParticleCreator>() 494 .Union(ApplicationManager.Manager.GetInstances<IRealVectorParticleCreator>(), new TypeEqualityComparer<IRealVectorParticleCreator>()) 495 .ToList(); 482 496 foreach (var pc in particleCreators) { 483 497 pc.RealVectorParameter.ActualName = paramName; … … 488 502 pc.ProblemSizeParameter.Hidden = true; 489 503 } 490 Operators.AddRange(particleCreators. Where(x => Operators.All(y => x.GetType() != y.GetType())));504 Operators.AddRange(particleCreators.Except(Operators.OfType<IRealVectorParticleCreator>())); 491 505 #endregion 492 506 #region Wire RealVector ParticleUpdaters 493 Operators.RemoveAll(x => x is IRealVectorParticleUpdater && ((IRealVectorParticleUpdater)x).RealVectorParameter.ActualName != paramName); 494 var particleUpdaters = ApplicationManager.Manager.GetInstances<IRealVectorParticleUpdater>().ToList(); 507 var particleUpdaters = Operators.OfType<IRealVectorParticleUpdater>() 508 .Union(ApplicationManager.Manager.GetInstances<IRealVectorParticleUpdater>(), new TypeEqualityComparer<IRealVectorParticleUpdater>()) 509 .ToList(); 495 510 foreach (var pu in particleUpdaters) { 496 511 pu.RealVectorParameter.ActualName = paramName; … … 499 514 pu.BoundsParameter.Hidden = true; 500 515 } 501 Operators.AddRange(particleUpdaters. Where(x => Operators.All(y => x.GetType() != y.GetType())));516 Operators.AddRange(particleUpdaters.Except(Operators.OfType<IRealVectorParticleUpdater>())); 502 517 #endregion 503 518 #region Wire RealVector SwarmUpdaters 504 Operators.RemoveAll(x => x is IRealVectorSwarmUpdater && ((IRealVectorSwarmUpdater)x).RealVectorParameter.ActualName != paramName); 505 var swarmUpdaters = ApplicationManager.Manager.GetInstances<IRealVectorSwarmUpdater>().ToList(); 519 var swarmUpdaters = Operators.OfType<IRealVectorSwarmUpdater>() 520 .Union(ApplicationManager.Manager.GetInstances<IRealVectorSwarmUpdater>(), new TypeEqualityComparer<IRealVectorSwarmUpdater>()) 521 .ToList(); 506 522 foreach (var su in swarmUpdaters) { 507 523 su.RealVectorParameter.ActualName = paramName; … … 510 526 su.MaximizationParameter.Hidden = true; 511 527 } 512 Operators.AddRange(swarmUpdaters. Where(x => Operators.All(y => x.GetType() != y.GetType())));528 Operators.AddRange(swarmUpdaters.Except(Operators.OfType<IRealVectorSwarmUpdater>())); 513 529 #endregion 514 530 #region Wire RealVector ShakingOperators 515 Operators.RemoveAll(x => x is IRealVectorMultiNeighborhoodShakingOperator && ((IRealVectorMultiNeighborhoodShakingOperator)x).RealVectorParameter.ActualName != paramName); 516 var shakingOperators = ApplicationManager.Manager.GetInstances<IRealVectorMultiNeighborhoodShakingOperator>().ToList(); 531 var shakingOperators = Operators.OfType<IRealVectorMultiNeighborhoodShakingOperator>() 532 .Union(ApplicationManager.Manager.GetInstances<IRealVectorMultiNeighborhoodShakingOperator>(), new TypeEqualityComparer<IRealVectorMultiNeighborhoodShakingOperator>()) 533 .ToList(); 517 534 foreach (var so in shakingOperators) { 518 535 so.RealVectorParameter.ActualName = paramName; 519 536 so.RealVectorParameter.Hidden = true; 520 537 } 521 Operators.AddRange(shakingOperators. Where(x => Operators.All(y => x.GetType() != y.GetType())));538 Operators.AddRange(shakingOperators.Except(Operators.OfType<IRealVectorMultiNeighborhoodShakingOperator>())); 522 539 #endregion 523 540 } else { … … 544 561 545 562 #region Wire Permutation Crossovers 546 Operators.RemoveAll(x => x is IPermutationCrossover && ((IPermutationCrossover)x).ChildParameter.ActualName != paramName); 547 var crossovers = ApplicationManager.Manager.GetInstances<IPermutationCrossover>().ToList(); 563 var crossovers = Operators.OfType<IPermutationCrossover>() 564 .Union(ApplicationManager.Manager.GetInstances<IPermutationCrossover>(), new TypeEqualityComparer<IPermutationCrossover>()) 565 .ToList(); 548 566 foreach (var xo in crossovers) { 549 567 xo.ChildParameter.ActualName = permCreator.PermutationParameter.ActualName; … … 552 570 xo.ParentsParameter.Hidden = true; 553 571 } 554 Operators.AddRange(crossovers. Where(x => Operators.All(y => x.GetType() != y.GetType())));572 Operators.AddRange(crossovers.Except(Operators.OfType<IPermutationCrossover>())); 555 573 #endregion 556 574 #region Wire Permutation Manipulators 557 Operators.RemoveAll(x => x is IPermutationManipulator && ((IPermutationManipulator)x).PermutationParameter.ActualName != paramName); 558 var manipulators = ApplicationManager.Manager.GetInstances<IPermutationManipulator>().ToList(); 575 var manipulators = Operators.OfType<IPermutationManipulator>() 576 .Union(ApplicationManager.Manager.GetInstances<IPermutationManipulator>(), new TypeEqualityComparer<IPermutationManipulator>()) 577 .ToList(); 559 578 foreach (var m in manipulators) { 560 579 m.PermutationParameter.ActualName = permCreator.PermutationParameter.ActualName; 561 580 m.PermutationParameter.Hidden = true; 562 581 } 563 Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 564 #endregion 565 #region Wire ShakingOperators 566 Operators.RemoveAll(x => x is IPermutationMultiNeighborhoodShakingOperator && ((IPermutationMultiNeighborhoodShakingOperator)x).PermutationParameter.ActualName != paramName); 567 var shakingOperators = ApplicationManager.Manager.GetInstances<IPermutationMultiNeighborhoodShakingOperator>().ToList(); 582 Operators.AddRange(manipulators.Except(Operators.OfType<IPermutationManipulator>())); 583 #endregion 584 #region Wire Permutation ShakingOperators 585 var shakingOperators = Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>() 586 .Union(ApplicationManager.Manager.GetInstances<IPermutationMultiNeighborhoodShakingOperator>(), new TypeEqualityComparer<IPermutationMultiNeighborhoodShakingOperator>()) 587 .ToList(); 568 588 foreach (var op in shakingOperators) { 569 589 op.PermutationParameter.ActualName = paramName; 570 590 op.PermutationParameter.Hidden = true; 571 591 } 572 Operators.AddRange(shakingOperators. Where(x => Operators.All(y => x.GetType() != y.GetType())));592 Operators.AddRange(shakingOperators.Except(Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>())); 573 593 #endregion 574 594 } else { … … 580 600 } 581 601 582 protected virtual void UpdateMultiVectorEncodingOperators(List<ISolutionCreator> solutionCreators, Configuration configuration) { 583 var oldCreator = SolutionCreator as ParameterVectorCreater; 584 var newCreator = new ParameterVectorCreater(); 585 586 #region Configure BinaryVector Creator 587 var newBinParams = new HashSet<string>(solutionCreators.OfType<IBinaryVectorCreator>().Select(x => x.BinaryVectorParameter.ActualName)); 588 if (oldCreator != null) { 589 // we want to reuse the old creator 590 var oldParams = new HashSet<string>(oldCreator.Operators.OfType<IBinaryVectorCreator>() 591 .Select(x => x.BinaryVectorParameter.ActualName)); 592 foreach (var toAdd in newBinParams.Except(oldParams)) { 593 var paramName = toAdd; 594 oldCreator.Operators.Add( 595 solutionCreators.OfType<IBinaryVectorCreator>().Single(x => x.BinaryVectorParameter.ActualName == paramName)); 596 } 597 foreach (var toRemove in oldParams.Except(newBinParams)) { 598 var paramName = toRemove; 599 var op = 600 oldCreator.Operators.OfType<IBinaryVectorCreator>() 601 .SingleOrDefault(x => x.BinaryVectorParameter.ActualName == paramName); 602 protected virtual void ConfigureMultiVectorEncodingOperators(MultiEncodingCreator newCreator, MultiEncoding encoding) { 603 var newBinParams = new HashSet<string>(newCreator.Operators.OfType<IBinaryVectorCreator>().Select(x => x.BinaryVectorParameter.ActualName)); 604 var newIntParams = new HashSet<string>(newCreator.Operators.OfType<IIntegerVectorCreator>().Select(x => x.IntegerVectorParameter.ActualName)); 605 var newRealParams = new HashSet<string>(newCreator.Operators.OfType<IRealVectorCreator>().Select(x => x.RealVectorParameter.ActualName)); 606 var newPermParams = new HashSet<string>(newCreator.Operators.OfType<IPermutationCreator>().Select(x => x.PermutationParameter.ActualName)); 607 608 var oldCreator = SolutionCreator as MultiEncodingCreator; 609 if (oldCreator == null) SolutionCreator = newCreator; 610 else { 611 #region Configure BinaryVector Creator 612 var oldBinParams = new HashSet<string>(oldCreator.Operators.OfType<IBinaryVectorCreator>().Select(x => x.BinaryVectorParameter.ActualName)); 613 foreach (var toAdd in newBinParams.Except(oldBinParams)) { 614 oldCreator.Operators.Add(newCreator.Operators.OfType<IBinaryVectorCreator>().Single(x => x.BinaryVectorParameter.ActualName == toAdd)); 615 } 616 foreach (var toRemove in oldBinParams.Except(newBinParams)) { 617 var op = oldCreator.Operators.OfType<IBinaryVectorCreator>().SingleOrDefault(x => x.BinaryVectorParameter.ActualName == toRemove); 602 618 if (op != null) oldCreator.Operators.Remove(op); 603 619 } 604 } else { 605 // we will use the new creator 606 foreach (var binCreator in solutionCreators.OfType<IBinaryVectorCreator>()) { 607 newCreator.Operators.Add(binCreator); 608 } 609 } 610 #endregion 611 #region Configure IntegerVector Creator 612 var newIntParams = new HashSet<string>(solutionCreators.OfType<IIntegerVectorCreator>().Select(x => x.IntegerVectorParameter.ActualName)); 613 if (oldCreator != null) { 614 // we want to reuse the old creator 615 var oldParams = new HashSet<string>(oldCreator 616 .Operators.OfType<IIntegerVectorCreator>() 617 .Select(x => x.IntegerVectorParameter.ActualName)); 618 foreach (var toAdd in newIntParams.Except(oldParams)) { 619 var paramName = toAdd; 620 oldCreator.Operators.Add( 621 solutionCreators.OfType<IIntegerVectorCreator>().Single(x => x.IntegerVectorParameter.ActualName == paramName)); 622 } 623 foreach (var toRemove in oldParams.Except(newIntParams)) { 624 var paramName = toRemove; 625 var op = 626 oldCreator.Operators.OfType<IIntegerVectorCreator>() 627 .SingleOrDefault(x => x.IntegerVectorParameter.ActualName == paramName); 620 #endregion 621 622 #region Configure IntegerVector Creator 623 var oldIntParams = new HashSet<string>(oldCreator.Operators.OfType<IIntegerVectorCreator>().Select(x => x.IntegerVectorParameter.ActualName)); 624 foreach (var toAdd in newIntParams.Except(oldIntParams)) { 625 oldCreator.Operators.Add(newCreator.Operators.OfType<IIntegerVectorCreator>().Single(x => x.IntegerVectorParameter.ActualName == toAdd)); 626 } 627 foreach (var toRemove in oldIntParams.Except(newIntParams)) { 628 var op = oldCreator.Operators.OfType<IIntegerVectorCreator>().SingleOrDefault(x => x.IntegerVectorParameter.ActualName == toRemove); 628 629 if (op != null) oldCreator.Operators.Remove(op); 629 630 } 630 } else { 631 // we will use the new creator 632 foreach (var intCreator in solutionCreators.OfType<IIntegerVectorCreator>()) { 633 newCreator.Operators.Add(intCreator); 634 } 635 } 636 #endregion 637 #region Configure RealVector Creator 638 var newRealParams = new HashSet<string>(solutionCreators.OfType<IRealVectorCreator>().Select(x => x.RealVectorParameter.ActualName)); 639 if (oldCreator != null) { 640 // we want to reuse the old creator 641 var oldParams = new HashSet<string>(oldCreator 642 .Operators.OfType<IRealVectorCreator>() 643 .Select(x => x.RealVectorParameter.ActualName)); 644 foreach (var toAdd in newRealParams.Except(oldParams)) { 645 var paramName = toAdd; 646 oldCreator.Operators.Add( 647 solutionCreators.OfType<IRealVectorCreator>().Single(x => x.RealVectorParameter.ActualName == paramName)); 648 } 649 foreach (var toRemove in oldParams.Except(newRealParams)) { 650 var paramName = toRemove; 651 var op = 652 oldCreator.Operators.OfType<IRealVectorCreator>() 653 .SingleOrDefault(x => x.RealVectorParameter.ActualName == paramName); 631 #endregion 632 633 #region Configure RealVector Creator 634 var oldRealParams = new HashSet<string>(oldCreator.Operators.OfType<IRealVectorCreator>().Select(x => x.RealVectorParameter.ActualName)); 635 foreach (var toAdd in newRealParams.Except(oldRealParams)) { 636 oldCreator.Operators.Add(newCreator.Operators.OfType<IRealVectorCreator>().Single(x => x.RealVectorParameter.ActualName == toAdd)); 637 } 638 foreach (var toRemove in oldRealParams.Except(newRealParams)) { 639 var op = oldCreator.Operators.OfType<IRealVectorCreator>().SingleOrDefault(x => x.RealVectorParameter.ActualName == toRemove); 654 640 if (op != null) oldCreator.Operators.Remove(op); 655 641 } 656 } else { 657 // we will use the new creator 658 foreach (var realCreator in solutionCreators.OfType<IRealVectorCreator>()) { 659 newCreator.Operators.Add(realCreator); 660 } 661 } 662 #endregion 663 #region Configure Permutation Creator 664 var newPermParams = new HashSet<string>(solutionCreators.OfType<IPermutationCreator>().Select(x => x.PermutationParameter.ActualName)); 665 if (oldCreator != null) { 666 // we want to reuse the old creator 667 var oldParams = new HashSet<string>(oldCreator 668 .Operators.OfType<IPermutationCreator>() 669 .Select(x => x.PermutationParameter.ActualName)); 670 foreach (var toAdd in newPermParams.Except(oldParams)) { 671 var paramName = toAdd; 672 oldCreator.Operators.Add( 673 solutionCreators.OfType<IPermutationCreator>().Single(x => x.PermutationParameter.ActualName == paramName)); 674 } 675 foreach (var toRemove in oldParams.Except(newPermParams)) { 676 var paramName = toRemove; 677 var op = 678 oldCreator.Operators.OfType<IPermutationCreator>() 679 .SingleOrDefault(x => x.PermutationParameter.ActualName == paramName); 642 #endregion 643 644 #region Configure Permutation Creator 645 var oldPermParams = new HashSet<string>(oldCreator.Operators.OfType<IPermutationCreator>().Select(x => x.PermutationParameter.ActualName)); 646 foreach (var toAdd in newPermParams.Except(oldPermParams)) { 647 oldCreator.Operators.Add(newCreator.Operators.OfType<IPermutationCreator>().Single(x => x.PermutationParameter.ActualName == toAdd)); 648 } 649 foreach (var toRemove in oldPermParams.Except(newPermParams)) { 650 var op = oldCreator.Operators.OfType<IPermutationCreator>().SingleOrDefault(x => x.PermutationParameter.ActualName == toRemove); 680 651 if (op != null) oldCreator.Operators.Remove(op); 681 652 } 682 653 // we also have to sync the permutation type (in case this changes, as it is a value parameter) 683 foreach (var intersect in newPermParams.Intersect(oldParams)) { 684 var paramName = intersect; 685 var oldPermCreator = oldCreator.Operators.OfType<IPermutationCreator>() 686 .Single(x => x.PermutationParameter.ActualName == paramName); 687 var newPermCreator = solutionCreators.OfType<IPermutationCreator>() 688 .Single(x => x.PermutationParameter.ActualName == paramName); 654 foreach (var intersect in newPermParams.Intersect(oldPermParams)) { 655 var oldPermCreator = oldCreator.Operators.OfType<IPermutationCreator>().Single(x => x.PermutationParameter.ActualName == intersect); 656 var newPermCreator = newCreator.Operators.OfType<IPermutationCreator>().Single(x => x.PermutationParameter.ActualName == intersect); 689 657 oldPermCreator.PermutationTypeParameter.Value = newPermCreator.PermutationTypeParameter.Value; 690 658 } 691 } else { 692 // we will use the new creator 693 foreach (var permCreator in solutionCreators.OfType<IPermutationCreator>()) { 694 newCreator.Operators.Add(permCreator); 695 } 696 } 697 #endregion 698 699 if (oldCreator == null) SolutionCreator = newCreator; 659 #endregion 660 661 } 700 662 701 663 // crossover and manipulator for multi-vector encoding 702 664 // the condition checks if a multi-vector encoding is to be updated (there already exists ParameterVectorCrossover and ParameterVectorManipulator) 703 if (Operators.OfType< ParameterVectorCrossover>().Any() && Operators.OfType<ParameterVectorManipulator>().Any()) {665 if (Operators.OfType<MultiEncodingCrossover>().Any() && Operators.OfType<MultiEncodingManipulator>().Any()) { 704 666 #region Update existing multi-vector encoding 705 667 #region Update ParameterVector Crossover ... 706 foreach (var oldXo in Operators.OfType< ParameterVectorCrossover>()) {668 foreach (var oldXo in Operators.OfType<MultiEncodingCrossover>()) { 707 669 #region ... for binary parameters 708 var oldBinParams = new HashSet<string>(oldXo.Operators.OfType<IBinaryVectorCrossover>() 709 .Select(x => x.ChildParameter.ActualName)); 670 var oldBinParams = new HashSet<string>(oldXo.Operators.OfType<IBinaryVectorCrossover>().Select(x => x.ChildParameter.ActualName)); 710 671 foreach (var toAdd in newBinParams.Except(oldBinParams)) 711 oldXo.Operators.Add(GetDefaultBinaryCrossover(toAdd, configuration));672 oldXo.Operators.Add(GetDefaultBinaryCrossover(toAdd, encoding)); 712 673 foreach (var toRemove in oldBinParams.Except(newBinParams)) { 713 var op = 714 oldXo.Operators.OfType<IBinaryVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove); 674 var op = oldXo.Operators.OfType<IBinaryVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove); 715 675 if (op != null) oldXo.Operators.Remove(op); 716 676 } 717 677 #endregion 718 678 #region ... for integer parameters 719 var oldIntParams = new HashSet<string>(oldXo.Operators.OfType<IIntegerVectorCrossover>() 720 .Select(x => x.ChildParameter.ActualName)); 679 var oldIntParams = new HashSet<string>(oldXo.Operators.OfType<IIntegerVectorCrossover>().Select(x => x.ChildParameter.ActualName)); 721 680 foreach (var toAdd in newIntParams.Except(oldIntParams)) 722 oldXo.Operators.Add(GetDefaultIntegerCrossover(toAdd, configuration));681 oldXo.Operators.Add(GetDefaultIntegerCrossover(toAdd, encoding)); 723 682 foreach (var toRemove in oldIntParams.Except(newIntParams)) { 724 var op = 725 oldXo.Operators.OfType<IIntegerVectorCrossover>() 726 .SingleOrDefault(x => x.ChildParameter.ActualName == toRemove); 683 var op = oldXo.Operators.OfType<IIntegerVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove); 727 684 if (op != null) oldXo.Operators.Remove(op); 728 685 } 729 686 #endregion 730 687 #region ... for real parameters 731 var oldRealParams = new HashSet<string>(oldXo.Operators.OfType<IRealVectorCrossover>() 732 .Select(x => x.ChildParameter.ActualName)); 688 var oldRealParams = new HashSet<string>(oldXo.Operators.OfType<IRealVectorCrossover>().Select(x => x.ChildParameter.ActualName)); 733 689 foreach (var toAdd in newRealParams.Except(oldRealParams)) 734 oldXo.Operators.Add(GetDefaultRealCrossover(toAdd, configuration));690 oldXo.Operators.Add(GetDefaultRealCrossover(toAdd, encoding)); 735 691 foreach (var toRemove in oldRealParams.Except(newRealParams)) { 736 var op = 737 oldXo.Operators.OfType<IRealVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove); 692 var op = oldXo.Operators.OfType<IRealVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove); 738 693 if (op != null) oldXo.Operators.Remove(op); 739 694 } 740 695 #endregion 741 696 #region ... for permutation parameters 742 var oldPermParams = new HashSet<string>(oldXo.Operators.OfType<IPermutationCrossover>() 743 .Select(x => x.ChildParameter.ActualName)); 697 var oldPermParams = new HashSet<string>(oldXo.Operators.OfType<IPermutationCrossover>().Select(x => x.ChildParameter.ActualName)); 744 698 foreach (var toAdd in newPermParams.Except(oldPermParams)) 745 oldXo.Operators.Add(GetDefaultPermutationCrossover(toAdd, configuration));699 oldXo.Operators.Add(GetDefaultPermutationCrossover(toAdd, encoding)); 746 700 foreach (var toRemove in oldPermParams.Except(newPermParams)) { 747 var op = 748 oldXo.Operators.OfType<IPermutationCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove); 701 var op = oldXo.Operators.OfType<IPermutationCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove); 749 702 if (op != null) oldXo.Operators.Remove(op); 750 703 } … … 753 706 #endregion 754 707 #region Update ParameterVector Manipulator ... 755 foreach (var oldM in Operators.OfType< ParameterVectorManipulator>()) {708 foreach (var oldM in Operators.OfType<MultiEncodingManipulator>()) { 756 709 #region ... for binary parameters 757 var oldBinParams = new HashSet<string>(oldM.Operators.OfType<IBinaryVectorManipulator>() 758 .Select(x => x.BinaryVectorParameter.ActualName)); 710 var oldBinParams = new HashSet<string>(oldM.Operators.OfType<IBinaryVectorManipulator>().Select(x => x.BinaryVectorParameter.ActualName)); 759 711 foreach (var toAdd in newBinParams.Except(oldBinParams)) 760 oldM.Operators.Add(GetDefaultBinaryManipulator(toAdd, configuration));712 oldM.Operators.Add(GetDefaultBinaryManipulator(toAdd, encoding)); 761 713 foreach (var toRemove in oldBinParams.Except(newBinParams)) { 762 var op = 763 oldM.Operators.OfType<IBinaryVectorManipulator>() 764 .SingleOrDefault(x => x.BinaryVectorParameter.ActualName == toRemove); 714 var op = oldM.Operators.OfType<IBinaryVectorManipulator>().SingleOrDefault(x => x.BinaryVectorParameter.ActualName == toRemove); 765 715 if (op != null) oldM.Operators.Remove(op); 766 716 } 767 717 #endregion 768 718 #region ... for integer parameters 769 var oldIntParams = new HashSet<string>(oldM.Operators.OfType<IIntegerVectorManipulator>() 770 .Select(x => x.IntegerVectorParameter.ActualName)); 719 var oldIntParams = new HashSet<string>(oldM.Operators.OfType<IIntegerVectorManipulator>().Select(x => x.IntegerVectorParameter.ActualName)); 771 720 foreach (var toAdd in newIntParams.Except(oldIntParams)) 772 oldM.Operators.Add(GetDefaultIntegerManipulator(toAdd, configuration));721 oldM.Operators.Add(GetDefaultIntegerManipulator(toAdd, encoding)); 773 722 foreach (var toRemove in oldIntParams.Except(newIntParams)) { 774 var op = 775 oldM.Operators.OfType<IIntegerVectorManipulator>() 776 .SingleOrDefault(x => x.IntegerVectorParameter.ActualName == toRemove); 723 var op = oldM.Operators.OfType<IIntegerVectorManipulator>().SingleOrDefault(x => x.IntegerVectorParameter.ActualName == toRemove); 777 724 if (op != null) oldM.Operators.Remove(op); 778 725 } 779 726 #endregion 780 727 #region ... for real parameters 781 var oldRealParams = new HashSet<string>(oldM.Operators.OfType<IRealVectorManipulator>() 782 .Select(x => x.RealVectorParameter.ActualName)); 728 var oldRealParams = new HashSet<string>(oldM.Operators.OfType<IRealVectorManipulator>().Select(x => x.RealVectorParameter.ActualName)); 783 729 foreach (var toAdd in newRealParams.Except(oldRealParams)) 784 oldM.Operators.Add(GetDefaultRealManipulator(toAdd, configuration));730 oldM.Operators.Add(GetDefaultRealManipulator(toAdd, encoding)); 785 731 foreach (var toRemove in oldRealParams.Except(newRealParams)) { 786 var op = 787 oldM.Operators.OfType<IRealVectorManipulator>() 788 .SingleOrDefault(x => x.RealVectorParameter.ActualName == toRemove); 732 var op = oldM.Operators.OfType<IRealVectorManipulator>().SingleOrDefault(x => x.RealVectorParameter.ActualName == toRemove); 789 733 if (op != null) oldM.Operators.Remove(op); 790 734 } 791 735 #endregion 792 736 #region ... for permutation parameters 793 var oldPermParams = new HashSet<string>(oldM.Operators.OfType<IPermutationManipulator>() 794 .Select(x => x.PermutationParameter.ActualName)); 737 var oldPermParams = new HashSet<string>(oldM.Operators.OfType<IPermutationManipulator>().Select(x => x.PermutationParameter.ActualName)); 795 738 foreach (var toAdd in newPermParams.Except(oldPermParams)) 796 oldM.Operators.Add(GetDefaultPermutationManipulator(toAdd, configuration));739 oldM.Operators.Add(GetDefaultPermutationManipulator(toAdd, encoding)); 797 740 foreach (var toRemove in oldPermParams.Except(newPermParams)) { 798 var op = 799 oldM.Operators.OfType<IPermutationManipulator>() 800 .SingleOrDefault(x => x.PermutationParameter.ActualName == toRemove); 741 var op = oldM.Operators.OfType<IPermutationManipulator>().SingleOrDefault(x => x.PermutationParameter.ActualName == toRemove); 801 742 if (op != null) oldM.Operators.Remove(op); 802 743 } … … 815 756 Operators.RemoveAll(x => x is IMultiNeighborhoodShakingOperator); 816 757 817 var crossover = new ParameterVectorCrossover();818 var manipulator = new ParameterVectorManipulator();819 foreach (var param in configuration.Parameters) {820 if ( param.Value is BinaryParameterConfiguration) {821 crossover.Operators.Add(GetDefaultBinaryCrossover( param.Key, configuration));822 manipulator.Operators.Add(GetDefaultBinaryManipulator( param.Key, configuration));758 var crossover = new MultiEncodingCrossover(); 759 var manipulator = new MultiEncodingManipulator(); 760 foreach (var enc in encoding.Encodings) { 761 if (enc is BinaryEncoding) { 762 crossover.Operators.Add(GetDefaultBinaryCrossover(enc.Name, encoding)); 763 manipulator.Operators.Add(GetDefaultBinaryManipulator(enc.Name, encoding)); 823 764 continue; 824 765 } 825 var intConfig = param.Value as IntegerParameterConfiguration;766 var intConfig = enc as IntegerEncoding; 826 767 if (intConfig != null) { 827 crossover.Operators.Add(GetDefaultIntegerCrossover( param.Key, configuration));828 manipulator.Operators.Add(GetDefaultIntegerManipulator( param.Key, configuration));768 crossover.Operators.Add(GetDefaultIntegerCrossover(enc.Name, encoding)); 769 manipulator.Operators.Add(GetDefaultIntegerManipulator(enc.Name, encoding)); 829 770 continue; 830 771 } 831 var realConfig = param.Value as RealParameterConfiguration;772 var realConfig = enc as RealEncoding; 832 773 if (realConfig != null) { 833 crossover.Operators.Add(GetDefaultRealCrossover( param.Key, configuration));834 manipulator.Operators.Add(GetDefaultRealManipulator( param.Key, configuration));774 crossover.Operators.Add(GetDefaultRealCrossover(enc.Name, encoding)); 775 manipulator.Operators.Add(GetDefaultRealManipulator(enc.Name, encoding)); 835 776 continue; 836 777 } 837 var permConfig = param.Value as PermutationParameterConfiguration;778 var permConfig = enc as PermutationEncoding; 838 779 if (permConfig != null) { 839 crossover.Operators.Add(GetDefaultPermutationCrossover( param.Key, configuration));840 manipulator.Operators.Add(GetDefaultPermutationManipulator( param.Key, configuration));780 crossover.Operators.Add(GetDefaultPermutationCrossover(enc.Name, encoding)); 781 manipulator.Operators.Add(GetDefaultPermutationManipulator(enc.Name, encoding)); 841 782 continue; 842 783 } 843 throw new InvalidOperationException("Unknown type for parameter " + param.Key);784 throw new InvalidOperationException("Unknown type for parameter " + enc.Name); 844 785 } 845 786 Operators.Add(crossover); … … 849 790 } 850 791 851 protected virtual void UpdateMoveOperators() {852 Operators.RemoveAll(x => x is IParameterVectorMoveOperator);853 var generator = new ParameterVectorMoveGenerator();854 generator.ConfigurationParameter.ActualName = ConfigurationParameter.Name;855 generator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;856 857 var evaluator = new ParameterVectorMoveEvaluator();858 evaluator.ConfigurationParameter.ActualName = ConfigurationParameter.Name;859 evaluator.QualityParameter.ActualName = Evaluator.QualitiesParameter.ActualName;860 evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;861 862 var maker = new ParameterVectorMoveMaker();863 maker.ConfigurationParameter.ActualName = ConfigurationParameter.Name;864 maker.MoveQualityParameter.ActualName = evaluator.MoveQualityParameter.ActualName;865 maker.QualityParameter.ActualName = Evaluator.QualitiesParameter.ActualName;866 867 Operators.AddRange(new IItem[] { generator, evaluator, maker });868 }869 870 792 #region GetDefaultOperators for Crossovers and Manipulators 871 793 // ReSharper disable RedundantNameQualifier 872 protected virtual IBinaryVectorCrossover GetDefaultBinaryCrossover(string paramName, Configurationconfig) {873 var binConfig = (Binary ParameterConfiguration)config.Parameters[paramName];794 protected virtual IBinaryVectorCrossover GetDefaultBinaryCrossover(string paramName, MultiEncoding config) { 795 var binConfig = (BinaryEncoding)config.Encodings[paramName]; 874 796 IBinaryVectorCrossover binXo; 875 797 if (binConfig.Length.Value > 3) binXo = new Encodings.BinaryVectorEncoding.SinglePointCrossover(); … … 880 802 } 881 803 882 protected virtual IBinaryVectorManipulator GetDefaultBinaryManipulator(string paramName, Configurationconfig) {804 protected virtual IBinaryVectorManipulator GetDefaultBinaryManipulator(string paramName, MultiEncoding config) { 883 805 var binM = new Encodings.BinaryVectorEncoding.SomePositionsBitflipManipulator(); 884 806 binM.BinaryVectorParameter.ActualName = paramName; … … 887 809 } 888 810 889 protected virtual IIntegerVectorCrossover GetDefaultIntegerCrossover(string paramName, Configurationconfig) {811 protected virtual IIntegerVectorCrossover GetDefaultIntegerCrossover(string paramName, MultiEncoding config) { 890 812 var intXo = new Encodings.IntegerVectorEncoding.RoundedBlendAlphaCrossover(); 891 813 intXo.ChildParameter.ActualName = paramName; … … 895 817 } 896 818 897 protected virtual IIntegerVectorManipulator GetDefaultIntegerManipulator(string paramName, Configurationconfiguration) {819 protected virtual IIntegerVectorManipulator GetDefaultIntegerManipulator(string paramName, MultiEncoding configuration) { 898 820 var intM = new Encodings.IntegerVectorEncoding.UniformSomePositionsManipulator(); 899 821 intM.IntegerVectorParameter.ActualName = paramName; … … 903 825 } 904 826 905 protected virtual IRealVectorCrossover GetDefaultRealCrossover(string paramName, Configurationconfiguration) {827 protected virtual IRealVectorCrossover GetDefaultRealCrossover(string paramName, MultiEncoding configuration) { 906 828 var realXo = new Encodings.RealVectorEncoding.BlendAlphaCrossover(); 907 829 realXo.ChildParameter.ActualName = paramName; … … 911 833 } 912 834 913 protected virtual IRealVectorManipulator GetDefaultRealManipulator(string paramName, Configurationconfiguration) {835 protected virtual IRealVectorManipulator GetDefaultRealManipulator(string paramName, MultiEncoding configuration) { 914 836 var realM = new Encodings.RealVectorEncoding.BreederGeneticAlgorithmManipulator(); 915 837 realM.RealVectorParameter.ActualName = paramName; … … 918 840 } 919 841 920 protected virtual IPermutationCrossover GetDefaultPermutationCrossover(string paramName, Configurationconfiguration) {842 protected virtual IPermutationCrossover GetDefaultPermutationCrossover(string paramName, MultiEncoding configuration) { 921 843 var permXo = new Encodings.PermutationEncoding.PartiallyMatchedCrossover(); 922 844 permXo.ChildParameter.ActualName = paramName; … … 925 847 } 926 848 927 protected virtual IPermutationManipulator GetDefaultPermutationManipulator(string paramName, Configurationconfiguration) {849 protected virtual IPermutationManipulator GetDefaultPermutationManipulator(string paramName, MultiEncoding configuration) { 928 850 var permM = new Encodings.PermutationEncoding.Swap2Manipulator(); 929 851 permM.PermutationParameter.ActualName = paramName; -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/MultiObjectiveAnalyzer.cs
r11400 r11484 11 11 12 12 namespace HeuristicLab.Problems.Programmable { 13 [Item("Multi-objective Analyzer", "Calls the script's Analyze method to be able to write into the results collection.")]13 [Item("Multi-objective Analyzer", "Calls the Analyze method of the problem definition.")] 14 14 [StorableClass] 15 15 public class MultiObjectiveAnalyzer : SingleSuccessorOperator, IMultiObjectiveProgrammableProblemAnalyzer { 16 16 public bool EnabledByDefault { get { return true; } } 17 17 18 public ILookupParameter<IMultiObjectiveProblemDefinition Host> ProblemDefinitionParameter {19 get { return (ILookupParameter<IMultiObjectiveProblemDefinition Host>)Parameters["ProblemDefinition"]; }18 public ILookupParameter<IMultiObjectiveProblemDefinition> ProblemDefinitionParameter { 19 get { return (ILookupParameter<IMultiObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; } 20 20 } 21 21 22 public ILookupParameter< Configuration> ConfigurationParameter {23 get { return (ILookupParameter< Configuration>)Parameters["Configuration"]; }22 public ILookupParameter<Encoding> EncodingParameter { 23 get { return (ILookupParameter<Encoding>)Parameters["Encoding"]; } 24 24 } 25 25 … … 37 37 public MultiObjectiveAnalyzer() { 38 38 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 39 Parameters.Add(new LookupParameter<IMultiObjectiveProblemDefinition Host>("ProblemDefinition", "The host that holds the problem definition."));40 Parameters.Add(new LookupParameter< Configuration>("Configuration", "An item that holds the problem's configuration."));39 Parameters.Add(new LookupParameter<IMultiObjectiveProblemDefinition>("ProblemDefinition", "The host that holds the problem definition.")); 40 Parameters.Add(new LookupParameter<Encoding>("Encoding", "An item that holds the problem's encoding.")); 41 41 Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The qualities of the parameter vector.")); 42 42 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The results collection to write to.")); … … 48 48 49 49 public override IOperation Apply() { 50 var host= ProblemDefinitionParameter.ActualValue;51 if ( host.Instance == null) throw new InvalidOperationException("Script instance is null, maybe the code doesn't compile.");52 var config = ConfigurationParameter.ActualValue;50 var definition = ProblemDefinitionParameter.ActualValue; 51 if (definition == null) throw new InvalidOperationException("Problem definition is null."); 52 var config = EncodingParameter.ActualValue; 53 53 var results = ResultsParameter.ActualValue; 54 54 … … 58 58 59 59 var vectors = scopes.Select(scope => Helper.Extract(scope, config)).ToArray(); 60 host.Instance.Analyze(vectors, QualitiesParameter.ActualValue.Select(x => x.ToArray()).ToArray(), results);60 definition.Analyze(vectors, QualitiesParameter.ActualValue.Select(x => x.ToArray()).ToArray(), results); 61 61 return base.Apply(); 62 62 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/MultiObjectiveEvaluator.cs
r11400 r11484 30 30 31 31 namespace HeuristicLab.Problems.Programmable { 32 [Item("Multi-objective Evaluator", "Calls the script's Evaluate method to get the quality values of the parameter vector.")]32 [Item("Multi-objective Evaluator", "Calls the Evaluate method of the problem definition and writes the return value into the scope.")] 33 33 [StorableClass] 34 34 public class MultiObjectiveEvaluator : SingleSuccessorOperator, IMultiObjectiveProgrammableProblemEvaluator, IStochasticOperator { … … 38 38 } 39 39 40 public ILookupParameter<IMultiObjectiveProblemDefinition Host> ProblemDefinitionParameter {41 get { return (ILookupParameter<IMultiObjectiveProblemDefinition Host>)Parameters["ProblemDefinition"]; }40 public ILookupParameter<IMultiObjectiveProblemDefinition> ProblemDefinitionParameter { 41 get { return (ILookupParameter<IMultiObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; } 42 42 } 43 43 44 public ILookupParameter< Configuration> ConfigurationParameter {45 get { return (ILookupParameter< Configuration>)Parameters["Configuration"]; }44 public ILookupParameter<Encoding> EncodingParameter { 45 get { return (ILookupParameter<Encoding>)Parameters["Encoding"]; } 46 46 } 47 47 … … 55 55 public MultiObjectiveEvaluator() { 56 56 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 57 Parameters.Add(new LookupParameter<IMultiObjectiveProblemDefinition Host>("ProblemDefinition", "The host that holds the problem definition."));58 Parameters.Add(new LookupParameter< Configuration>("Configuration", "An item that holds the problem's configuration."));57 Parameters.Add(new LookupParameter<IMultiObjectiveProblemDefinition>("ProblemDefinition", "The host that holds the problem definition.")); 58 Parameters.Add(new LookupParameter<Encoding>("Encoding", "An item that holds the problem's encoding.")); 59 59 Parameters.Add(new LookupParameter<DoubleArray>("Qualities", "The qualities of the parameter vector.")); 60 60 } … … 66 66 public override IOperation Apply() { 67 67 var random = RandomParameter.ActualValue; 68 var host= ProblemDefinitionParameter.ActualValue;69 if ( host.Instance == null) throw new InvalidOperationException("Script instance is null, maybe the code doesn't compile.");70 var config = ConfigurationParameter.ActualValue;68 var definition = ProblemDefinitionParameter.ActualValue; 69 if (definition == null) throw new InvalidOperationException("Problem definition is null."); 70 var config = EncodingParameter.ActualValue; 71 71 var vector = Helper.Extract(ExecutionContext.Scope, config); 72 QualitiesParameter.ActualValue = new DoubleArray( host.Instance.Evaluate(random, vector));72 QualitiesParameter.ActualValue = new DoubleArray(definition.Evaluate(random, vector)); 73 73 return base.Apply(); 74 74 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveAnalyzer.cs
r11405 r11484 16 16 public bool EnabledByDefault { get { return true; } } 17 17 18 public ILookupParameter<ISingleObjectiveProblemDefinition Host> ProblemDefinitionParameter {19 get { return (ILookupParameter<ISingleObjectiveProblemDefinition Host>)Parameters["ProblemDefinition"]; }18 public ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter { 19 get { return (ILookupParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; } 20 20 } 21 21 22 public ILookupParameter< Configuration> ConfigurationParameter {23 get { return (ILookupParameter< Configuration>)Parameters["Configuration"]; }22 public ILookupParameter<Encoding> EncodingParameter { 23 get { return (ILookupParameter<Encoding>)Parameters["Encoding"]; } 24 24 } 25 25 … … 37 37 public SingleObjectiveAnalyzer() { 38 38 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 39 Parameters.Add(new LookupParameter<ISingleObjectiveProblemDefinition Host>("ProblemDefinition", "The host that holds the problem definition."));40 Parameters.Add(new LookupParameter< Configuration>("Configuration", "An item that holds the problem's configuration."));39 Parameters.Add(new LookupParameter<ISingleObjectiveProblemDefinition>("ProblemDefinition", "The host that holds the problem definition.")); 40 Parameters.Add(new LookupParameter<Encoding>("Encoding", "An item that holds the problem's encoding.")); 41 41 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality of the parameter vector.")); 42 42 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The results collection to write to.")); … … 48 48 49 49 public override IOperation Apply() { 50 var host= ProblemDefinitionParameter.ActualValue;51 if ( host.Instance == null) throw new InvalidOperationException("Problem definition is not available.");52 var config = ConfigurationParameter.ActualValue;50 var definition = ProblemDefinitionParameter.ActualValue; 51 if (definition == null) throw new InvalidOperationException("Problem definition is null"); 52 var config = EncodingParameter.ActualValue; 53 53 var results = ResultsParameter.ActualValue; 54 54 … … 58 58 59 59 var vectors = scopes.Select(scope => Helper.Extract(scope, config)).ToArray(); 60 host.Instance.Analyze(vectors, QualityParameter.ActualValue.Select(x => x.Value).ToArray(), results);60 definition.Analyze(vectors, QualityParameter.ActualValue.Select(x => x.Value).ToArray(), results); 61 61 return base.Apply(); 62 62 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveEvaluator.cs
r11405 r11484 38 38 } 39 39 40 public ILookupParameter<ISingleObjectiveProblemDefinition Host> ProblemDefinitionParameter {41 get { return (ILookupParameter<ISingleObjectiveProblemDefinition Host>)Parameters["ProblemDefinition"]; }40 public ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter { 41 get { return (ILookupParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; } 42 42 } 43 43 44 public ILookupParameter< Configuration> ConfigurationParameter {45 get { return (ILookupParameter< Configuration>)Parameters["Configuration"]; }44 public ILookupParameter<Encoding> EncodingParameter { 45 get { return (ILookupParameter<Encoding>)Parameters["Encoding"]; } 46 46 } 47 47 … … 55 55 public SingleObjectiveEvaluator() { 56 56 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 57 Parameters.Add(new LookupParameter<ISingleObjectiveProblemDefinition Host>("ProblemDefinition", "The host that holds the problem definition."));58 Parameters.Add(new LookupParameter< Configuration>("Configuration", "An item that holds the problem's configuration."));57 Parameters.Add(new LookupParameter<ISingleObjectiveProblemDefinition>("ProblemDefinition", "The host that holds the problem definition.")); 58 Parameters.Add(new LookupParameter<Encoding>("Encoding", "An item that holds the problem's encoding.")); 59 59 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector.")); 60 60 } … … 66 66 public override IOperation Apply() { 67 67 var random = RandomParameter.ActualValue; 68 var host= ProblemDefinitionParameter.ActualValue;69 if ( host.Instance == null) throw new InvalidOperationException("Problem definition is not available.");70 var config = ConfigurationParameter.ActualValue;68 var definition = ProblemDefinitionParameter.ActualValue; 69 if (definition == null) throw new InvalidOperationException("Problem definition is null."); 70 var config = EncodingParameter.ActualValue; 71 71 var vector = Helper.Extract(ExecutionContext.Scope, config); 72 QualityParameter.ActualValue = new DoubleValue( host.Instance.Evaluate(random, vector));72 QualityParameter.ActualValue = new DoubleValue(definition.Evaluate(random, vector)); 73 73 return base.Apply(); 74 74 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/ProblemDefinition.cs
r11402 r11484 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using HeuristicLab.Common; 25 using HeuristicLab.Core; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 22 28 namespace HeuristicLab.Problems.Programmable { 23 public abstract class ProblemDefinition : IProblemDefinition { 24 public abstract Configuration GetConfiguration(); 29 [Item("ProblemDefinition", "Base class for problem definitions.")] 30 [StorableClass] 31 public abstract class ProblemDefinition : NamedItem, IProblemDefinition { 32 [Storable(Name = "Encoding")] 33 private Encoding encoding; 34 public Encoding Encoding { 35 get { return encoding; } 36 protected set { 37 if (encoding == value) return; 38 encoding = value; 39 OnProblemDefinitionChanged(); 40 } 41 } 25 42 26 public dynamic vars { get; set; } 27 public abstract void Initialize(); 43 [StorableConstructor] 44 protected ProblemDefinition(bool deserializing) : base(deserializing) { } 45 protected ProblemDefinition(ProblemDefinition original, Cloner cloner) 46 : base(original, cloner) { 47 this.encoding = cloner.Clone(original.encoding); 48 } 49 protected ProblemDefinition(Encoding encoding) : this(encoding, "ProblemDefinition") { } 50 protected ProblemDefinition(Encoding encoding, string name) : this(encoding, name, string.Empty) { } 51 protected ProblemDefinition(Encoding encoding, string name, string description) 52 : base(name, description) { 53 Encoding = encoding; 54 } 55 56 public event EventHandler ProblemDefinitionChanged; 57 protected void OnProblemDefinitionChanged() { 58 var handler = ProblemDefinitionChanged; 59 if (handler != null) handler(this, EventArgs.Empty); 60 } 61 62 public abstract IEnumerable<Individual> GetNeighbors(IRandom random, Individual vector); 28 63 } 29 64 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinition.cs
r11402 r11484 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Drawing;25 22 using HeuristicLab.Common; 26 23 using HeuristicLab.Core; 27 24 using HeuristicLab.Optimization; 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 26 29 27 namespace HeuristicLab.Problems.Programmable { 30 [Item("Single-objective Problem Definition", "This definition can be dynamically created through code and assigned to the problem.")] 31 public class SingleObjectiveProblemDefinition : ISingleObjectiveProblemDefinitionHost, ISingleObjectiveProblemDefinition { 28 [Item("Single-objective Problem Definition", "Base class for custom single-objective problem definitions.")] 29 [StorableClass] 30 public abstract class SingleObjectiveProblemDefinition : ProblemDefinition, ISingleObjectiveProblemDefinition { 31 [Storable(Name = "Storable")] 32 32 private bool isMaximizationProblem; 33 33 public bool IsMaximizationProblem { 34 34 get { return isMaximizationProblem; } 35 35 set { 36 if (isMaximizationProblem == value) return; 36 37 isMaximizationProblem = value; 37 On InstanceChanged();38 OnProblemDefinitionChanged(); 38 39 } 39 40 } 40 41 41 private Func<Configuration> configuration; 42 public Func<Configuration> Configuration { 43 get { return configuration; } 44 set { 45 configuration = value; 46 OnInstanceChanged(); 47 } 42 public abstract double Evaluate(IRandom random, Individual vector); 43 44 public abstract void Analyze(Individual[] vectors, double[] qualities, ResultCollection results); 45 46 [StorableConstructor] 47 protected SingleObjectiveProblemDefinition(bool deserializing) : base(deserializing) { } 48 protected SingleObjectiveProblemDefinition(SingleObjectiveProblemDefinition original, Cloner cloner) 49 : base(original, cloner) { 50 this.isMaximizationProblem = original.isMaximizationProblem; 48 51 } 49 50 private Func<IRandom, ParameterVector, double> evaluate; 51 public Func<IRandom, ParameterVector, double> Evaluate { 52 get { return evaluate; } 53 set { 54 evaluate = value; 55 OnInstanceChanged(); 56 } 57 } 58 59 private Action<ParameterVector[], double[], ResultCollection> analyze; 60 public Action<ParameterVector[], double[], ResultCollection> Analyze { 61 get { return analyze; } 62 set { 63 analyze = value; 64 OnInstanceChanged(); 65 } 66 } 67 68 private Func<IRandom, ParameterVector, IEnumerable<ParameterVector>> neighbors; 69 public Func<IRandom, ParameterVector, IEnumerable<ParameterVector>> Neighbors { 70 get { return neighbors; } 71 set { 72 neighbors = value; 73 OnInstanceChanged(); 74 } 75 } 76 77 protected SingleObjectiveProblemDefinition(SingleObjectiveProblemDefinition original, Cloner cloner) { 78 cloner.RegisterClonedObject(original, this); 79 name = original.name; 80 description = original.description; 81 isMaximizationProblem = original.isMaximizationProblem; 82 configuration = original.configuration; 83 evaluate = original.evaluate; 84 analyze = original.analyze; 85 neighbors = original.neighbors; 86 } 87 88 public SingleObjectiveProblemDefinition() : this((string)null, null) { } 89 public SingleObjectiveProblemDefinition(string name) : this(name, null) { } 90 public SingleObjectiveProblemDefinition(string name, string description) { 91 this.name = name ?? ItemName; 92 this.description = description ?? ItemDescription; 93 configuration = () => new Configuration(); 94 evaluate = (random, vector) => 0; 95 analyze = (vectors, doubles, results) => { }; 96 neighbors = (random, vector) => new[] { (ParameterVector)vector.Clone() }; 97 } 98 99 100 public IDeepCloneable Clone(Cloner cloner) { 101 return new SingleObjectiveProblemDefinition(this, cloner); 102 } 103 104 public ISingleObjectiveProblemDefinition Instance { 105 get { return this; } 106 } 107 108 public event EventHandler InstanceChanged; 109 protected void OnInstanceChanged() { 110 var handler = InstanceChanged; 111 if (handler != null) handler(this, EventArgs.Empty); 112 } 113 114 #region Problem definition explicit interface implementations 115 Configuration IProblemDefinition.GetConfiguration() { 116 return Configuration(); 117 } 118 119 bool ISingleObjectiveProblemDefinition.IsMaximizationProblem { 120 get { return IsMaximizationProblem; } 121 } 122 123 double ISingleObjectiveProblemDefinition.Evaluate(IRandom random, ParameterVector vector) { 124 return Evaluate(random, vector); 125 } 126 127 void ISingleObjectiveProblemDefinition.Analyze(ParameterVector[] vectors, double[] qualities, ResultCollection results) { 128 Analyze(vectors, qualities, results); 129 } 130 131 IEnumerable<ParameterVector> ISingleObjectiveProblemDefinition.GetNeighbors(IRandom random, ParameterVector vector) { 132 return Neighbors(random, vector); 133 } 134 #endregion 135 136 #region INamedItem 137 protected string name; 138 /// <inheritdoc/> 139 /// <remarks>Calls <see cref="OnNameChanging"/> and also <see cref="OnNameChanged"/> 140 /// eventually in the setter.</remarks> 141 public string Name { 142 get { return name; } 143 set { 144 if (!CanChangeName) throw new NotSupportedException("Name cannot be changed."); 145 if (!(name.Equals(value) || (value == null) && (name == string.Empty))) { 146 CancelEventArgs<string> e = value == null ? new CancelEventArgs<string>(string.Empty) : new CancelEventArgs<string>(value); 147 OnNameChanging(e); 148 if (!e.Cancel) { 149 name = value == null ? string.Empty : value; 150 OnNameChanged(); 151 } 152 } 153 } 154 } 155 public virtual bool CanChangeName { 156 get { return true; } 157 } 158 protected string description; 159 public string Description { 160 get { return description; } 161 set { 162 if (!CanChangeDescription) throw new NotSupportedException("Description cannot be changed."); 163 if (!(description.Equals(value) || (value == null) && (description == string.Empty))) { 164 description = value == null ? string.Empty : value; 165 OnDescriptionChanged(); 166 } 167 } 168 } 169 public virtual bool CanChangeDescription { 170 get { return true; } 171 } 172 173 /// <summary> 174 /// Gets the string representation of the current instance in the format: <c>Name: [null|Value]</c>. 175 /// </summary> 176 /// <returns>The current instance as a string.</returns> 177 public override string ToString() { 178 return Name; 179 } 180 181 /// <inheritdoc/> 182 public event EventHandler<CancelEventArgs<string>> NameChanging; 183 /// <summary> 184 /// Fires a new <c>NameChanging</c> event. 185 /// </summary> 186 /// <param name="e">The event arguments of the changing.</param> 187 protected virtual void OnNameChanging(CancelEventArgs<string> e) { 188 var handler = NameChanging; 189 if (handler != null) handler(this, e); 190 } 191 /// <inheritdoc/> 192 public event EventHandler NameChanged; 193 /// <summary> 194 /// Fires a new <c>NameChanged</c> event. 195 /// </summary> 196 /// <remarks>Calls <see cref="ItemBase.OnChanged"/>.</remarks> 197 protected virtual void OnNameChanged() { 198 var handler = NameChanged; 199 if (handler != null) handler(this, EventArgs.Empty); 200 OnToStringChanged(); 201 } 202 /// <inheritdoc/> 203 public event EventHandler DescriptionChanged; 204 /// <summary> 205 /// Fires a new <c>DescriptionChanged</c> event. 206 /// </summary> 207 /// <remarks>Calls <see cref="ItemBase.OnChanged"/>.</remarks> 208 protected virtual void OnDescriptionChanged() { 209 var handler = DescriptionChanged; 210 if (handler != null) handler(this, EventArgs.Empty); 211 } 212 #endregion 213 #region IItem 214 public virtual string ItemName { 215 get { return ItemAttribute.GetName(this.GetType()); } 216 } 217 public virtual string ItemDescription { 218 get { return ItemAttribute.GetDescription(this.GetType()); } 219 } 220 public Version ItemVersion { 221 get { return ItemAttribute.GetVersion(this.GetType()); } 222 } 223 public static Image StaticItemImage { 224 get { return HeuristicLab.Common.Resources.VSImageLibrary.Class; } 225 } 226 public virtual Image ItemImage { 227 get { return ItemAttribute.GetImage(this.GetType()); } 228 } 229 public object Clone() { 230 return Clone(new Cloner()); 231 } 232 233 public event EventHandler ItemImageChanged; 234 protected virtual void OnItemImageChanged() { 235 var handler = ItemImageChanged; 236 if (handler != null) handler(this, EventArgs.Empty); 237 } 238 public event EventHandler ToStringChanged; 239 protected virtual void OnToStringChanged() { 240 var handler = ToStringChanged; 241 if (handler != null) handler(this, EventArgs.Empty); 242 } 243 #endregion 52 protected SingleObjectiveProblemDefinition(Encoding encoding) : this(encoding, "SingleObjectiveProblemDefinition", null) { } 53 protected SingleObjectiveProblemDefinition(Encoding encoding, string name) : this(encoding, name, null) { } 54 protected SingleObjectiveProblemDefinition(Encoding encoding, string name, string description) 55 : base(encoding) { } 244 56 } 245 57 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs
r11424 r11484 55 55 } 56 56 57 public IValueParameter<ISingleObjectiveProblemDefinition Host> ProblemDefinitionParameter {58 get { return (IValueParameter<ISingleObjectiveProblemDefinition Host>)Parameters["ProblemDefinition"]; }59 } 60 61 protected IValueParameter< Configuration> ConfigurationParameter {62 get { return (IValueParameter< Configuration>)Parameters["Configuration"]; }63 } 64 65 public ISingleObjectiveProblemDefinition HostProblemDefinition {57 public IValueParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter { 58 get { return (IValueParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; } 59 } 60 61 protected IValueParameter<Encoding> EncodingParameter { 62 get { return (IValueParameter<Encoding>)Parameters["Encoding"]; } 63 } 64 65 public ISingleObjectiveProblemDefinition ProblemDefinition { 66 66 get { return ProblemDefinitionParameter.Value; } 67 67 set { ProblemDefinitionParameter.Value = value; } … … 69 69 70 70 [Storable] 71 protected List<IParameter> Dynamic ConfigurationParameters;71 protected List<IParameter> DynamicEncodingParameters; 72 72 73 73 [StorableConstructor] … … 76 76 protected SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblem original, Cloner cloner) 77 77 : base(original, cloner) { 78 Dynamic ConfigurationParameters = original.DynamicConfigurationParameters.Select(cloner.Clone).ToList();78 DynamicEncodingParameters = original.DynamicEncodingParameters.Select(cloner.Clone).ToList(); 79 79 RegisterEventHandlers(); 80 80 } 81 81 public SingleObjectiveProgrammableProblem() 82 : base(new SingleObjectiveEvaluator(), new ParameterVectorCreater()) {83 Parameters.Add(new ValueParameter<ISingleObjectiveProblemDefinition Host>("ProblemDefinition", "Defines the problem.", new SingleObjectiveProblemDefinitionScript() { Name = Name }));84 Parameters.Add(new ValueParameter< Configuration>("Configuration", "Describes which parameters exist, what they're called, what type they are and their bounds if any."));85 86 Dynamic ConfigurationParameters = new List<IParameter>();82 : base(new SingleObjectiveEvaluator(), new MultiEncodingCreator()) { 83 Parameters.Add(new ValueParameter<ISingleObjectiveProblemDefinition>("ProblemDefinition", "Defines the problem.", new SingleObjectiveProblemScript() { Name = Name })); 84 Parameters.Add(new ValueParameter<Encoding>("Encoding", "Describes the configuration of the encoding, what the variables are called, what type they are and their bounds if any.")); 85 86 DynamicEncodingParameters = new List<IParameter>(); 87 87 88 88 Operators.Add(new BestScopeSolutionAnalyzer()); … … 116 116 117 117 private void RegisterHostInstanceChanges() { 118 ProblemDefinitionParameter.Value. InstanceChanged += ProblemDefinitionHostOnInstanceChanged;118 ProblemDefinitionParameter.Value.ProblemDefinitionChanged += ProblemDefinitionChanged; 119 119 ProblemDefinitionParameter.Value.NameChanged += ProblemDefinitionHostOnNameChanged; 120 120 } … … 135 135 } 136 136 137 protected virtual void ProblemDefinition HostOnInstanceChanged(object sender, EventArgs eventArgs) {137 protected virtual void ProblemDefinitionChanged(object sender, EventArgs eventArgs) { 138 138 Parameterize(); 139 139 } 140 140 141 141 protected virtual void Parameterize() { 142 var instance = ProblemDefinitionParameter.Value.Instance;143 if ( instance== null) return;144 145 Configuration configuration;142 var definition = ProblemDefinitionParameter.Value; 143 if (definition == null) return; 144 145 Encoding encoding; 146 146 try { 147 configuration = instance.GetConfiguration();147 encoding = definition.Encoding; 148 148 } catch { return; } 149 ConfigurationParameter.Value = configuration;150 Maximization.Value = instance.IsMaximizationProblem;151 152 Evaluator. ConfigurationParameter.ActualName = ConfigurationParameter.Name;149 EncodingParameter.Value = encoding; 150 Maximization.Value = definition.IsMaximizationProblem; 151 152 Evaluator.EncodingParameter.ActualName = EncodingParameter.Name; 153 153 Evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 154 154 foreach (var evalOp in Operators.OfType<ISingleObjectiveProgrammableProblemEvaluator>()) { 155 evalOp. ConfigurationParameter.ActualName = ConfigurationParameter.Name;155 evalOp.EncodingParameter.ActualName = EncodingParameter.Name; 156 156 evalOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 157 157 } 158 158 foreach (var analyzeOp in Operators.OfType<ISingleObjectiveProgrammableProblemAnalyzer>()) { 159 analyzeOp. ConfigurationParameter.ActualName = ConfigurationParameter.Name;159 analyzeOp.EncodingParameter.ActualName = EncodingParameter.Name; 160 160 analyzeOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 161 161 analyzeOp.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 162 162 } 163 163 164 var solutionCreators = UpdateDynamicConfigurationParameters(configuration); 165 166 if (solutionCreators.Count == 1) { 167 Operators.RemoveAll(x => x is ParameterVectorCrossover 168 || x is ParameterVectorManipulator); 169 UpdateSingleVectorEncodingOperators(solutionCreators, configuration); 164 foreach (var param in DynamicEncodingParameters) 165 if (Parameters.Contains(param)) Parameters.Remove(param); 166 DynamicEncodingParameters.Clear(); 167 168 var creator = ConfigureCreator(encoding); 169 170 foreach (var param in DynamicEncodingParameters) { 171 param.Hidden = true; 172 Parameters.Add(param); 173 } 174 175 var multiEncoding = encoding as MultiEncoding; 176 if (multiEncoding != null) { 177 ConfigureMultiVectorEncodingOperators((MultiEncodingCreator)creator, multiEncoding); 170 178 } else { 171 UpdateMultiVectorEncodingOperators(solutionCreators, configuration);179 ConfigureSingleEncodingOperators(creator, encoding); 172 180 } 173 181 UpdateImprovementOperators(); … … 175 183 } 176 184 177 protected virtual List<ISolutionCreator> UpdateDynamicConfigurationParameters(Configuration configuration) { 178 foreach (var param in DynamicConfigurationParameters) 179 if (Parameters.Contains(param)) Parameters.Remove(param); 180 DynamicConfigurationParameters.Clear(); 181 182 var solutionCreators = new List<ISolutionCreator>(); 183 foreach (var param in configuration.Parameters) { 184 #region Configure BinaryVector Creator 185 var binConfig = param.Value as BinaryParameterConfiguration; 186 if (binConfig != null) { 187 var p = new ValueParameter<IntValue>(param.Key + "Length", binConfig.Length); 188 DynamicConfigurationParameters.Add(p); 189 190 var creator = new RandomBinaryVectorCreator(); 191 creator.BinaryVectorParameter.ActualName = param.Key; 192 creator.LengthParameter.ActualName = p.Name; 193 solutionCreators.Add(creator); 194 } 195 #endregion 196 #region Configure IntegerVector Creator 197 var intConfig = param.Value as IntegerParameterConfiguration; 198 if (intConfig != null) { 199 var l = new ValueParameter<IntValue>(param.Key + "Length", intConfig.Length); 200 var b = new ValueParameter<IntMatrix>(param.Key + "Bounds", intConfig.Bounds); 201 DynamicConfigurationParameters.Add(l); 202 DynamicConfigurationParameters.Add(b); 203 204 var creator = new UniformRandomIntegerVectorCreator(); 205 creator.IntegerVectorParameter.ActualName = param.Key; 206 creator.LengthParameter.ActualName = l.Name; 207 creator.BoundsParameter.ActualName = b.Name; 208 solutionCreators.Add(creator); 209 } 210 #endregion 211 #region Configure RealVector Creator 212 var realConfig = param.Value as RealParameterConfiguration; 213 if (realConfig != null) { 214 var l = new ValueParameter<IntValue>(param.Key + "Length", realConfig.Length); 215 var b = new ValueParameter<DoubleMatrix>(param.Key + "Bounds", realConfig.Bounds); 216 DynamicConfigurationParameters.Add(l); 217 DynamicConfigurationParameters.Add(b); 218 219 var creator = new UniformRandomRealVectorCreator(); 220 creator.RealVectorParameter.ActualName = param.Key; 221 creator.LengthParameter.ActualName = l.Name; 222 creator.BoundsParameter.ActualName = b.Name; 223 solutionCreators.Add(creator); 224 } 225 #endregion 226 #region Configure Permutation Creator 227 var permConfig = param.Value as PermutationParameterConfiguration; 228 if (permConfig != null) { 229 var l = new ValueParameter<IntValue>(param.Key + "Length", permConfig.Length); 230 DynamicConfigurationParameters.Add(l); 231 232 var creator = new RandomPermutationCreator(); 233 creator.PermutationParameter.ActualName = param.Key; 234 creator.LengthParameter.ActualName = l.Name; 235 creator.PermutationTypeParameter.Value = permConfig.Type; 236 solutionCreators.Add(creator); 237 } 238 #endregion 239 } 240 241 foreach (var param in DynamicConfigurationParameters) { 242 param.Hidden = true; 243 Parameters.Add(param); 244 } 245 return solutionCreators; 246 } 247 248 protected virtual void UpdateSingleVectorEncodingOperators(List<ISolutionCreator> solutionCreators, Configuration configuration) { 249 var newCreator = solutionCreators.Single(); 185 protected virtual ISolutionCreator ConfigureCreator(Encoding encoding) { 186 #region Configure MultiEncoding Creator 187 var multiEncoding = encoding as MultiEncoding; 188 if (multiEncoding != null) { 189 var creator = new MultiEncodingCreator(); 190 foreach (var enc in multiEncoding.Encodings) { 191 if (enc is MultiEncoding) throw new InvalidOperationException("MultiEncoding within a MultiEncoding is not supported."); 192 creator.Operators.Add(ConfigureCreator(enc)); 193 } 194 return creator; 195 } 196 #endregion 197 #region Configure BinaryVector Creator 198 var binEnc = encoding as BinaryEncoding; 199 if (binEnc != null) { 200 var p = new ValueParameter<IntValue>(binEnc.Name + "Length", binEnc.Length); 201 DynamicEncodingParameters.Add(p); 202 203 var creator = new RandomBinaryVectorCreator(); 204 creator.BinaryVectorParameter.ActualName = binEnc.Name; 205 creator.LengthParameter.ActualName = p.Name; 206 return creator; 207 } 208 #endregion 209 #region Configure IntegerVector Creator 210 var intEnc = encoding as IntegerEncoding; 211 if (intEnc != null) { 212 var l = new ValueParameter<IntValue>(intEnc.Name + "Length", intEnc.Length); 213 var b = new ValueParameter<IntMatrix>(intEnc.Name + "Bounds", intEnc.Bounds); 214 DynamicEncodingParameters.Add(l); 215 DynamicEncodingParameters.Add(b); 216 217 var creator = new UniformRandomIntegerVectorCreator(); 218 creator.IntegerVectorParameter.ActualName = intEnc.Name; 219 creator.LengthParameter.ActualName = l.Name; 220 creator.BoundsParameter.ActualName = b.Name; 221 return creator; 222 } 223 #endregion 224 #region Configure RealVector Creator 225 var realEnc = encoding as RealEncoding; 226 if (realEnc != null) { 227 var l = new ValueParameter<IntValue>(realEnc.Name + "Length", realEnc.Length); 228 var b = new ValueParameter<DoubleMatrix>(realEnc.Name + "Bounds", realEnc.Bounds); 229 DynamicEncodingParameters.Add(l); 230 DynamicEncodingParameters.Add(b); 231 232 var creator = new UniformRandomRealVectorCreator(); 233 creator.RealVectorParameter.ActualName = realEnc.Name; 234 creator.LengthParameter.ActualName = l.Name; 235 creator.BoundsParameter.ActualName = b.Name; 236 return creator; 237 } 238 #endregion 239 #region Configure Permutation Creator 240 var permEnc = encoding as PermutationEncoding; 241 if (permEnc != null) { 242 var l = new ValueParameter<IntValue>(permEnc.Name + "Length", permEnc.Length); 243 DynamicEncodingParameters.Add(l); 244 245 var creator = new RandomPermutationCreator(); 246 creator.PermutationParameter.ActualName = permEnc.Name; 247 creator.LengthParameter.ActualName = l.Name; 248 creator.PermutationTypeParameter.Value = permEnc.Type; 249 return creator; 250 } 251 #endregion 252 throw new ArgumentException(string.Format("Encoding {0} is unknown.", encoding != null ? encoding.GetType().FullName : "(null)")); 253 } 254 255 protected virtual void ConfigureSingleEncodingOperators(ISolutionCreator newCreator, Encoding encoding) { 256 // remove all multiencoding operators 257 Operators.RemoveAll(x => x is MultiEncodingCrossover 258 || x is MultiEncodingManipulator 259 || x is MultiEncodingCreator); 260 250 261 #region Configure Operators for BinaryVectorEncoding 251 262 var binCreator = newCreator as IBinaryVectorCreator; … … 260 271 261 272 #region Wire BinaryVector Crossovers 262 Operators.RemoveAll(x => x is IBinaryVectorCrossover && ((IBinaryVectorCrossover)x).ChildParameter.ActualName != paramName); 263 var crossovers = ApplicationManager.Manager.GetInstances<IBinaryVectorCrossover>().ToList(); 273 var crossovers = Operators.OfType<IBinaryVectorCrossover>() 274 .Union(ApplicationManager.Manager.GetInstances<IBinaryVectorCrossover>(), new TypeEqualityComparer<IBinaryVectorCrossover>()) 275 .ToList(); 264 276 foreach (var xo in crossovers) { 265 277 xo.ChildParameter.ActualName = binCreator.BinaryVectorParameter.ActualName; … … 268 280 xo.ParentsParameter.Hidden = true; 269 281 } 270 Operators.AddRange(crossovers. Where(x => Operators.All(y => x.GetType() != y.GetType())));282 Operators.AddRange(crossovers.Except(Operators.OfType<IBinaryVectorCrossover>())); 271 283 #endregion 272 284 #region Wire BinaryVector Manipulators 273 Operators.RemoveAll(x => x is IBinaryVectorManipulator && ((IBinaryVectorManipulator)x).BinaryVectorParameter.ActualName != paramName); 274 var manipulators = ApplicationManager.Manager.GetInstances<IBinaryVectorManipulator>().ToList(); 285 var manipulators = Operators.OfType<IBinaryVectorManipulator>() 286 .Union(ApplicationManager.Manager.GetInstances<IBinaryVectorManipulator>(), new TypeEqualityComparer<IBinaryVectorManipulator>()) 287 .ToList(); 275 288 foreach (var m in manipulators) { 276 289 m.BinaryVectorParameter.ActualName = binCreator.BinaryVectorParameter.ActualName; 277 290 m.BinaryVectorParameter.Hidden = true; 278 291 } 279 Operators.AddRange(manipulators. Where(x => Operators.All(y => x.GetType() != y.GetType())));292 Operators.AddRange(manipulators.Except(Operators.OfType<IBinaryVectorManipulator>())); 280 293 #endregion 281 294 #region Wire BinaryVector ShakingOperators 282 Operators.RemoveAll(x => x is IBinaryVectorMultiNeighborhoodShakingOperator && ((IBinaryVectorMultiNeighborhoodShakingOperator)x).BinaryVectorParameter.ActualName != paramName); 283 var shakingOperators = ApplicationManager.Manager.GetInstances<IBinaryVectorMultiNeighborhoodShakingOperator>().ToList(); 295 var shakingOperators = Operators.OfType<IBinaryVectorMultiNeighborhoodShakingOperator>() 296 .Union(ApplicationManager.Manager.GetInstances<IBinaryVectorMultiNeighborhoodShakingOperator>(), new TypeEqualityComparer<IBinaryVectorMultiNeighborhoodShakingOperator>()) 297 .ToList(); 284 298 foreach (var so in shakingOperators) { 285 299 so.BinaryVectorParameter.ActualName = paramName; 286 300 so.BinaryVectorParameter.Hidden = true; 287 301 } 288 Operators.AddRange(shakingOperators. Where(x => Operators.All(y => x.GetType() != y.GetType())));302 Operators.AddRange(shakingOperators.Except(Operators.OfType<IBinaryVectorMultiNeighborhoodShakingOperator>())); 289 303 #endregion 290 304 } else { … … 307 321 308 322 #region Wire IntegerVector Crossovers 309 Operators.RemoveAll(x => x is IIntegerVectorCrossover && ((IIntegerVectorCrossover)x).ChildParameter.ActualName != paramName); 310 var crossovers = ApplicationManager.Manager.GetInstances<IIntegerVectorCrossover>().ToList(); 323 var crossovers = Operators.OfType<IIntegerVectorCrossover>() 324 .Union(ApplicationManager.Manager.GetInstances<IIntegerVectorCrossover>(), new TypeEqualityComparer<IIntegerVectorCrossover>()) 325 .ToList(); 311 326 foreach (var xo in crossovers) { 312 327 xo.ChildParameter.ActualName = intCreator.IntegerVectorParameter.ActualName; … … 320 335 } 321 336 } 322 Operators.AddRange(crossovers. Where(x => Operators.All(y => x.GetType() != y.GetType())));337 Operators.AddRange(crossovers.Except(Operators.OfType<IIntegerVectorCrossover>())); 323 338 #endregion 324 339 #region Wire IntegerVector Manipulators 325 Operators.RemoveAll(x => x is IIntegerVectorManipulator && ((IIntegerVectorManipulator)x).IntegerVectorParameter.ActualName != paramName); 326 var manipulators = ApplicationManager.Manager.GetInstances<IIntegerVectorManipulator>().ToList(); 340 var manipulators = Operators.OfType<IIntegerVectorManipulator>() 341 .Union(ApplicationManager.Manager.GetInstances<IIntegerVectorManipulator>(), new TypeEqualityComparer<IIntegerVectorManipulator>()) 342 .ToList(); 327 343 foreach (var m in manipulators) { 328 344 m.IntegerVectorParameter.ActualName = intCreator.IntegerVectorParameter.ActualName; … … 342 358 } 343 359 } 344 Operators.AddRange(manipulators. Where(x => Operators.All(y => x.GetType() != y.GetType())));360 Operators.AddRange(manipulators.Except(Operators.OfType<IIntegerVectorManipulator>())); 345 361 #region Wire IntegerVector StrategyParameters for SelfAdaptiveManipulators 346 Operators.RemoveAll(x => x is IStrategyParameterCreator && !(x is IIntegerVectorStdDevStrategyParameterCreator) || x is IIntegerVectorStdDevStrategyParameterCreator && ((IIntegerVectorStdDevStrategyParameterCreator)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 347 Operators.RemoveAll(x => x is IStrategyParameterManipulator && !(x is IIntegerVectorStdDevStrategyParameterManipulator) || x is IIntegerVectorStdDevStrategyParameterManipulator && ((IIntegerVectorStdDevStrategyParameterManipulator)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 348 Operators.RemoveAll(x => x is IStrategyParameterCrossover && !(x is IIntegerVectorStdDevStrategyParameterCrossover) || x is IIntegerVectorStdDevStrategyParameterCrossover && ((IIntegerVectorStdDevStrategyParameterCrossover)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 349 var strategyOperators = ApplicationManager.Manager.GetInstances<IIntegerVectorStdDevStrategyParameterOperator>().ToList(); 350 if (!(configuration.Parameters.First().Value is IntegerParameterConfiguration)) throw new InvalidOperationException("Single-encoded problem with integervector creator that is not an integer-coded problem."); 351 var problemSize = ((IntegerParameterConfiguration)configuration.Parameters.First().Value).Length.Value; 352 var b = ((IntegerParameterConfiguration)configuration.Parameters.First().Value).Bounds; 362 var strategyOperators = Operators.OfType<IIntegerVectorStdDevStrategyParameterOperator>() 363 .Union(ApplicationManager.Manager.GetInstances<IIntegerVectorStdDevStrategyParameterOperator>(), new TypeEqualityComparer<IIntegerVectorStdDevStrategyParameterOperator>()) 364 .ToList(); 365 var problemSize = ((IntegerEncoding)encoding).Length.Value; 366 var b = ((IntegerEncoding)encoding).Bounds; 353 367 var bounds = new DoubleMatrix(b.Rows, b.Columns); 354 368 for (var i = 0; i < bounds.Rows; i++) { … … 380 394 } 381 395 } 382 Operators.AddRange(strategyOperators. Where(x => Operators.All(y => x.GetType() != y.GetType())));396 Operators.AddRange(strategyOperators.Except(Operators.OfType<IIntegerVectorStdDevStrategyParameterOperator>())); 383 397 #endregion 384 398 #endregion 385 399 #region Wire IntegerVector ShakingOperators 386 Operators.RemoveAll(x => x is IIntegerVectorMultiNeighborhoodShakingOperator && ((IIntegerVectorMultiNeighborhoodShakingOperator)x).IntegerVectorParameter.ActualName != paramName); 387 var shakingOperators = ApplicationManager.Manager.GetInstances<IIntegerVectorMultiNeighborhoodShakingOperator>().ToList(); 400 var shakingOperators = Operators.OfType<IIntegerVectorMultiNeighborhoodShakingOperator>() 401 .Union(ApplicationManager.Manager.GetInstances<IIntegerVectorMultiNeighborhoodShakingOperator>(), new TypeEqualityComparer<IIntegerVectorMultiNeighborhoodShakingOperator>()) 402 .ToList(); 388 403 foreach (var so in shakingOperators) { 389 404 so.IntegerVectorParameter.ActualName = paramName; 390 405 so.IntegerVectorParameter.Hidden = true; 391 406 } 392 Operators.AddRange(shakingOperators. Where(x => Operators.All(y => x.GetType() != y.GetType())));407 Operators.AddRange(shakingOperators.Except(Operators.OfType<IIntegerVectorMultiNeighborhoodShakingOperator>())); 393 408 #endregion 394 409 } else { … … 412 427 413 428 #region Wire RealVector Crossovers 414 Operators.RemoveAll(x => x is IRealVectorCrossover && ((IRealVectorCrossover)x).ChildParameter.ActualName != paramName); 415 var crossovers = ApplicationManager.Manager.GetInstances<IRealVectorCrossover>().ToList(); 429 var crossovers = Operators.OfType<IRealVectorCrossover>() 430 .Union(ApplicationManager.Manager.GetInstances<IRealVectorCrossover>(), new TypeEqualityComparer<IRealVectorCrossover>()) 431 .ToList(); 416 432 foreach (var xo in crossovers) { 417 433 xo.ChildParameter.ActualName = paramName; … … 422 438 xo.BoundsParameter.Hidden = true; 423 439 } 424 Operators.AddRange(crossovers. Where(x => Operators.All(y => x.GetType() != y.GetType())));440 Operators.AddRange(crossovers.Except(Operators.OfType<IRealVectorCrossover>())); 425 441 #endregion 426 442 #region Wire RealVector Manipulators 427 Operators.RemoveAll(x => x is IRealVectorManipulator && ((IRealVectorManipulator)x).RealVectorParameter.ActualName != paramName); 428 var manipulators = ApplicationManager.Manager.GetInstances<IRealVectorManipulator>().ToList(); 443 var manipulators = Operators.OfType<IRealVectorManipulator>() 444 .Union(ApplicationManager.Manager.GetInstances<IRealVectorManipulator>(), new TypeEqualityComparer<IRealVectorManipulator>()) 445 .ToList(); 429 446 foreach (var m in manipulators) { 430 447 m.RealVectorParameter.ActualName = paramName; … … 441 458 } 442 459 } 443 Operators.AddRange(manipulators. Where(x => Operators.All(y => x.GetType() != y.GetType())));460 Operators.AddRange(manipulators.Except(Operators.OfType<IRealVectorManipulator>())); 444 461 #region Wire RealVector Strategy Parameters for SelfAdaptiveManipulators 445 446 Operators.RemoveAll(x => x is IStrategyParameterCreator && !(x is IRealVectorStdDevStrategyParameterCreator) || x is IRealVectorStdDevStrategyParameterCreator && ((IRealVectorStdDevStrategyParameterCreator)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 447 Operators.RemoveAll(x => x is IStrategyParameterManipulator && !(x is IRealVectorStdDevStrategyParameterManipulator) || x is IRealVectorStdDevStrategyParameterManipulator && ((IRealVectorStdDevStrategyParameterManipulator)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 448 Operators.RemoveAll(x => x is IStrategyParameterCrossover && !(x is IRealVectorStdDevStrategyParameterCrossover) || x is IRealVectorStdDevStrategyParameterCrossover && ((IRealVectorStdDevStrategyParameterCrossover)x).StrategyParameterParameter.ActualName != paramName + "Strategy"); 449 var strategyOperators = ApplicationManager.Manager.GetInstances<IRealVectorStdDevStrategyParameterOperator>().ToList(); 450 if (!(configuration.Parameters.First().Value is RealParameterConfiguration)) throw new InvalidOperationException("Single-encoded problem with realvector creator that is not a real-coded problem."); 451 var problemSize = ((RealParameterConfiguration)configuration.Parameters.First().Value).Length.Value; 452 var bounds = (DoubleMatrix)((RealParameterConfiguration)configuration.Parameters.First().Value).Bounds.Clone(); 462 var strategyOperators = Operators.OfType<IRealVectorStdDevStrategyParameterOperator>() 463 .Union(ApplicationManager.Manager.GetInstances<IRealVectorStdDevStrategyParameterOperator>(), new TypeEqualityComparer<IRealVectorStdDevStrategyParameterOperator>()) 464 .ToList(); 465 var problemSize = ((RealEncoding)encoding).Length.Value; 466 var bounds = (DoubleMatrix)((RealEncoding)encoding).Bounds.Clone(); 453 467 for (var i = 0; i < bounds.Rows; i++) { 454 468 bounds[i, 1] = 0.1 * (bounds[i, 1] - bounds[i, 0]); … … 478 492 } 479 493 } 480 Operators.AddRange(strategyOperators. Where(x => Operators.All(y => x.GetType() != y.GetType())));494 Operators.AddRange(strategyOperators.Except(Operators.OfType<IRealVectorStdDevStrategyParameterOperator>())); 481 495 #endregion 482 496 #endregion 483 497 #region Wire RealVector ParticleCreators 484 Operators.RemoveAll(x => x is IRealVectorParticleCreator && ((IRealVectorParticleCreator)x).RealVectorParameter.ActualName != paramName); 485 var particleCreators = ApplicationManager.Manager.GetInstances<IRealVectorParticleCreator>().ToList(); 498 var particleCreators = Operators.OfType<IRealVectorParticleCreator>() 499 .Union(ApplicationManager.Manager.GetInstances<IRealVectorParticleCreator>(), new TypeEqualityComparer<IRealVectorParticleCreator>()) 500 .ToList(); 486 501 foreach (var pc in particleCreators) { 487 502 pc.RealVectorParameter.ActualName = paramName; … … 492 507 pc.ProblemSizeParameter.Hidden = true; 493 508 } 494 Operators.AddRange(particleCreators. Where(x => Operators.All(y => x.GetType() != y.GetType())));509 Operators.AddRange(particleCreators.Except(Operators.OfType<IRealVectorParticleCreator>())); 495 510 #endregion 496 511 #region Wire RealVector ParticleUpdaters 497 Operators.RemoveAll(x => x is IRealVectorParticleUpdater && ((IRealVectorParticleUpdater)x).RealVectorParameter.ActualName != paramName); 498 var particleUpdaters = ApplicationManager.Manager.GetInstances<IRealVectorParticleUpdater>().ToList(); 512 var particleUpdaters = Operators.OfType<IRealVectorParticleUpdater>() 513 .Union(ApplicationManager.Manager.GetInstances<IRealVectorParticleUpdater>(), new TypeEqualityComparer<IRealVectorParticleUpdater>()) 514 .ToList(); 499 515 foreach (var pu in particleUpdaters) { 500 516 pu.RealVectorParameter.ActualName = paramName; … … 503 519 pu.BoundsParameter.Hidden = true; 504 520 } 505 Operators.AddRange(particleUpdaters. Where(x => Operators.All(y => x.GetType() != y.GetType())));521 Operators.AddRange(particleUpdaters.Except(Operators.OfType<IRealVectorParticleUpdater>())); 506 522 #endregion 507 523 #region Wire RealVector SwarmUpdaters 508 Operators.RemoveAll(x => x is IRealVectorSwarmUpdater && ((IRealVectorSwarmUpdater)x).RealVectorParameter.ActualName != paramName); 509 var swarmUpdaters = ApplicationManager.Manager.GetInstances<IRealVectorSwarmUpdater>().ToList(); 524 var swarmUpdaters = Operators.OfType<IRealVectorSwarmUpdater>() 525 .Union(ApplicationManager.Manager.GetInstances<IRealVectorSwarmUpdater>(), new TypeEqualityComparer<IRealVectorSwarmUpdater>()) 526 .ToList(); 510 527 foreach (var su in swarmUpdaters) { 511 528 su.RealVectorParameter.ActualName = paramName; … … 514 531 su.MaximizationParameter.Hidden = true; 515 532 } 516 Operators.AddRange(swarmUpdaters. Where(x => Operators.All(y => x.GetType() != y.GetType())));533 Operators.AddRange(swarmUpdaters.Except(Operators.OfType<IRealVectorSwarmUpdater>())); 517 534 #endregion 518 535 #region Wire RealVector ShakingOperators 519 Operators.RemoveAll(x => x is IRealVectorMultiNeighborhoodShakingOperator && ((IRealVectorMultiNeighborhoodShakingOperator)x).RealVectorParameter.ActualName != paramName); 520 var shakingOperators = ApplicationManager.Manager.GetInstances<IRealVectorMultiNeighborhoodShakingOperator>().ToList(); 536 var shakingOperators = Operators.OfType<IRealVectorMultiNeighborhoodShakingOperator>() 537 .Union(ApplicationManager.Manager.GetInstances<IRealVectorMultiNeighborhoodShakingOperator>(), new TypeEqualityComparer<IRealVectorMultiNeighborhoodShakingOperator>()) 538 .ToList(); 521 539 foreach (var so in shakingOperators) { 522 540 so.RealVectorParameter.ActualName = paramName; 523 541 so.RealVectorParameter.Hidden = true; 524 542 } 525 Operators.AddRange(shakingOperators. Where(x => Operators.All(y => x.GetType() != y.GetType())));543 Operators.AddRange(shakingOperators.Except(Operators.OfType<IRealVectorMultiNeighborhoodShakingOperator>())); 526 544 #endregion 527 545 } else { … … 548 566 549 567 #region Wire Permutation Crossovers 550 Operators.RemoveAll(x => x is IPermutationCrossover && ((IPermutationCrossover)x).ChildParameter.ActualName != paramName); 551 var crossovers = ApplicationManager.Manager.GetInstances<IPermutationCrossover>().ToList(); 568 var crossovers = Operators.OfType<IPermutationCrossover>() 569 .Union(ApplicationManager.Manager.GetInstances<IPermutationCrossover>(), new TypeEqualityComparer<IPermutationCrossover>()) 570 .ToList(); 552 571 foreach (var xo in crossovers) { 553 572 xo.ChildParameter.ActualName = permCreator.PermutationParameter.ActualName; … … 556 575 xo.ParentsParameter.Hidden = true; 557 576 } 558 Operators.AddRange(crossovers. Where(x => Operators.All(y => x.GetType() != y.GetType())));577 Operators.AddRange(crossovers.Except(Operators.OfType<IPermutationCrossover>())); 559 578 #endregion 560 579 #region Wire Permutation Manipulators 561 Operators.RemoveAll(x => x is IPermutationManipulator && ((IPermutationManipulator)x).PermutationParameter.ActualName != paramName); 562 var manipulators = ApplicationManager.Manager.GetInstances<IPermutationManipulator>().ToList(); 580 var manipulators = Operators.OfType<IPermutationManipulator>() 581 .Union(ApplicationManager.Manager.GetInstances<IPermutationManipulator>(), new TypeEqualityComparer<IPermutationManipulator>()) 582 .ToList(); 563 583 foreach (var m in manipulators) { 564 584 m.PermutationParameter.ActualName = permCreator.PermutationParameter.ActualName; 565 585 m.PermutationParameter.Hidden = true; 566 586 } 567 Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType()))); 568 #endregion 569 #region Wire ShakingOperators 570 Operators.RemoveAll(x => x is IPermutationMultiNeighborhoodShakingOperator && ((IPermutationMultiNeighborhoodShakingOperator)x).PermutationParameter.ActualName != paramName); 571 var shakingOperators = ApplicationManager.Manager.GetInstances<IPermutationMultiNeighborhoodShakingOperator>().ToList(); 587 Operators.AddRange(manipulators.Except(Operators.OfType<IPermutationManipulator>())); 588 #endregion 589 #region Wire Permutation ShakingOperators 590 var shakingOperators = Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>() 591 .Union(ApplicationManager.Manager.GetInstances<IPermutationMultiNeighborhoodShakingOperator>(), new TypeEqualityComparer<IPermutationMultiNeighborhoodShakingOperator>()) 592 .ToList(); 572 593 foreach (var op in shakingOperators) { 573 594 op.PermutationParameter.ActualName = paramName; 574 595 op.PermutationParameter.Hidden = true; 575 596 } 576 Operators.AddRange(shakingOperators. Where(x => Operators.All(y => x.GetType() != y.GetType())));597 Operators.AddRange(shakingOperators.Except(Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>())); 577 598 #endregion 578 599 } else { … … 584 605 } 585 606 586 protected virtual void UpdateMultiVectorEncodingOperators(List<ISolutionCreator> solutionCreators, Configuration configuration) { 587 var oldCreator = SolutionCreator as ParameterVectorCreater; 588 var newCreator = new ParameterVectorCreater(); 589 590 #region Configure BinaryVector Creator 591 var newBinParams = new HashSet<string>(solutionCreators.OfType<IBinaryVectorCreator>().Select(x => x.BinaryVectorParameter.ActualName)); 592 if (oldCreator != null) { 593 // we want to reuse the old creator 594 var oldParams = new HashSet<string>(oldCreator.Operators.OfType<IBinaryVectorCreator>() 595 .Select(x => x.BinaryVectorParameter.ActualName)); 596 foreach (var toAdd in newBinParams.Except(oldParams)) { 597 var paramName = toAdd; 598 oldCreator.Operators.Add( 599 solutionCreators.OfType<IBinaryVectorCreator>().Single(x => x.BinaryVectorParameter.ActualName == paramName)); 600 } 601 foreach (var toRemove in oldParams.Except(newBinParams)) { 602 var paramName = toRemove; 603 var op = 604 oldCreator.Operators.OfType<IBinaryVectorCreator>() 605 .SingleOrDefault(x => x.BinaryVectorParameter.ActualName == paramName); 607 protected virtual void ConfigureMultiVectorEncodingOperators(MultiEncodingCreator newCreator, MultiEncoding encoding) { 608 var newBinParams = new HashSet<string>(newCreator.Operators.OfType<IBinaryVectorCreator>().Select(x => x.BinaryVectorParameter.ActualName)); 609 var newIntParams = new HashSet<string>(newCreator.Operators.OfType<IIntegerVectorCreator>().Select(x => x.IntegerVectorParameter.ActualName)); 610 var newRealParams = new HashSet<string>(newCreator.Operators.OfType<IRealVectorCreator>().Select(x => x.RealVectorParameter.ActualName)); 611 var newPermParams = new HashSet<string>(newCreator.Operators.OfType<IPermutationCreator>().Select(x => x.PermutationParameter.ActualName)); 612 613 var oldCreator = SolutionCreator as MultiEncodingCreator; 614 if (oldCreator == null) SolutionCreator = newCreator; 615 else { 616 #region Configure BinaryVector Creator 617 var oldBinParams = new HashSet<string>(oldCreator.Operators.OfType<IBinaryVectorCreator>().Select(x => x.BinaryVectorParameter.ActualName)); 618 foreach (var toAdd in newBinParams.Except(oldBinParams)) { 619 oldCreator.Operators.Add(newCreator.Operators.OfType<IBinaryVectorCreator>().Single(x => x.BinaryVectorParameter.ActualName == toAdd)); 620 } 621 foreach (var toRemove in oldBinParams.Except(newBinParams)) { 622 var op = oldCreator.Operators.OfType<IBinaryVectorCreator>().SingleOrDefault(x => x.BinaryVectorParameter.ActualName == toRemove); 606 623 if (op != null) oldCreator.Operators.Remove(op); 607 624 } 608 } else { 609 // we will use the new creator 610 foreach (var binCreator in solutionCreators.OfType<IBinaryVectorCreator>()) { 611 newCreator.Operators.Add(binCreator); 612 } 613 } 614 #endregion 615 #region Configure IntegerVector Creator 616 var newIntParams = new HashSet<string>(solutionCreators.OfType<IIntegerVectorCreator>().Select(x => x.IntegerVectorParameter.ActualName)); 617 if (oldCreator != null) { 618 // we want to reuse the old creator 619 var oldParams = new HashSet<string>(oldCreator 620 .Operators.OfType<IIntegerVectorCreator>() 621 .Select(x => x.IntegerVectorParameter.ActualName)); 622 foreach (var toAdd in newIntParams.Except(oldParams)) { 623 var paramName = toAdd; 624 oldCreator.Operators.Add( 625 solutionCreators.OfType<IIntegerVectorCreator>().Single(x => x.IntegerVectorParameter.ActualName == paramName)); 626 } 627 foreach (var toRemove in oldParams.Except(newIntParams)) { 628 var paramName = toRemove; 629 var op = 630 oldCreator.Operators.OfType<IIntegerVectorCreator>() 631 .SingleOrDefault(x => x.IntegerVectorParameter.ActualName == paramName); 625 #endregion 626 627 #region Configure IntegerVector Creator 628 var oldIntParams = new HashSet<string>(oldCreator.Operators.OfType<IIntegerVectorCreator>().Select(x => x.IntegerVectorParameter.ActualName)); 629 foreach (var toAdd in newIntParams.Except(oldIntParams)) { 630 oldCreator.Operators.Add(newCreator.Operators.OfType<IIntegerVectorCreator>().Single(x => x.IntegerVectorParameter.ActualName == toAdd)); 631 } 632 foreach (var toRemove in oldIntParams.Except(newIntParams)) { 633 var op = oldCreator.Operators.OfType<IIntegerVectorCreator>().SingleOrDefault(x => x.IntegerVectorParameter.ActualName == toRemove); 632 634 if (op != null) oldCreator.Operators.Remove(op); 633 635 } 634 } else { 635 // we will use the new creator 636 foreach (var intCreator in solutionCreators.OfType<IIntegerVectorCreator>()) { 637 newCreator.Operators.Add(intCreator); 638 } 639 } 640 #endregion 641 #region Configure RealVector Creator 642 var newRealParams = new HashSet<string>(solutionCreators.OfType<IRealVectorCreator>().Select(x => x.RealVectorParameter.ActualName)); 643 if (oldCreator != null) { 644 // we want to reuse the old creator 645 var oldParams = new HashSet<string>(oldCreator 646 .Operators.OfType<IRealVectorCreator>() 647 .Select(x => x.RealVectorParameter.ActualName)); 648 foreach (var toAdd in newRealParams.Except(oldParams)) { 649 var paramName = toAdd; 650 oldCreator.Operators.Add( 651 solutionCreators.OfType<IRealVectorCreator>().Single(x => x.RealVectorParameter.ActualName == paramName)); 652 } 653 foreach (var toRemove in oldParams.Except(newRealParams)) { 654 var paramName = toRemove; 655 var op = 656 oldCreator.Operators.OfType<IRealVectorCreator>() 657 .SingleOrDefault(x => x.RealVectorParameter.ActualName == paramName); 636 #endregion 637 638 #region Configure RealVector Creator 639 var oldRealParams = new HashSet<string>(oldCreator.Operators.OfType<IRealVectorCreator>().Select(x => x.RealVectorParameter.ActualName)); 640 foreach (var toAdd in newRealParams.Except(oldRealParams)) { 641 oldCreator.Operators.Add(newCreator.Operators.OfType<IRealVectorCreator>().Single(x => x.RealVectorParameter.ActualName == toAdd)); 642 } 643 foreach (var toRemove in oldRealParams.Except(newRealParams)) { 644 var op = oldCreator.Operators.OfType<IRealVectorCreator>().SingleOrDefault(x => x.RealVectorParameter.ActualName == toRemove); 658 645 if (op != null) oldCreator.Operators.Remove(op); 659 646 } 660 } else { 661 // we will use the new creator 662 foreach (var realCreator in solutionCreators.OfType<IRealVectorCreator>()) { 663 newCreator.Operators.Add(realCreator); 664 } 665 } 666 #endregion 667 #region Configure Permutation Creator 668 var newPermParams = new HashSet<string>(solutionCreators.OfType<IPermutationCreator>().Select(x => x.PermutationParameter.ActualName)); 669 if (oldCreator != null) { 670 // we want to reuse the old creator 671 var oldParams = new HashSet<string>(oldCreator 672 .Operators.OfType<IPermutationCreator>() 673 .Select(x => x.PermutationParameter.ActualName)); 674 foreach (var toAdd in newPermParams.Except(oldParams)) { 675 var paramName = toAdd; 676 oldCreator.Operators.Add( 677 solutionCreators.OfType<IPermutationCreator>().Single(x => x.PermutationParameter.ActualName == paramName)); 678 } 679 foreach (var toRemove in oldParams.Except(newPermParams)) { 680 var paramName = toRemove; 681 var op = 682 oldCreator.Operators.OfType<IPermutationCreator>() 683 .SingleOrDefault(x => x.PermutationParameter.ActualName == paramName); 647 #endregion 648 649 #region Configure Permutation Creator 650 var oldPermParams = new HashSet<string>(oldCreator.Operators.OfType<IPermutationCreator>().Select(x => x.PermutationParameter.ActualName)); 651 foreach (var toAdd in newPermParams.Except(oldPermParams)) { 652 oldCreator.Operators.Add(newCreator.Operators.OfType<IPermutationCreator>().Single(x => x.PermutationParameter.ActualName == toAdd)); 653 } 654 foreach (var toRemove in oldPermParams.Except(newPermParams)) { 655 var op = oldCreator.Operators.OfType<IPermutationCreator>().SingleOrDefault(x => x.PermutationParameter.ActualName == toRemove); 684 656 if (op != null) oldCreator.Operators.Remove(op); 685 657 } 686 658 // we also have to sync the permutation type (in case this changes, as it is a value parameter) 687 foreach (var intersect in newPermParams.Intersect(oldParams)) { 688 var paramName = intersect; 689 var oldPermCreator = oldCreator.Operators.OfType<IPermutationCreator>() 690 .Single(x => x.PermutationParameter.ActualName == paramName); 691 var newPermCreator = solutionCreators.OfType<IPermutationCreator>() 692 .Single(x => x.PermutationParameter.ActualName == paramName); 659 foreach (var intersect in newPermParams.Intersect(oldPermParams)) { 660 var oldPermCreator = oldCreator.Operators.OfType<IPermutationCreator>().Single(x => x.PermutationParameter.ActualName == intersect); 661 var newPermCreator = newCreator.Operators.OfType<IPermutationCreator>().Single(x => x.PermutationParameter.ActualName == intersect); 693 662 oldPermCreator.PermutationTypeParameter.Value = newPermCreator.PermutationTypeParameter.Value; 694 663 } 695 } else { 696 // we will use the new creator 697 foreach (var permCreator in solutionCreators.OfType<IPermutationCreator>()) { 698 newCreator.Operators.Add(permCreator); 699 } 700 } 701 #endregion 702 703 if (oldCreator == null) SolutionCreator = newCreator; 664 #endregion 665 666 } 704 667 705 668 // crossover and manipulator for multi-vector encoding 706 669 // the condition checks if a multi-vector encoding is to be updated (there already exists ParameterVectorCrossover and ParameterVectorManipulator) 707 if (Operators.OfType< ParameterVectorCrossover>().Any() && Operators.OfType<ParameterVectorManipulator>().Any()) {670 if (Operators.OfType<MultiEncodingCrossover>().Any() && Operators.OfType<MultiEncodingManipulator>().Any()) { 708 671 #region Update existing multi-vector encoding 709 672 #region Update ParameterVector Crossover ... 710 foreach (var oldXo in Operators.OfType< ParameterVectorCrossover>()) {673 foreach (var oldXo in Operators.OfType<MultiEncodingCrossover>()) { 711 674 #region ... for binary parameters 712 var oldBinParams = new HashSet<string>(oldXo.Operators.OfType<IBinaryVectorCrossover>() 713 .Select(x => x.ChildParameter.ActualName)); 675 var oldBinParams = new HashSet<string>(oldXo.Operators.OfType<IBinaryVectorCrossover>().Select(x => x.ChildParameter.ActualName)); 714 676 foreach (var toAdd in newBinParams.Except(oldBinParams)) 715 oldXo.Operators.Add(GetDefaultBinaryCrossover(toAdd, configuration));677 oldXo.Operators.Add(GetDefaultBinaryCrossover(toAdd, encoding)); 716 678 foreach (var toRemove in oldBinParams.Except(newBinParams)) { 717 var op = 718 oldXo.Operators.OfType<IBinaryVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove); 679 var op = oldXo.Operators.OfType<IBinaryVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove); 719 680 if (op != null) oldXo.Operators.Remove(op); 720 681 } 721 682 #endregion 722 683 #region ... for integer parameters 723 var oldIntParams = new HashSet<string>(oldXo.Operators.OfType<IIntegerVectorCrossover>() 724 .Select(x => x.ChildParameter.ActualName)); 684 var oldIntParams = new HashSet<string>(oldXo.Operators.OfType<IIntegerVectorCrossover>().Select(x => x.ChildParameter.ActualName)); 725 685 foreach (var toAdd in newIntParams.Except(oldIntParams)) 726 oldXo.Operators.Add(GetDefaultIntegerCrossover(toAdd, configuration));686 oldXo.Operators.Add(GetDefaultIntegerCrossover(toAdd, encoding)); 727 687 foreach (var toRemove in oldIntParams.Except(newIntParams)) { 728 var op = 729 oldXo.Operators.OfType<IIntegerVectorCrossover>() 730 .SingleOrDefault(x => x.ChildParameter.ActualName == toRemove); 688 var op = oldXo.Operators.OfType<IIntegerVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove); 731 689 if (op != null) oldXo.Operators.Remove(op); 732 690 } 733 691 #endregion 734 692 #region ... for real parameters 735 var oldRealParams = new HashSet<string>(oldXo.Operators.OfType<IRealVectorCrossover>() 736 .Select(x => x.ChildParameter.ActualName)); 693 var oldRealParams = new HashSet<string>(oldXo.Operators.OfType<IRealVectorCrossover>().Select(x => x.ChildParameter.ActualName)); 737 694 foreach (var toAdd in newRealParams.Except(oldRealParams)) 738 oldXo.Operators.Add(GetDefaultRealCrossover(toAdd, configuration));695 oldXo.Operators.Add(GetDefaultRealCrossover(toAdd, encoding)); 739 696 foreach (var toRemove in oldRealParams.Except(newRealParams)) { 740 var op = 741 oldXo.Operators.OfType<IRealVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove); 697 var op = oldXo.Operators.OfType<IRealVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove); 742 698 if (op != null) oldXo.Operators.Remove(op); 743 699 } 744 700 #endregion 745 701 #region ... for permutation parameters 746 var oldPermParams = new HashSet<string>(oldXo.Operators.OfType<IPermutationCrossover>() 747 .Select(x => x.ChildParameter.ActualName)); 702 var oldPermParams = new HashSet<string>(oldXo.Operators.OfType<IPermutationCrossover>().Select(x => x.ChildParameter.ActualName)); 748 703 foreach (var toAdd in newPermParams.Except(oldPermParams)) 749 oldXo.Operators.Add(GetDefaultPermutationCrossover(toAdd, configuration));704 oldXo.Operators.Add(GetDefaultPermutationCrossover(toAdd, encoding)); 750 705 foreach (var toRemove in oldPermParams.Except(newPermParams)) { 751 var op = 752 oldXo.Operators.OfType<IPermutationCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove); 706 var op = oldXo.Operators.OfType<IPermutationCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove); 753 707 if (op != null) oldXo.Operators.Remove(op); 754 708 } … … 757 711 #endregion 758 712 #region Update ParameterVector Manipulator ... 759 foreach (var oldM in Operators.OfType< ParameterVectorManipulator>()) {713 foreach (var oldM in Operators.OfType<MultiEncodingManipulator>()) { 760 714 #region ... for binary parameters 761 var oldBinParams = new HashSet<string>(oldM.Operators.OfType<IBinaryVectorManipulator>() 762 .Select(x => x.BinaryVectorParameter.ActualName)); 715 var oldBinParams = new HashSet<string>(oldM.Operators.OfType<IBinaryVectorManipulator>().Select(x => x.BinaryVectorParameter.ActualName)); 763 716 foreach (var toAdd in newBinParams.Except(oldBinParams)) 764 oldM.Operators.Add(GetDefaultBinaryManipulator(toAdd, configuration));717 oldM.Operators.Add(GetDefaultBinaryManipulator(toAdd, encoding)); 765 718 foreach (var toRemove in oldBinParams.Except(newBinParams)) { 766 var op = 767 oldM.Operators.OfType<IBinaryVectorManipulator>() 768 .SingleOrDefault(x => x.BinaryVectorParameter.ActualName == toRemove); 719 var op = oldM.Operators.OfType<IBinaryVectorManipulator>().SingleOrDefault(x => x.BinaryVectorParameter.ActualName == toRemove); 769 720 if (op != null) oldM.Operators.Remove(op); 770 721 } 771 722 #endregion 772 723 #region ... for integer parameters 773 var oldIntParams = new HashSet<string>(oldM.Operators.OfType<IIntegerVectorManipulator>() 774 .Select(x => x.IntegerVectorParameter.ActualName)); 724 var oldIntParams = new HashSet<string>(oldM.Operators.OfType<IIntegerVectorManipulator>().Select(x => x.IntegerVectorParameter.ActualName)); 775 725 foreach (var toAdd in newIntParams.Except(oldIntParams)) 776 oldM.Operators.Add(GetDefaultIntegerManipulator(toAdd, configuration));726 oldM.Operators.Add(GetDefaultIntegerManipulator(toAdd, encoding)); 777 727 foreach (var toRemove in oldIntParams.Except(newIntParams)) { 778 var op = 779 oldM.Operators.OfType<IIntegerVectorManipulator>() 780 .SingleOrDefault(x => x.IntegerVectorParameter.ActualName == toRemove); 728 var op = oldM.Operators.OfType<IIntegerVectorManipulator>().SingleOrDefault(x => x.IntegerVectorParameter.ActualName == toRemove); 781 729 if (op != null) oldM.Operators.Remove(op); 782 730 } 783 731 #endregion 784 732 #region ... for real parameters 785 var oldRealParams = new HashSet<string>(oldM.Operators.OfType<IRealVectorManipulator>() 786 .Select(x => x.RealVectorParameter.ActualName)); 733 var oldRealParams = new HashSet<string>(oldM.Operators.OfType<IRealVectorManipulator>().Select(x => x.RealVectorParameter.ActualName)); 787 734 foreach (var toAdd in newRealParams.Except(oldRealParams)) 788 oldM.Operators.Add(GetDefaultRealManipulator(toAdd, configuration));735 oldM.Operators.Add(GetDefaultRealManipulator(toAdd, encoding)); 789 736 foreach (var toRemove in oldRealParams.Except(newRealParams)) { 790 var op = 791 oldM.Operators.OfType<IRealVectorManipulator>() 792 .SingleOrDefault(x => x.RealVectorParameter.ActualName == toRemove); 737 var op = oldM.Operators.OfType<IRealVectorManipulator>().SingleOrDefault(x => x.RealVectorParameter.ActualName == toRemove); 793 738 if (op != null) oldM.Operators.Remove(op); 794 739 } 795 740 #endregion 796 741 #region ... for permutation parameters 797 var oldPermParams = new HashSet<string>(oldM.Operators.OfType<IPermutationManipulator>() 798 .Select(x => x.PermutationParameter.ActualName)); 742 var oldPermParams = new HashSet<string>(oldM.Operators.OfType<IPermutationManipulator>().Select(x => x.PermutationParameter.ActualName)); 799 743 foreach (var toAdd in newPermParams.Except(oldPermParams)) 800 oldM.Operators.Add(GetDefaultPermutationManipulator(toAdd, configuration));744 oldM.Operators.Add(GetDefaultPermutationManipulator(toAdd, encoding)); 801 745 foreach (var toRemove in oldPermParams.Except(newPermParams)) { 802 var op = 803 oldM.Operators.OfType<IPermutationManipulator>() 804 .SingleOrDefault(x => x.PermutationParameter.ActualName == toRemove); 746 var op = oldM.Operators.OfType<IPermutationManipulator>().SingleOrDefault(x => x.PermutationParameter.ActualName == toRemove); 805 747 if (op != null) oldM.Operators.Remove(op); 806 748 } … … 819 761 Operators.RemoveAll(x => x is IMultiNeighborhoodShakingOperator); 820 762 821 var crossover = new ParameterVectorCrossover();822 var manipulator = new ParameterVectorManipulator();823 foreach (var param in configuration.Parameters) {824 if ( param.Value is BinaryParameterConfiguration) {825 crossover.Operators.Add(GetDefaultBinaryCrossover( param.Key, configuration));826 manipulator.Operators.Add(GetDefaultBinaryManipulator( param.Key, configuration));763 var crossover = new MultiEncodingCrossover(); 764 var manipulator = new MultiEncodingManipulator(); 765 foreach (var enc in encoding.Encodings) { 766 if (enc is BinaryEncoding) { 767 crossover.Operators.Add(GetDefaultBinaryCrossover(enc.Name, encoding)); 768 manipulator.Operators.Add(GetDefaultBinaryManipulator(enc.Name, encoding)); 827 769 continue; 828 770 } 829 var intConfig = param.Value as IntegerParameterConfiguration;771 var intConfig = enc as IntegerEncoding; 830 772 if (intConfig != null) { 831 crossover.Operators.Add(GetDefaultIntegerCrossover( param.Key, configuration));832 manipulator.Operators.Add(GetDefaultIntegerManipulator( param.Key, configuration));773 crossover.Operators.Add(GetDefaultIntegerCrossover(enc.Name, encoding)); 774 manipulator.Operators.Add(GetDefaultIntegerManipulator(enc.Name, encoding)); 833 775 continue; 834 776 } 835 var realConfig = param.Value as RealParameterConfiguration;777 var realConfig = enc as RealEncoding; 836 778 if (realConfig != null) { 837 crossover.Operators.Add(GetDefaultRealCrossover( param.Key, configuration));838 manipulator.Operators.Add(GetDefaultRealManipulator( param.Key, configuration));779 crossover.Operators.Add(GetDefaultRealCrossover(enc.Name, encoding)); 780 manipulator.Operators.Add(GetDefaultRealManipulator(enc.Name, encoding)); 839 781 continue; 840 782 } 841 var permConfig = param.Value as PermutationParameterConfiguration;783 var permConfig = enc as PermutationEncoding; 842 784 if (permConfig != null) { 843 crossover.Operators.Add(GetDefaultPermutationCrossover( param.Key, configuration));844 manipulator.Operators.Add(GetDefaultPermutationManipulator( param.Key, configuration));785 crossover.Operators.Add(GetDefaultPermutationCrossover(enc.Name, encoding)); 786 manipulator.Operators.Add(GetDefaultPermutationManipulator(enc.Name, encoding)); 845 787 continue; 846 788 } 847 throw new InvalidOperationException("Unknown type for parameter " + param.Key);789 throw new InvalidOperationException("Unknown type for parameter " + enc.Name); 848 790 } 849 791 Operators.Add(crossover); … … 854 796 855 797 protected virtual void UpdateImprovementOperators() { 856 if (!Operators.Any(x => x is SingleObjective ParameterVectorImprover))857 Operators.Add(new SingleObjective ParameterVectorImprover());858 foreach (var improver in Operators.OfType<SingleObjective ParameterVectorImprover>()) {859 improver. ConfigurationParameter.ActualName = ConfigurationParameter.Name;798 if (!Operators.Any(x => x is SingleObjectiveImprover)) 799 Operators.Add(new SingleObjectiveImprover()); 800 foreach (var improver in Operators.OfType<SingleObjectiveImprover>()) { 801 improver.EncodingParameter.ActualName = EncodingParameter.Name; 860 802 improver.MaximizationParameter.ActualName = MaximizationParameter.Name; 861 803 improver.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; … … 865 807 866 808 protected virtual void UpdateMoveOperators() { 867 if (!Operators.Any(x => x is ParameterVectorMoveGenerator))868 Operators.Add(new ParameterVectorMoveGenerator());869 if (!Operators.Any(x => x is ParameterVectorMoveEvaluator))870 Operators.Add(new ParameterVectorMoveEvaluator());871 if (!Operators.Any(x => x is ParameterVectorMoveMaker))872 Operators.Add(new ParameterVectorMoveMaker());873 874 foreach (var generator in Operators.OfType< ParameterVectorMoveGenerator>()) {875 generator. ConfigurationParameter.ActualName = ConfigurationParameter.Name;809 if (!Operators.Any(x => x is SingleObjectiveMoveGenerator)) 810 Operators.Add(new SingleObjectiveMoveGenerator()); 811 if (!Operators.Any(x => x is SingleObjectiveMoveEvaluator)) 812 Operators.Add(new SingleObjectiveMoveEvaluator()); 813 if (!Operators.Any(x => x is SingleObjectiveMoveMaker)) 814 Operators.Add(new SingleObjectiveMoveMaker()); 815 816 foreach (var generator in Operators.OfType<SingleObjectiveMoveGenerator>()) { 817 generator.EncodingParameter.ActualName = EncodingParameter.Name; 876 818 generator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 877 819 } 878 foreach (var evaluator in Operators.OfType< ParameterVectorMoveEvaluator>()) {879 evaluator. ConfigurationParameter.ActualName = ConfigurationParameter.Name;820 foreach (var evaluator in Operators.OfType<SingleObjectiveMoveEvaluator>()) { 821 evaluator.EncodingParameter.ActualName = EncodingParameter.Name; 880 822 evaluator.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 881 823 evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 882 824 } 883 foreach (var maker in Operators.OfType< ParameterVectorMoveMaker>()) {884 maker. ConfigurationParameter.ActualName = ConfigurationParameter.Name;885 maker.MoveQualityParameter.ActualName = Operators.OfType< ParameterVectorMoveEvaluator>().First().MoveQualityParameter.ActualName;825 foreach (var maker in Operators.OfType<SingleObjectiveMoveMaker>()) { 826 maker.EncodingParameter.ActualName = EncodingParameter.Name; 827 maker.MoveQualityParameter.ActualName = Operators.OfType<SingleObjectiveMoveEvaluator>().First().MoveQualityParameter.ActualName; 886 828 maker.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 887 829 } … … 890 832 #region GetDefaultOperators for Crossovers and Manipulators 891 833 // ReSharper disable RedundantNameQualifier 892 protected virtual IBinaryVectorCrossover GetDefaultBinaryCrossover(string paramName, Configurationconfig) {893 var binConfig = (Binary ParameterConfiguration)config.Parameters[paramName];834 protected virtual IBinaryVectorCrossover GetDefaultBinaryCrossover(string paramName, MultiEncoding config) { 835 var binConfig = (BinaryEncoding)config.Encodings[paramName]; 894 836 IBinaryVectorCrossover binXo; 895 837 if (binConfig.Length.Value > 3) binXo = new Encodings.BinaryVectorEncoding.SinglePointCrossover(); … … 900 842 } 901 843 902 protected virtual IBinaryVectorManipulator GetDefaultBinaryManipulator(string paramName, Configurationconfig) {844 protected virtual IBinaryVectorManipulator GetDefaultBinaryManipulator(string paramName, MultiEncoding config) { 903 845 var binM = new Encodings.BinaryVectorEncoding.SomePositionsBitflipManipulator(); 904 846 binM.BinaryVectorParameter.ActualName = paramName; … … 907 849 } 908 850 909 protected virtual IIntegerVectorCrossover GetDefaultIntegerCrossover(string paramName, Configurationconfig) {851 protected virtual IIntegerVectorCrossover GetDefaultIntegerCrossover(string paramName, MultiEncoding config) { 910 852 var intXo = new Encodings.IntegerVectorEncoding.RoundedBlendAlphaBetaCrossover(); 911 853 intXo.ChildParameter.ActualName = paramName; … … 917 859 } 918 860 919 protected virtual IIntegerVectorManipulator GetDefaultIntegerManipulator(string paramName, Configurationconfiguration) {861 protected virtual IIntegerVectorManipulator GetDefaultIntegerManipulator(string paramName, MultiEncoding configuration) { 920 862 var intM = new Encodings.IntegerVectorEncoding.UniformSomePositionsManipulator(); 921 863 intM.IntegerVectorParameter.ActualName = paramName; … … 925 867 } 926 868 927 protected virtual IRealVectorCrossover GetDefaultRealCrossover(string paramName, Configurationconfiguration) {869 protected virtual IRealVectorCrossover GetDefaultRealCrossover(string paramName, MultiEncoding configuration) { 928 870 var realXo = new Encodings.RealVectorEncoding.BlendAlphaBetaCrossover(); 929 871 realXo.ChildParameter.ActualName = paramName; … … 935 877 } 936 878 937 protected virtual IRealVectorManipulator GetDefaultRealManipulator(string paramName, Configurationconfiguration) {879 protected virtual IRealVectorManipulator GetDefaultRealManipulator(string paramName, MultiEncoding configuration) { 938 880 var realM = new Encodings.RealVectorEncoding.BreederGeneticAlgorithmManipulator(); 939 881 realM.RealVectorParameter.ActualName = paramName; … … 942 884 } 943 885 944 protected virtual IPermutationCrossover GetDefaultPermutationCrossover(string paramName, Configurationconfiguration) {886 protected virtual IPermutationCrossover GetDefaultPermutationCrossover(string paramName, MultiEncoding configuration) { 945 887 var permXo = new Encodings.PermutationEncoding.PartiallyMatchedCrossover(); 946 888 permXo.ChildParameter.ActualName = paramName; … … 949 891 } 950 892 951 protected virtual IPermutationManipulator GetDefaultPermutationManipulator(string paramName, Configurationconfiguration) {893 protected virtual IPermutationManipulator GetDefaultPermutationManipulator(string paramName, MultiEncoding configuration) { 952 894 var permM = new Encodings.PermutationEncoding.Swap2Manipulator(); 953 895 permM.PermutationParameter.ActualName = paramName;
Note: See TracChangeset
for help on using the changeset viewer.