Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8628 for trunk


Ignore:
Timestamp:
09/11/12 11:41:19 (12 years ago)
Author:
jkarder
Message:

#1331: adjusted event handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs

    r8380 r8628  
    8888      get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
    8989    }
    90     public IConstrainedValueParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
    91       get { return (IConstrainedValueParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
     90    public IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator> SimilarityCalculatorParameter {
     91      get { return (IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    9292    }
    9393    #endregion
     
    138138      set { SetSeedRandomlyParameter.Value = value; }
    139139    }
    140     public ISolutionSimilarityCalculator SimilarityCalculator {
     140    public ISingleObjectiveSolutionSimilarityCalculator SimilarityCalculator {
    141141      get { return SimilarityCalculatorParameter.Value; }
    142142      set { SimilarityCalculatorParameter.Value = value; }
     
    184184      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    185185      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
    186       Parameters.Add(new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
     186      Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
    187187      #endregion
    188188
     
    307307      base.Problem_OperatorsChanged(sender, e);
    308308    }
     309    private void SimilarityCalculatorParameter_ValueChanged(object sender, EventArgs e) {
     310      ParameterizeMainLoop();
     311    }
    309312    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    310313      ParameterizeMainLoop();
    311314      ParameterizeAnalyzers();
    312315      ParameterizeBestSelector();
     316      ParameterizeSimilarityCalculators();
    313317    }
    314318    #endregion
     
    316320    #region Helpers
    317321    private void Initialize() {
     322      SimilarityCalculatorParameter.ValueChanged += new EventHandler(SimilarityCalculatorParameter_ValueChanged);
    318323      if (Problem != null)
    319324        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
     
    379384    }
    380385    private void UpdateSimilarityCalculators() {
    381       ISolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
     386      ISingleObjectiveSolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
    382387      SimilarityCalculatorParameter.ValidValues.Clear();
    383       ISolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISolutionSimilarityCalculator>().FirstOrDefault();
    384 
    385       foreach (ISolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISolutionSimilarityCalculator>())
     388      ISingleObjectiveSolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>().FirstOrDefault();
     389
     390      SimilarityCalculatorParameter.ValidValues.Add(new QualitySimilarityCalculator { QualityVariableName = Problem.Evaluator.QualityParameter.ActualName });
     391      SimilarityCalculatorParameter.ValidValues.Add(new BlindSimilarityCalculator());
     392
     393      foreach (ISingleObjectiveSolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>())
    386394        SimilarityCalculatorParameter.ValidValues.Add(similarityCalculator);
    387395
    388396      if (oldSimilarityCalculator != null) {
    389         ISolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
     397        ISingleObjectiveSolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
    390398        if (similarityCalculator != null) SimilarityCalculatorParameter.Value = similarityCalculator;
    391399        else oldSimilarityCalculator = null;
     
    434442      }
    435443    }
     444    private void ParameterizeSimilarityCalculators() {
     445      foreach (ISingleObjectiveSolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {
     446        calc.QualityVariableName = Problem.Evaluator.QualityParameter.ActualName;
     447      }
     448    }
    436449    private ScatterSearchMainLoop FindMainLoop(IOperator start) {
    437450      IOperator mainLoop = start;
Note: See TracChangeset for help on using the changeset viewer.