- Timestamp:
- 07/23/20 16:21:55 (4 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Algorithms
- Files:
-
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Algorithms/HeuristicOptimizationEngineAlgorithm.cs
r17226 r17695 21 21 22 22 using System; 23 using HEAL.Attic; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 using H EAL.Attic;26 using HeuristicLab.Parameters; 26 27 27 28 namespace HeuristicLab.Optimization { … … 37 38 } 38 39 39 protected HeuristicOptimizationEngineAlgorithm() : base() { } 40 protected HeuristicOptimizationEngineAlgorithm(string name) : base(name) { } 41 protected HeuristicOptimizationEngineAlgorithm(string name, ParameterCollection parameters) : base(name, parameters) { } 42 protected HeuristicOptimizationEngineAlgorithm(string name, string description) : base(name, description) { } 43 protected HeuristicOptimizationEngineAlgorithm(string name, string description, ParameterCollection parameters) : base(name, description, parameters) { } 40 [Storable] public IConstrainedValueParameter<ISolutionCreator> SolutionCreatorParameter { get; private set; } 41 public ISolutionCreator SolutionCreator { 42 get => SolutionCreatorParameter.Value; 43 set { 44 if (!SolutionCreatorParameter.ValidValues.Contains(value)) 45 SolutionCreatorParameter.ValidValues.Add(value); 46 SolutionCreatorParameter.Value = value; 47 } 48 } 49 50 protected HeuristicOptimizationEngineAlgorithm() : base() { 51 Parameters.Add(SolutionCreatorParameter = new ConstrainedValueParameter<ISolutionCreator>("SolutionCreator", "An operator that creates a solution for a given problem.")); 52 53 RegisterEventHandlers(); 54 } 55 protected HeuristicOptimizationEngineAlgorithm(string name) : base(name) { 56 Parameters.Add(SolutionCreatorParameter = new ConstrainedValueParameter<ISolutionCreator>("SolutionCreator", "An operator that creates a solution for a given problem.")); 57 58 RegisterEventHandlers(); 59 } 60 protected HeuristicOptimizationEngineAlgorithm(string name, ParameterCollection parameters) : base(name, parameters) { 61 Parameters.Add(SolutionCreatorParameter = new ConstrainedValueParameter<ISolutionCreator>("SolutionCreator", "An operator that creates a solution for a given problem.")); 62 63 RegisterEventHandlers(); 64 } 65 protected HeuristicOptimizationEngineAlgorithm(string name, string description) : base(name, description) { 66 Parameters.Add(SolutionCreatorParameter = new ConstrainedValueParameter<ISolutionCreator>("SolutionCreator", "An operator that creates a solution for a given problem.")); 67 68 RegisterEventHandlers(); 69 } 70 protected HeuristicOptimizationEngineAlgorithm(string name, string description, ParameterCollection parameters) : base(name, description, parameters) { 71 Parameters.Add(SolutionCreatorParameter = new ConstrainedValueParameter<ISolutionCreator>("SolutionCreator", "An operator that creates a solution for a given problem.")); 72 73 RegisterEventHandlers(); 74 } 44 75 45 76 [StorableConstructor] 46 77 protected HeuristicOptimizationEngineAlgorithm(StorableConstructorFlag _) : base(_) { } 47 protected HeuristicOptimizationEngineAlgorithm(HeuristicOptimizationEngineAlgorithm original, Cloner cloner) : base(original, cloner) { } 78 protected HeuristicOptimizationEngineAlgorithm(HeuristicOptimizationEngineAlgorithm original, Cloner cloner) : base(original, cloner) { 79 SolutionCreatorParameter = cloner.Clone(original.SolutionCreatorParameter); 80 81 RegisterEventHandlers(); 82 } 83 84 [StorableHook(HookType.AfterDeserialization)] 85 private void AfterDeserialization() { 86 RegisterEventHandlers(); 87 } 48 88 49 89 #region Events 90 private void RegisterEventHandlers() { 91 ParameterChangeHandler<ISolutionCreator>.Create(SolutionCreatorParameter, SolutionCreatorOnChanged); 92 } 50 93 protected override void DeregisterProblemEvents() { 51 Problem.SolutionCreatorChanged -= new EventHandler(Problem_SolutionCreatorChanged); 52 Problem.EvaluatorChanged -= new EventHandler(Problem_EvaluatorChanged); 94 Problem.EvaluatorChanged -= Problem_EvaluatorChanged; 53 95 base.DeregisterProblemEvents(); 54 96 } 55 97 protected override void RegisterProblemEvents() { 56 98 base.RegisterProblemEvents(); 57 Problem.SolutionCreatorChanged += new EventHandler(Problem_SolutionCreatorChanged); 58 Problem.EvaluatorChanged += new EventHandler(Problem_EvaluatorChanged); 99 Problem.EvaluatorChanged += Problem_EvaluatorChanged; 100 } 101 protected override void OnProblemChanged() { 102 base.OnProblemChanged(); 103 SolutionCreatorParameter.Repopulate(Problem.Operators); 59 104 } 60 105 61 protected virtual void Problem_SolutionCreatorChanged(object sender, EventArgs e) { }106 protected virtual void SolutionCreatorOnChanged() { } 62 107 protected virtual void Problem_EvaluatorChanged(object sender, EventArgs e) { } 108 109 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { 110 base.Problem_OperatorsChanged(sender, e); 111 SolutionCreatorParameter.Repopulate(Problem.Operators); 112 } 63 113 #endregion 64 114 }
Note: See TracChangeset
for help on using the changeset viewer.