- Timestamp:
- 07/23/20 16:21:55 (4 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/HeuristicOptimizationProblem.cs
r17513 r17695 29 29 [Item("Heuristic Optimization Problem", "Represents the base class for a heuristic optimization problem.")] 30 30 [StorableType("DE0478BA-3797-4AC3-9A89-3734D2643823")] 31 public abstract class HeuristicOptimizationProblem<T, U> : EncodedProblem, IHeuristicOptimizationProblem 32 where T : class, IEvaluator 33 where U : class, ISolutionCreator { 31 public abstract class HeuristicOptimizationProblem<T> : EncodedProblem, IHeuristicOptimizationProblem 32 where T : class, IEvaluator { 34 33 private const string EvaluatorParameterName = "Evaluator"; 35 private const string SolutionCreateParameterName = "SolutionCreator";36 34 37 35 [StorableConstructor] 38 36 protected HeuristicOptimizationProblem(StorableConstructorFlag _) : base(_) { } 39 protected HeuristicOptimizationProblem(HeuristicOptimizationProblem<T , U> original, Cloner cloner)37 protected HeuristicOptimizationProblem(HeuristicOptimizationProblem<T> original, Cloner cloner) 40 38 : base(original, cloner) { 41 39 RegisterEventHandlers(); … … 45 43 : base() { 46 44 Parameters.Add(new ValueParameter<T>(EvaluatorParameterName, "The operator used to evaluate a solution.")); 47 Parameters.Add(new ValueParameter<U>(SolutionCreateParameterName, "The operator to create a solution."));48 45 RegisterEventHandlers(); 49 46 } 50 47 51 protected HeuristicOptimizationProblem(T evaluator , U solutionCreator)48 protected HeuristicOptimizationProblem(T evaluator) 52 49 : base() { 53 50 Parameters.Add(new ValueParameter<T>(EvaluatorParameterName, "The operator used to evaluate a solution.", evaluator)); 54 Parameters.Add(new ValueParameter<U>(SolutionCreateParameterName, "The operator to create a solution.", solutionCreator));55 51 RegisterEventHandlers(); 56 52 } … … 63 59 private void RegisterEventHandlers() { 64 60 EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged); 65 SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);66 61 } 67 62 … … 76 71 IEvaluator IHeuristicOptimizationProblem.Evaluator { get { return Evaluator; } } 77 72 IParameter IHeuristicOptimizationProblem.EvaluatorParameter { get { return EvaluatorParameter; } } 78 79 public U SolutionCreator {80 get { return (U)SolutionCreatorParameter.Value; }81 protected set { SolutionCreatorParameter.Value = value; }82 }83 public IValueParameter SolutionCreatorParameter {84 get { return (IValueParameter)Parameters[SolutionCreateParameterName]; }85 }86 ISolutionCreator IHeuristicOptimizationProblem.SolutionCreator { get { return SolutionCreator; } }87 IParameter IHeuristicOptimizationProblem.SolutionCreatorParameter { get { return SolutionCreatorParameter; } }88 73 #endregion 89 74 … … 98 83 handler(this, EventArgs.Empty); 99 84 } 100 101 private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {102 OnSolutionCreatorChanged();103 }104 public event EventHandler SolutionCreatorChanged;105 protected virtual void OnSolutionCreatorChanged() {106 EventHandler handler = SolutionCreatorChanged;107 if (handler != null)108 handler(this, EventArgs.Empty);109 }110 85 #endregion 111 86 } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/MultiObjectiveHeuristicOptimizationProblem.cs
r17317 r17695 30 30 [Item("Multi-Objective Heuristic Optimization Problem", "A base class for multi-objective heuristic optimization problems.")] 31 31 [StorableType("C46643E3-7144-4884-A30A-5329BD80DC4E")] 32 public abstract class MultiObjectiveHeuristicOptimizationProblem<T, U> : HeuristicOptimizationProblem<T, U>, IMultiObjectiveHeuristicOptimizationProblem 33 where T : class, IMultiObjectiveEvaluator 34 where U : class, ISolutionCreator { 32 public abstract class MultiObjectiveHeuristicOptimizationProblem<T> : HeuristicOptimizationProblem<T>, IMultiObjectiveHeuristicOptimizationProblem 33 where T : class, IMultiObjectiveEvaluator { 35 34 private const string MaximizationParameterName = "Maximization"; 36 35 37 36 [StorableConstructor] 38 37 protected MultiObjectiveHeuristicOptimizationProblem(StorableConstructorFlag _) : base(_) { } 39 protected MultiObjectiveHeuristicOptimizationProblem(MultiObjectiveHeuristicOptimizationProblem<T , U> original, Cloner cloner)38 protected MultiObjectiveHeuristicOptimizationProblem(MultiObjectiveHeuristicOptimizationProblem<T> original, Cloner cloner) 40 39 : base(original, cloner) { 41 40 RegisterEventHandlers(); … … 48 47 } 49 48 50 protected MultiObjectiveHeuristicOptimizationProblem(T evaluator , U solutionCreator)51 : base(evaluator , solutionCreator) {49 protected MultiObjectiveHeuristicOptimizationProblem(T evaluator) 50 : base(evaluator) { 52 51 Parameters.Add(new ValueParameter<BoolArray>(MaximizationParameterName, "Determines for each objective whether it should be maximized or minimized.")); 53 52 -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs
r17317 r17695 30 30 [Item("Single-Objective Heuristic OptimizationProblem", "A base class for single-objective heuristic optimization problems.")] 31 31 [StorableType("DFD5588E-6AB2-4712-9083-A405EF21226F")] 32 public abstract class SingleObjectiveHeuristicOptimizationProblem<T, U> : HeuristicOptimizationProblem<T, U>, ISingleObjectiveHeuristicOptimizationProblem 33 where T : class, ISingleObjectiveEvaluator 34 where U : class, ISolutionCreator { 32 public abstract class SingleObjectiveHeuristicOptimizationProblem<T> : HeuristicOptimizationProblem<T>, ISingleObjectiveHeuristicOptimizationProblem 33 where T : class, ISingleObjectiveEvaluator { 35 34 private const string MaximizationParameterName = "Maximization"; 36 35 private const string BestKnownQualityParameterName = "BestKnownQuality"; … … 38 37 [StorableConstructor] 39 38 protected SingleObjectiveHeuristicOptimizationProblem(StorableConstructorFlag _) : base(_) { } 40 protected SingleObjectiveHeuristicOptimizationProblem(SingleObjectiveHeuristicOptimizationProblem<T , U> original, Cloner cloner)39 protected SingleObjectiveHeuristicOptimizationProblem(SingleObjectiveHeuristicOptimizationProblem<T> original, Cloner cloner) 41 40 : base(original, cloner) { 42 41 RegisterEventHandlers(); … … 50 49 } 51 50 52 protected SingleObjectiveHeuristicOptimizationProblem(T evaluator , U solutionCreator)53 : base(evaluator , solutionCreator) {51 protected SingleObjectiveHeuristicOptimizationProblem(T evaluator) 52 : base(evaluator) { 54 53 Parameters.Add(new ValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized.", new BoolValue())); 55 54 Parameters.Add(new OptionalValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem.")); -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/UserDefinedProblem.cs
r17612 r17695 62 62 get { return MaximizationParameter; } 63 63 } 64 public ValueParameter<ISolutionCreator> SolutionCreatorParameter {65 get { return (ValueParameter<ISolutionCreator>)Parameters["SolutionCreator"]; }66 }67 IParameter IHeuristicOptimizationProblem.SolutionCreatorParameter {68 get { return SolutionCreatorParameter; }69 }70 64 IParameter IHeuristicOptimizationProblem.EvaluatorParameter { 71 65 get { return EvaluatorParameter; } … … 89 83 get { return MaximizationParameter.Value; } 90 84 set { MaximizationParameter.Value = value; } 91 }92 public ISolutionCreator SolutionCreator {93 get { return SolutionCreatorParameter.Value; }94 set { SolutionCreatorParameter.Value = value; }95 }96 ISolutionCreator IHeuristicOptimizationProblem.SolutionCreator {97 get { return SolutionCreatorParameter.Value; }98 85 } 99 86 public ISingleObjectiveEvaluator Evaluator { … … 138 125 : base() { 139 126 Parameters.Add(new ValueParameter<ISingleObjectiveEvaluator>("Evaluator", "The evaluator that collects the values to exchange.", new EmptyUserDefinedProblemEvaluator())); 140 Parameters.Add(new ValueParameter<ISolutionCreator>("SolutionCreator", "An operator to create the solution components."));141 127 Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as most test functions are minimization problems.", new BoolValue(false))); 142 128 Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem.")); … … 156 142 157 143 #region Events 158 public event EventHandler SolutionCreatorChanged;159 private void OnSolutionCreatorChanged() {160 EventHandler handler = SolutionCreatorChanged;161 if (handler != null) handler(this, EventArgs.Empty);162 }163 144 public event EventHandler EvaluatorChanged; 164 145 private void OnEvaluatorChanged() { … … 174 155 175 156 #region Event handlers 176 private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {177 OnSolutionCreatorChanged();178 }179 157 private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) { 180 158 if (Evaluator != null) … … 202 180 #region Helpers 203 181 private void RegisterEventHandlers() { 204 SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);205 182 EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged); 206 183 if (Evaluator != null)
Note: See TracChangeset
for help on using the changeset viewer.