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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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() {
Note: See TracChangeset for help on using the changeset viewer.