Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/20/20 14:40:24 (5 years ago)
Author:
mkommend
Message:

#2521: Splitted problems into several problem and encoded problems.

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  
    2121
    2222using System;
     23using HEAL.Attic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Parameters;
    26 using HEAL.Attic;
    2727
    2828namespace HeuristicLab.Optimization {
    2929  [Item("Heuristic Optimization Problem", "Represents the base class for a heuristic optimization problem.")]
    3030  [StorableType("DE0478BA-3797-4AC3-9A89-3734D2643823")]
    31   public abstract class HeuristicOptimizationProblem<T, U> : Problem, IHeuristicOptimizationProblem
    32     where T : class,IEvaluator
    33     where U : class,ISolutionCreator {
     31  public abstract class HeuristicOptimizationProblem<T, U> : EncodedProblem, IHeuristicOptimizationProblem
     32    where T : class, IEvaluator
     33    where U : class, ISolutionCreator {
    3434    private const string EvaluatorParameterName = "Evaluator";
    3535    private const string SolutionCreateParameterName = "SolutionCreator";
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/Problem.cs

    r17334 r17513  
    3131
    3232namespace 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
    3367  [Item("Problem", "Represents the base class for a problem.")]
    3468  [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 {
    3770
    3871    private const string OperatorsParameterName = "Operators";
     
    4174    }
    4275
    43     public static new Image StaticItemImage {
    44       get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; }
    45     }
    46 
    4776    [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)
    5079      : base(original, cloner) {
    5180      RegisterEventHandlers();
    5281    }
    5382
    54     protected Problem()
     83    protected EncodedProblem()
    5584      : base() {
    5685      Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>()) { GetsCollected = false });
     
    116145      }
    117146    }
    118     IEnumerable<IItem> IProblem.Operators { get { return GetOperators(); } }
     147    IEnumerable<IItem> IEncodedProblem.Operators { get { return GetOperators(); } }
    119148
    120149    protected virtual IEnumerable<IItem> GetOperators() {
     
    127156    #endregion
    128157
    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
    137159
    138160    #region events
     
    146168        handler(this, EventArgs.Empty);
    147169    }
    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     }
    155170    #endregion
    156171  }
Note: See TracChangeset for help on using the changeset viewer.