Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/19/20 17:53:36 (4 years ago)
Author:
abeham
Message:

#2521: work in progress (removed solution creator parameter from encoding), OrienteeringProblem and test functions are broken

Location:
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Algorithms/EngineAlgorithm.cs

    r17517 r17614  
    185185    protected override void DeregisterProblemEvents() {
    186186      Problem.Reset -= new EventHandler(Problem_Reset);
     187      Problem.OperatorsChanged -= new EventHandler(Problem_OperatorsChanged);
    187188    }
    188189    protected override void RegisterProblemEvents() {
    189190      Problem.Reset += new EventHandler(Problem_Reset);
     191      Problem.OperatorsChanged += new EventHandler(Problem_OperatorsChanged);
    190192    }
    191193    protected virtual void Problem_OperatorsChanged(object sender, EventArgs e) { }
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/CombinedEncoding.cs

    r17226 r17614  
    5555      : base("CombinedEncoding") {
    5656      encodings = new ItemCollection<IEncoding>();
    57       SolutionCreator = new MultiEncodingCreator() { SolutionParameter = { ActualName = Name } };
    5857      foreach (var @operator in ApplicationManager.Manager.GetInstances<IMultiEncodingOperator>()) {
    5958        @operator.SolutionParameter.ActualName = Name;
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Encoding.cs

    r17571 r17614  
    5252        encodingOperators.Clear();
    5353        foreach (var op in value) encodingOperators.Add(op);
    54 
    55         ISolutionCreator<TEncodedSolution> newSolutionCreator = (ISolutionCreator<TEncodedSolution>)encodingOperators.FirstOrDefault(o => o.GetType() == SolutionCreator.GetType()) ??
    56                                encodingOperators.OfType<ISolutionCreator<TEncodedSolution>>().First();
    57         SolutionCreator = newSolutionCreator;
    5854        OnOperatorsChanged();
    59       }
    60     }
    61 
    62     public IValueParameter SolutionCreatorParameter {
    63       get { return (IValueParameter)Parameters[Name + ".SolutionCreator"]; }
    64     }
    65 
    66     ISolutionCreator IEncoding.SolutionCreator {
    67       get { return SolutionCreator; }
    68     }
    69     public ISolutionCreator<TEncodedSolution> SolutionCreator {
    70       get { return (ISolutionCreator<TEncodedSolution>)SolutionCreatorParameter.Value; }
    71       set {
    72         if (value == null) throw new ArgumentNullException("SolutionCreator must not be null.");
    73         encodingOperators.Remove(SolutionCreator);
    74         encodingOperators.Add(value);
    75         SolutionCreatorParameter.Value = value;
    76         OnSolutionCreatorChanged();
    7755      }
    7856    }
     
    8260    protected Encoding(StorableConstructorFlag _) : base(_) { }
    8361    [StorableHook(HookType.AfterDeserialization)]
    84     private void AfterDeserialization() {
    85       RegisterEventHandlers();
    86     }
     62    private void AfterDeserialization() { }
    8763
    8864    protected Encoding(Encoding<TEncodedSolution> original, Cloner cloner)
    8965      : base(original, cloner) {
    9066      encodingOperators = cloner.Clone(original.encodingOperators);
    91 
    92       RegisterEventHandlers();
    9367    }
    9468
    9569    protected Encoding(string name)
    9670      : base(name) {
    97       Parameters.Add(new ValueParameter<ISolutionCreator<TEncodedSolution>>(name + ".SolutionCreator", "The operator to create a solution.") {
    98         ReadOnly = true
    99       });
    10071      Parameters.Add(new FixedValueParameter<ReadOnlyItemSet<IOperator>>(name + ".Operators", "The operators that the encoding specifies.", encodingOperators.AsReadOnly()) {
    10172        GetsCollected = false, ReadOnly = true
    10273      });
    103 
    104       RegisterEventHandlers();
    105     }
    106 
    107     private void RegisterEventHandlers() {
    108       SolutionCreatorParameter.ValueChanged += (o, e) => OnSolutionCreatorChanged();
    10974    }
    11075
     
    137102    }
    138103
    139     public event EventHandler SolutionCreatorChanged;
    140     protected virtual void OnSolutionCreatorChanged() {
    141       ConfigureOperator(SolutionCreator);
    142       var handler = SolutionCreatorChanged;
    143       if (handler != null) handler(this, EventArgs.Empty);
    144     }
    145 
    146104    public event EventHandler OperatorsChanged;
    147105    protected virtual void OnOperatorsChanged() {
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IEncoding.cs

    r17226 r17614  
    2828  [StorableType("d70b2675-246c-489c-a91b-b2e19a1616a3")]
    2929  public interface IEncoding : IParameterizedNamedItem {
    30     IValueParameter SolutionCreatorParameter { get; }
    31     ISolutionCreator SolutionCreator { get; }
    32 
    3330    IEnumerable<IOperator> Operators { get; set; }
    3431
     
    3734
    3835    event EventHandler OperatorsChanged;
    39     event EventHandler SolutionCreatorChanged;
    4036  }
    4137
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IProblem.cs

    r17612 r17614  
    4040  //TODO Intermediate class for compatibility
    4141  //TODO move members to generic IProblem after every problem used the new architecture
     42  //TODO ABE: We can maybe use it as non-generic interface that exports IEncoding Encoding { get; }
     43  //TODO ABE: and which is explicitely implemented in some base class
    4244  public interface IEncodedProblem : IProblem {
    4345    IEnumerable<IItem> Operators { get; }
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiEncodingCreator.cs

    r17226 r17614  
    2020#endregion
    2121
    22 using System;
    23 using System.Linq;
    2422using HEAL.Attic;
    2523using HeuristicLab.Common;
     
    5755    }
    5856
    59     public override void AddEncoding(IEncoding encoding) {
    60       base.AddEncoding(encoding);
    61       var parameter = GetParameter(encoding);
    62       parameter.Value = encoding.SolutionCreator;
    63       encoding.SolutionCreatorChanged += Encoding_SolutionCreatorChanged;
    64     }
    65 
    66     public override bool RemoveEncoding(IEncoding encoding) {
    67       var success = base.RemoveEncoding(encoding);
    68       encoding.SolutionCreatorChanged -= Encoding_SolutionCreatorChanged;
    69       return success;
    70     }
    71 
    72     private void Encoding_SolutionCreatorChanged(object sender, EventArgs e) {
    73       var encoding = (IEncoding)sender;
    74       var parameter = GetParameter(encoding);
    75 
    76       var oldCreator = parameter.ValidValues.Single(creator => creator.GetType() == encoding.SolutionCreator.GetType());
    77       parameter.ValidValues.Remove(oldCreator);
    78       parameter.ValidValues.Add(encoding.SolutionCreator);
    79       parameter.Value = encoding.SolutionCreator;
    80     }
    81 
    8257
    8358    public override IOperation InstrumentedApply() {
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Problem.cs

    r17612 r17614  
    3737    where TEvaluator : class, IEvaluator {
    3838
     39    [Storable] protected ConstrainedValueParameter<ISolutionCreator> SolutionCreatorParameter { get; private set; }
    3940
    4041    //TODO remove parameter for encoding?
     
    5253    }
    5354
    54 
    55     ISolutionCreator IHeuristicOptimizationProblem.SolutionCreator {
    56       get { return Encoding.SolutionCreator; }
    57     }
    58     IParameter IHeuristicOptimizationProblem.SolutionCreatorParameter {
    59       get { return Encoding.SolutionCreatorParameter; }
    60     }
     55    ISolutionCreator IHeuristicOptimizationProblem.SolutionCreator { get => SolutionCreatorParameter.Value; }
     56    IParameter IHeuristicOptimizationProblem.SolutionCreatorParameter { get => SolutionCreatorParameter; }
     57
    6158    event EventHandler IHeuristicOptimizationProblem.SolutionCreatorChanged {
    6259      add {
    63         if (Encoding != null) Encoding.SolutionCreatorChanged += value;
     60        SolutionCreatorParameter.ValueChanged += value;
    6461      }
    6562      remove {
    66         if (Encoding != null) Encoding.SolutionCreatorChanged -= value;
     63        SolutionCreatorParameter.ValueChanged -= value;
    6764      }
    6865    }
     
    106103      Parameters.Add(new ValueParameter<TEncoding>("Encoding", "Describes the configuration of the encoding, what the variables are called, what type they are and their bounds if any.", encoding) { Hidden = true });
    107104      Parameters.Add(new ValueParameter<TEvaluator>("Evaluator", "The operator used to evaluate a solution.") { Hidden = true });
     105      Parameters.Add(SolutionCreatorParameter = new ConstrainedValueParameter<ISolutionCreator>("SolutionCreator", "The operator used to create a solution."));
    108106
    109107      oldEncoding = Encoding;
     
    116114      : base(original, cloner) {
    117115      oldEncoding = cloner.Clone(original.oldEncoding);
     116      SolutionCreatorParameter = cloner.Clone(original.SolutionCreatorParameter);
    118117      RegisterEvents();
    119118    }
     
    124123    private void AfterDeserialization() {
    125124      oldEncoding = Encoding;
     125      // TODO: remove below
     126      if (SolutionCreatorParameter == null) Parameters.Add(SolutionCreatorParameter = new ConstrainedValueParameter<ISolutionCreator>("SolutionCreator", "The operator used to create a solution."));
     127
    126128      RegisterEvents();
    127129    }
     
    157159
    158160      Encoding.ConfigureOperators(Operators);
     161
     162      SolutionCreatorParameter.Repopulate(GetOperators());
    159163      //var multiEncoding = Encoding as MultiEncoding;
    160164      //if (multiEncoding != null) multiEncoding.EncodingsChanged += MultiEncodingOnEncodingsChanged;
Note: See TracChangeset for help on using the changeset viewer.