- Timestamp:
- 04/15/19 14:13:13 (5 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs
r16565 r16782 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Analysis; 26 27 using HeuristicLab.Collections; … … 32 33 using HeuristicLab.Optimization.Operators; 33 34 using HeuristicLab.Parameters; 34 using HEAL.Attic;35 35 using HeuristicLab.PluginInfrastructure; 36 36 using HeuristicLab.Random; … … 501 501 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { 502 502 base.Problem_OperatorsChanged(sender, e); 503 foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op); 503 504 ParameterizeIterationBasedOperators(); 504 505 UpdateCrossovers(); -
trunk/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingCreator.cs
r16565 r16782 22 22 using System; 23 23 using System.Linq; 24 using HEAL.Attic; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 using H EAL.Attic;27 using HeuristicLab.Parameters; 27 28 28 29 namespace HeuristicLab.Optimization { 29 30 [Item("MultiEncodingCreator", "Contains solution creators that together create a multi-encoding.")] 30 31 [StorableType("E261B506-6F74-4BC4-8164-5ACE20FBC319")] 31 public sealed class MultiEncodingCreator : MultiEncodingOperator<ISolutionCreator>, ISolutionCreator { 32 public sealed class MultiEncodingCreator : MultiEncodingOperator<ISolutionCreator>, ISolutionCreator, IStochasticOperator { 33 public ILookupParameter<IRandom> RandomParameter { 34 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 35 } 36 37 public override string OperatorPrefix => "Creator"; 38 32 39 [StorableConstructor] 33 40 private MultiEncodingCreator(StorableConstructorFlag _) : base(_) { } 34 41 35 42 private MultiEncodingCreator(MultiEncodingCreator original, Cloner cloner) : base(original, cloner) { } 36 public MultiEncodingCreator() { } 43 public MultiEncodingCreator() { 44 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators.")); 45 } 37 46 38 47 public override IDeepCloneable Clone(Cloner cloner) { 39 48 return new MultiEncodingCreator(this, cloner); 49 } 50 51 [StorableHook(HookType.AfterDeserialization)] 52 private void AfterDeserialization() { 53 if (!Parameters.ContainsKey("Random")) { 54 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators.")); 55 } 40 56 } 41 57 -
trunk/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingCrossover.cs
r16565 r16782 20 20 #endregion 21 21 22 using HEAL.Attic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 using H EAL.Attic;25 using HeuristicLab.Parameters; 25 26 26 27 namespace HeuristicLab.Optimization { 27 28 [Item("MultiEncoding Crossover", "Applies different crossovers to cross a multi-encoding.")] 28 29 [StorableType("BB0A04E2-899D-460C-82A2-5E4CEEDE8996")] 29 public sealed class MultiEncodingCrossover : MultiEncodingOperator<ICrossover>, ICrossover { 30 public sealed class MultiEncodingCrossover : MultiEncodingOperator<ICrossover>, ICrossover, IStochasticOperator { 31 public ILookupParameter<IRandom> RandomParameter { 32 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 33 } 34 35 public override string OperatorPrefix => "Crossover"; 36 30 37 [StorableConstructor] 31 38 private MultiEncodingCrossover(StorableConstructorFlag _) : base(_) { } 32 39 private MultiEncodingCrossover(MultiEncodingCrossover original, Cloner cloner) : base(original, cloner) { } 33 public MultiEncodingCrossover() { } 40 public MultiEncodingCrossover() { 41 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators.")); 42 } 34 43 35 44 public override IDeepCloneable Clone(Cloner cloner) { return new MultiEncodingCrossover(this, cloner); } 45 46 [StorableHook(HookType.AfterDeserialization)] 47 private void AfterDeserialization() { 48 if (!Parameters.ContainsKey("Random")) { 49 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators.")); 50 } 51 } 36 52 } 37 53 } -
trunk/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingManipulator.cs
r16565 r16782 20 20 #endregion 21 21 22 using HEAL.Attic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 using H EAL.Attic;25 using HeuristicLab.Parameters; 25 26 26 27 namespace HeuristicLab.Optimization { 27 28 [Item("MultiEncoding Manipulator", "Applies different manipulators to change a multi-encoding.")] 28 29 [StorableType("574D0530-47E8-4FD9-8AC8-B8EA2DE3C203")] 29 public sealed class MultiEncodingManipulator : MultiEncodingOperator<IManipulator>, IManipulator { 30 public sealed class MultiEncodingManipulator : MultiEncodingOperator<IManipulator>, IManipulator, IStochasticOperator { 31 public ILookupParameter<IRandom> RandomParameter { 32 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 33 } 34 35 public override string OperatorPrefix => "Manipulator"; 36 30 37 [StorableConstructor] 31 38 private MultiEncodingManipulator(StorableConstructorFlag _) : base(_) { } 32 39 private MultiEncodingManipulator(MultiEncodingManipulator original, Cloner cloner) 33 40 : base(original, cloner) { } 34 public MultiEncodingManipulator() { } 41 public MultiEncodingManipulator() { 42 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators.")); 43 } 35 44 36 45 public override IDeepCloneable Clone(Cloner cloner) { return new MultiEncodingManipulator(this, cloner); } 37 46 47 [StorableHook(HookType.AfterDeserialization)] 48 private void AfterDeserialization() { 49 if (!Parameters.ContainsKey("Random")) { 50 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators.")); 51 } 52 } 53 38 54 } 39 55 } -
trunk/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingOperator.cs
r16565 r16782 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Operators; 28 29 using HeuristicLab.Parameters; 29 using HEAL.Attic;30 30 31 31 namespace HeuristicLab.Optimization { … … 39 39 } 40 40 41 public abstract string OperatorPrefix { get; } 42 41 43 [StorableConstructor] 42 protected MultiEncodingOperator(StorableConstructorFlag _) : base(_) { 43 } 44 44 protected MultiEncodingOperator(StorableConstructorFlag _) : base(_) { } 45 45 protected MultiEncodingOperator(MultiEncodingOperator<T> original, Cloner cloner) 46 46 : base(original, cloner) { … … 49 49 encoding.OperatorsChanged += Encoding_OperatorsChanged; 50 50 } 51 52 51 protected MultiEncodingOperator() : base() { } 53 52 54 53 [StorableHook(HookType.AfterDeserialization)] 55 54 private void AfterDeserialization() { 56 foreach (var encoding in encodings) 55 foreach (var encoding in encodings) { 56 // BackwardsCompatibility3.3 57 #region Backwards compatible code, remove with 3.4 58 if (Parameters.ContainsKey(encoding.Name) && !Parameters.ContainsKey(OperatorPrefix + "." + encoding.Name)) { 59 var oldParam = (IConstrainedValueParameter<T>)Parameters[encoding.Name]; 60 var selected = oldParam.Value; 61 Parameters.Remove(oldParam); 62 var newParam = new ConstrainedValueParameter<T>(OperatorPrefix + "." + encoding.Name, new ItemSet<T>(oldParam.ValidValues)); 63 newParam.Value = selected; 64 Parameters.Add(newParam); 65 oldParam.ValidValues.Clear(); 66 } 67 #endregion 57 68 encoding.OperatorsChanged += Encoding_OperatorsChanged; 69 } 58 70 } 59 71 60 61 72 public override IOperation Apply() { 62 var operations = Parameters.Select(p => p.ActualValue).OfType<IOperator>().Select(op => ExecutionContext.Create Operation(op));73 var operations = Parameters.Select(p => p.ActualValue).OfType<IOperator>().Select(op => ExecutionContext.CreateChildOperation(op)); 63 74 return new OperationCollection(operations); 64 75 } 65 76 66 77 public virtual void AddEncoding(IEncoding encoding) { 67 if (Parameters.ContainsKey( encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was already added.", encoding.Name));78 if (Parameters.ContainsKey(OperatorPrefix + "." + encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was already added.", encoding.Name)); 68 79 69 80 encodings.Add(encoding); 70 81 encoding.OperatorsChanged += Encoding_OperatorsChanged; 71 82 72 var param = new ConstrainedValueParameter<T>( encoding.Name, new ItemSet<T>(encoding.Operators.OfType<T>()));83 var param = new ConstrainedValueParameter<T>(OperatorPrefix + "." + encoding.Name, new ItemSet<T>(encoding.Operators.OfType<T>())); 73 84 param.Value = param.ValidValues.First(); 74 85 Parameters.Add(param); … … 78 89 if (!encodings.Remove(encoding)) throw new ArgumentException(string.Format("Encoding {0} was not added to the MultiEncoding.", encoding.Name)); 79 90 encoding.OperatorsChanged -= Encoding_OperatorsChanged; 80 return Parameters.Remove( encoding.Name);91 return Parameters.Remove(OperatorPrefix + "." + encoding.Name); 81 92 } 82 93 83 94 protected IConstrainedValueParameter<T> GetParameter(IEncoding encoding) { 84 if (!Parameters.ContainsKey( encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was not added to the MultiEncoding.", encoding.Name));95 if (!Parameters.ContainsKey(OperatorPrefix + "." + encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was not added to the MultiEncoding.", encoding.Name)); 85 96 86 return (IConstrainedValueParameter<T>)Parameters[ encoding.Name];97 return (IConstrainedValueParameter<T>)Parameters[OperatorPrefix + "." + encoding.Name]; 87 98 } 88 99
Note: See TracChangeset
for help on using the changeset viewer.