- Timestamp:
- 04/20/20 14:40:24 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/HeuristicOptimizationProblem.cs
r17226 r17513 21 21 22 22 using System; 23 using HEAL.Attic; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Parameters; 26 using HEAL.Attic;27 27 28 28 namespace HeuristicLab.Optimization { 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> : Problem, IHeuristicOptimizationProblem32 where T : class, IEvaluator33 where U : class, ISolutionCreator {31 public abstract class HeuristicOptimizationProblem<T, U> : EncodedProblem, IHeuristicOptimizationProblem 32 where T : class, IEvaluator 33 where U : class, ISolutionCreator { 34 34 private const string EvaluatorParameterName = "Evaluator"; 35 35 private const string SolutionCreateParameterName = "SolutionCreator"; -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/Problem.cs
r17334 r17513 31 31 32 32 namespace HeuristicLab.Optimization { 33 [StorableType("C213CE21-A970-4886-BC4C-9790B9897738")] 34 public abstract class Problem : ParameterizedNamedItem, IProblem { 35 public string Filename { get; set; } 36 37 public static new Image StaticItemImage { 38 get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; } 39 } 40 41 42 43 [StorableConstructor] 44 protected Problem(StorableConstructorFlag _) : base(_) { } 45 protected Problem(Problem original, Cloner cloner) : base(original, cloner) { } 46 public Problem() : base() { } 47 48 protected override IEnumerable<KeyValuePair<string, IItem>> GetCollectedValues(IValueParameter param) { 49 var children = base.GetCollectedValues(param); 50 foreach (var child in children) { 51 if (child.Value is IOperator) 52 yield return new KeyValuePair<string, IItem>(child.Key, new StringValue(((IOperator)child.Value).Name)); 53 else yield return child; 54 } 55 } 56 57 public event EventHandler Reset; 58 protected virtual void OnReset() { 59 EventHandler handler = Reset; 60 if (handler != null) 61 handler(this, EventArgs.Empty); 62 } 63 } 64 65 66 33 67 [Item("Problem", "Represents the base class for a problem.")] 34 68 [StorableType("6DC97432-9BD1-4304-802A-1FC48A0E0468")] 35 public abstract class Problem : ParameterizedNamedItem, IProblem { 36 public string Filename { get; set; } 69 public abstract class EncodedProblem : Problem, IEncodedProblem { 37 70 38 71 private const string OperatorsParameterName = "Operators"; … … 41 74 } 42 75 43 public static new Image StaticItemImage {44 get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; }45 }46 47 76 [StorableConstructor] 48 protected Problem(StorableConstructorFlag _) : base(_) { }49 protected Problem(Problem original, Cloner cloner)77 protected EncodedProblem(StorableConstructorFlag _) : base(_) { } 78 protected EncodedProblem(EncodedProblem original, Cloner cloner) 50 79 : base(original, cloner) { 51 80 RegisterEventHandlers(); 52 81 } 53 82 54 protected Problem()83 protected EncodedProblem() 55 84 : base() { 56 85 Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>()) { GetsCollected = false }); … … 116 145 } 117 146 } 118 IEnumerable<IItem> I Problem.Operators { get { return GetOperators(); } }147 IEnumerable<IItem> IEncodedProblem.Operators { get { return GetOperators(); } } 119 148 120 149 protected virtual IEnumerable<IItem> GetOperators() { … … 127 156 #endregion 128 157 129 protected override IEnumerable<KeyValuePair<string, IItem>> GetCollectedValues(IValueParameter param) { 130 var children = base.GetCollectedValues(param); 131 foreach (var child in children) { 132 if (child.Value is IOperator) 133 yield return new KeyValuePair<string, IItem>(child.Key, new StringValue(((IOperator)child.Value).Name)); 134 else yield return child; 135 } 136 } 158 137 159 138 160 #region events … … 146 168 handler(this, EventArgs.Empty); 147 169 } 148 149 public event EventHandler Reset;150 protected virtual void OnReset() {151 EventHandler handler = Reset;152 if (handler != null)153 handler(this, EventArgs.Empty);154 }155 170 #endregion 156 171 }
Note: See TracChangeset
for help on using the changeset viewer.