Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11516 for branches


Ignore:
Timestamp:
10/31/14 13:52:02 (10 years ago)
Author:
ascheibe
Message:

#2267 added new subscopes comparer

Location:
branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm-3.3.csproj

    r11513 r11516  
    172172    <Compile Include="VOffspringSelectionGeneticAlgorithmMainLoop.cs" />
    173173    <Compile Include="VOffspringSelectionGeneticAlgorithmMainOperator.cs" />
     174    <Compile Include="WeightedParentsDiversityComparator.cs" />
    174175    <Compile Include="WeightedParentsQualityComparator.cs" />
    175176  </ItemGroup>
  • branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/VOffspringSelectionGeneticAlgorithm.cs

    r11513 r11516  
    121121      get { return (ConstrainedValueParameter<ISubScopesQualityComparatorOperator>)Parameters["SubScopesQualityComparator"]; }
    122122    }
     123    public IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator> SimilarityCalculatorParameter {
     124      get { return (IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
     125    }
    123126    #endregion
    124127
     
    218221    private SolutionsCreator SolutionsCreator {
    219222      get { return (SolutionsCreator)RandomCreator.Successor; }
     223    }
     224    public ISingleObjectiveSolutionSimilarityCalculator SimilarityCalculator {
     225      get { return SimilarityCalculatorParameter.Value; }
     226      set { SimilarityCalculatorParameter.Value = value; }
    220227    }
    221228    private VOffspringSelectionGeneticAlgorithmMainLoop MainLoop {
     
    281288      Parameters.Add(new ConstrainedValueParameter<IOffspringSelector>("OffspringSelector", "The operator used as selection criterea for deciding which individuals are successful and which should be disgarded."));
    282289      Parameters.Add(new ConstrainedValueParameter<ISubScopesQualityComparatorOperator>("SubScopesQualityComparator", "The operator used to compare solution candidates with."));
     290      Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
    283291
    284292      RandomCreator randomCreator = new RandomCreator();
     
    378386      ParameterizeSubScopesQualityComparators();
    379387      ParameterizeOffspringSelectors();
     388      UpdateSimilarityCalculators();
    380389      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    381390      base.OnProblemChanged();
     
    422431      ParameterizeSelectors();
    423432      ParameterizeAnalyzers();
     433      ParameterizeSimilarityCalculators();
    424434    }
    425435    #endregion
     
    434444        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    435445      }
     446      SimilarityCalculatorParameter.ValueChanged += SimilarityCalculatorParameter_ValueChanged;
     447    }
     448    void SimilarityCalculatorParameter_ValueChanged(object sender, EventArgs e) {
     449      foreach (ISimilarityBasedOperator op in SubScopesQualityComparatorParameter.ValidValues.OfType<ISimilarityBasedOperator>())
     450        op.SimilarityCalculator = SimilarityCalculator;
    436451    }
    437452    private void ParameterizeSolutionsCreator() {
     
    560575      Analyzer.Operators.Add(successfulOffspringAnalyzer, successfulOffspringAnalyzer.EnabledByDefault);
    561576    }
     577    private void UpdateSimilarityCalculators() {
     578      ISingleObjectiveSolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
     579      SimilarityCalculatorParameter.ValidValues.Clear();
     580      ISingleObjectiveSolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>().FirstOrDefault();
     581
     582      SimilarityCalculatorParameter.ValidValues.Add(new QualitySimilarityCalculator { QualityVariableName = Problem.Evaluator.QualityParameter.ActualName });
     583      SimilarityCalculatorParameter.ValidValues.Add(new NoSimilarityCalculator());
     584
     585      foreach (ISingleObjectiveSolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>())
     586        SimilarityCalculatorParameter.ValidValues.Add(similarityCalculator);
     587
     588      if (oldSimilarityCalculator != null) {
     589        ISingleObjectiveSolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
     590        if (similarityCalculator != null) SimilarityCalculatorParameter.Value = similarityCalculator;
     591        else oldSimilarityCalculator = null;
     592      }
     593      if (oldSimilarityCalculator == null && defaultSimilarityCalculator != null)
     594        SimilarityCalculatorParameter.Value = defaultSimilarityCalculator;
     595    }
     596    private void ParameterizeSimilarityCalculators() {
     597      foreach (ISingleObjectiveSolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {
     598        calc.QualityVariableName = Problem.Evaluator.QualityParameter.ActualName;
     599      }
     600    }
    562601    private VOffspringSelectionGeneticAlgorithmMainLoop FindMainLoop(IOperator start) {
    563602      IOperator mainLoop = start;
Note: See TracChangeset for help on using the changeset viewer.