Changeset 16801 for branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators
- Timestamp:
- 04/17/19 16:03:57 (6 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring
- Property svn:mergeinfo changed
/trunk merged: 16729,16737,16740,16743,16757-16758,16762-16764,16768-16769,16779,16782-16784,16788,16792,16794-16799
- Property svn:mergeinfo changed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Optimization merged: 16782,16784,16794,16796
- Property svn:mergeinfo changed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingCreator.cs
r16753 r16801 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 internal sealed class MultiEncodingCreator : MultiEncodingOperator<ISolutionCreator>, ISolutionCreator<CombinedSolution> { 32 internal sealed class MultiEncodingCreator : MultiEncodingOperator<ISolutionCreator>, ISolutionCreator<CombinedSolution>, IStochasticOperator { 33 public ILookupParameter<IRandom> RandomParameter { 34 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 35 } 36 37 public override string OperatorPrefix => "Creator"; 32 38 33 39 [StorableConstructor] 34 40 private MultiEncodingCreator(StorableConstructorFlag _) : base(_) { } 35 41 private MultiEncodingCreator(MultiEncodingCreator original, Cloner cloner) : base(original, cloner) { } 36 public MultiEncodingCreator() : base() { } 42 public MultiEncodingCreator() : base(){ 43 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators.")); 44 } 37 45 38 46 public override IDeepCloneable Clone(Cloner cloner) { 39 47 return new MultiEncodingCreator(this, cloner); 48 } 49 50 [StorableHook(HookType.AfterDeserialization)] 51 private void AfterDeserialization() { 52 if (!Parameters.ContainsKey("Random")) { 53 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators.")); 54 } 40 55 } 41 56 -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingCrossover.cs
r16753 r16801 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 internal sealed class MultiEncodingCrossover : MultiEncodingOperator<ICrossover>, ICrossover { 30 internal 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"; 30 36 31 37 [StorableConstructor] 32 38 private MultiEncodingCrossover(StorableConstructorFlag _) : base(_) { } 33 39 private MultiEncodingCrossover(MultiEncodingCrossover original, Cloner cloner) : base(original, cloner) { } 34 public MultiEncodingCrossover() : base() { } 40 public MultiEncodingCrossover() : base() { 41 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator used by the individual operators.")); 42 } 35 43 36 44 public override IDeepCloneable Clone(Cloner cloner) { return new MultiEncodingCrossover(this, cloner); } 37 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 } 38 52 39 53 public override IOperation InstrumentedApply() { -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingManipulator.cs
r16753 r16801 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Parameters; 25 26 26 27 namespace HeuristicLab.Optimization { … … 28 29 [StorableType("574D0530-47E8-4FD9-8AC8-B8EA2DE3C203")] 29 30 internal sealed class MultiEncodingManipulator : MultiEncodingOperator<IManipulator>, IManipulator { 31 public ILookupParameter<IRandom> RandomParameter { 32 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 33 } 34 35 public override string OperatorPrefix => "Manipulator"; 30 36 [StorableConstructor] 31 37 private MultiEncodingManipulator(StorableConstructorFlag _) : base(_) { } 32 38 private MultiEncodingManipulator(MultiEncodingManipulator original, Cloner cloner) : base(original, cloner) { } 33 public MultiEncodingManipulator() : base() { } 39 40 public MultiEncodingManipulator() : base() { 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 MultiEncodingManipulator(this, cloner); } 36 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 } 52 37 53 } 38 54 } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingOperator.cs
r16753 r16801 22 22 using System; 23 23 using System.Linq; 24 using HEAL.Attic; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Operators; 27 28 using HeuristicLab.Parameters; 28 using HEAL.Attic;29 29 30 30 namespace HeuristicLab.Optimization { … … 39 39 } 40 40 41 public abstract string OperatorPrefix { get; } 42 41 43 [StorableConstructor] 42 44 protected MultiEncodingOperator(StorableConstructorFlag _) : base(_) { } … … 49 51 50 52 public override IOperation InstrumentedApply() { 51 var operations = Parameters.Select(p => p.ActualValue).OfType<IOperator>().Select(op => ExecutionContext.Create Operation(op));53 var operations = Parameters.Select(p => p.ActualValue).OfType<IOperator>().Select(op => ExecutionContext.CreateChildOperation(op)); 52 54 return new OperationCollection(operations); 53 55 } 54 56 55 57 public virtual void AddEncoding(IEncoding encoding) { 56 if (Parameters.ContainsKey( encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was already added.", encoding.Name));58 if (Parameters.ContainsKey(OperatorPrefix + "." + encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was already added.", encoding.Name)); 57 59 58 60 encoding.OperatorsChanged += Encoding_OperatorsChanged; 59 61 60 var param = new ConstrainedValueParameter<T>( encoding.Name, new ItemSet<T>(encoding.Operators.OfType<T>()));62 var param = new ConstrainedValueParameter<T>(OperatorPrefix + "." + encoding.Name, new ItemSet<T>(encoding.Operators.OfType<T>())); 61 63 param.Value = param.ValidValues.First(); 62 64 Parameters.Add(param); … … 66 68 if (!Parameters.ContainsKey(encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was not added to the MultiEncoding.", encoding.Name)); 67 69 encoding.OperatorsChanged -= Encoding_OperatorsChanged; 68 return Parameters.Remove( encoding.Name);70 return Parameters.Remove(OperatorPrefix + "." + encoding.Name); 69 71 } 70 72 71 73 protected IConstrainedValueParameter<T> GetParameter(IEncoding encoding) { 72 if (!Parameters.ContainsKey( encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was not added to the MultiEncoding.", encoding.Name));74 if (!Parameters.ContainsKey(OperatorPrefix + "." + encoding.Name)) throw new ArgumentException(string.Format("Encoding {0} was not added to the MultiEncoding.", encoding.Name)); 73 75 74 return (IConstrainedValueParameter<T>)Parameters[ encoding.Name];76 return (IConstrainedValueParameter<T>)Parameters[OperatorPrefix + "." + encoding.Name]; 75 77 } 76 78
Note: See TracChangeset
for help on using the changeset viewer.