Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8349 for branches


Ignore:
Timestamp:
07/27/12 16:17:01 (12 years ago)
Author:
jkarder
Message:

#1247: added duplication control

Location:
branches/RAPGA/HeuristicLab.Algorithms.RAPGA/3.3
Files:
3 edited

Legend:

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

    r8313 r8349  
    9797  </ItemGroup>
    9898  <ItemGroup>
     99    <Compile Include="DuplicateSelector.cs" />
    99100    <Compile Include="RAPGA.cs" />
    100101    <Compile Include="RAPGAMainLoop.cs" />
  • branches/RAPGA/HeuristicLab.Algorithms.RAPGA/3.3/RAPGA.cs

    r8330 r8349  
    6666    private IValueParameter<IntValue> MinimumPopulationSizeParameter {
    6767      get { return (IValueParameter<IntValue>)Parameters["MinimumPopulationSize"]; }
    68     } 
     68    }
    6969    private IValueParameter<IntValue> MaximumPopulationSizeParameter {
    70       get { return (IValueParameter<IntValue>) Parameters["MaximumPopulationSize"]; }
     70      get { return (IValueParameter<IntValue>)Parameters["MaximumPopulationSize"]; }
    7171    }
    7272    private IValueParameter<DoubleValue> ComparisonFactorParameter {
     
    9696    private ValueParameter<IntValue> MaximumGenerationsParameter {
    9797      get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
     98    }
     99    public IConstrainedValueParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
     100      get { return (IConstrainedValueParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    98101    }
    99102    #endregion
     
    155158      get { return MaximumGenerationsParameter.Value; }
    156159      set { MaximumGenerationsParameter.Value = value; }
     160    }
     161    public ISolutionSimilarityCalculator SimilarityCalculator {
     162      get { return SimilarityCalculatorParameter.Value; }
     163      set { SimilarityCalculatorParameter.Value = value; }
    157164    }
    158165    private RandomCreator RandomCreator {
     
    194201      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
    195202      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
     203      Parameters.Add(new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
    196204
    197205      RandomCreator randomCreator = new RandomCreator();
     
    249257
    250258    public override void Prepare() {
    251       if (Problem != null) base.Prepare();
     259      if (Problem != null && SimilarityCalculator != null) base.Prepare();
    252260    }
    253261
     
    258266      foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
    259267      ParameterizeSolutionsCreator();
    260       ParameterizeGeneticAlgorithmMainLoop();
    261268      ParameterizeSelectors();
    262269      ParameterizeAnalyzers();
     
    265272      UpdateMutators();
    266273      UpdateAnalyzers();
     274      UpdateSimilarityCalculators();
     275      ParameterizeRAPGAMainLoop();
    267276      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    268277      base.OnProblemChanged();
     
    277286      ParameterizeStochasticOperator(Problem.Evaluator);
    278287      ParameterizeSolutionsCreator();
    279       ParameterizeGeneticAlgorithmMainLoop();
     288      ParameterizeRAPGAMainLoop();
    280289      ParameterizeSelectors();
    281290      ParameterizeAnalyzers();
     
    284293    }
    285294    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
    286       foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
     295      foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
    287296      ParameterizeIterationBasedOperators();
    288297      UpdateCrossovers();
    289298      UpdateMutators();
    290299      UpdateAnalyzers();
     300      UpdateSimilarityCalculators();
     301      ParameterizeRAPGAMainLoop();
    291302      base.Problem_OperatorsChanged(sender, e);
    292303    }
     
    307318    }
    308319    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    309       ParameterizeGeneticAlgorithmMainLoop();
     320      ParameterizeRAPGAMainLoop();
    310321      ParameterizeSelectors();
    311322      ParameterizeAnalyzers();
     
    328339      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
    329340    }
    330     private void ParameterizeGeneticAlgorithmMainLoop() {
     341    private void ParameterizeRAPGAMainLoop() {
    331342      RAPGAMainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
    332343      RAPGAMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    333344      RAPGAMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     345      foreach (ISimilarityBasedOperator op in RAPGAMainLoop.OperatorGraph.Operators.OfType<ISimilarityBasedOperator>())
     346        op.SimilarityCalculator = SimilarityCalculator;
    334347    }
    335348    private void ParameterizeStochasticOperator(IOperator op) {
     
    416429      Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
    417430    }
     431    private void UpdateSimilarityCalculators() {
     432      ISolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
     433      SimilarityCalculatorParameter.ValidValues.Clear();
     434      ISolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISolutionSimilarityCalculator>().FirstOrDefault();
     435
     436      foreach (ISolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISolutionSimilarityCalculator>())
     437        SimilarityCalculatorParameter.ValidValues.Add(similarityCalculator);
     438
     439      if (oldSimilarityCalculator != null) {
     440        ISolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
     441        if (similarityCalculator != null) SimilarityCalculatorParameter.Value = similarityCalculator;
     442        else oldSimilarityCalculator = null;
     443      }
     444      if (oldSimilarityCalculator == null && defaultSimilarityCalculator != null)
     445        SimilarityCalculatorParameter.Value = defaultSimilarityCalculator;
     446    }
    418447    private RAPGAMainLoop FindMainLoop(IOperator start) {
    419448      IOperator mainLoop = start;
  • branches/RAPGA/HeuristicLab.Algorithms.RAPGA/3.3/RAPGAMainLoop.cs

    r8330 r8349  
    151151      ConditionalSelector conditionalSelector = new ConditionalSelector();
    152152      RightReducer rightReducer1 = new RightReducer();
     153      UniformSubScopesProcessor uniformSubScopesProcessor3 = new UniformSubScopesProcessor();
     154      SubScopesRemover subScopesRemover = new SubScopesRemover();
     155      DuplicateSelector duplicateSelector = new DuplicateSelector();
     156      LeftReducer leftReducer = new LeftReducer();
    153157      SubScopesCounter subScopesCounter1 = new SubScopesCounter();
    154158      IntCounter intCounter1 = new IntCounter();
    155       UniformSubScopesProcessor uniformSubScopesProcessor3 = new UniformSubScopesProcessor();
    156       SubScopesRemover subScopesRemover = new SubScopesRemover();
    157159      Comparator comparator2 = new Comparator();
    158160      ConditionalBranch conditionalBranch1 = new ConditionalBranch();
     
    217219      conditionalSelector.CopySelected.Value = false;
    218220
     221      duplicateSelector.CopySelected.Value = false;
     222
     223      uniformSubScopesProcessor3.Parallel.Value = true;
     224
     225      subScopesRemover.RemoveAllSubScopes = true;
     226
    219227      subScopesCounter1.Name = "Count Successful Offspring";
    220228      subScopesCounter1.ValueParameter.ActualName = "NumberOfSuccessfulOffspring";
     
    223231      intCounter1.IncrementParameter.Value = null;
    224232      intCounter1.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
    225 
    226       uniformSubScopesProcessor3.Parallel.Value = true;
    227 
    228       subScopesRemover.RemoveAllSubScopes = true;
    229233
    230234      comparator2.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
     
    267271      assigner2.RightSideParameter.Value = new IntValue(0);
    268272
    269       subScopesCounter2.Name = "Increment EvaluatedSolutions";
     273      subScopesCounter2.Name = "Set CurrentPopulationSize";
    270274      subScopesCounter2.ValueParameter.ActualName = "CurrentPopulationSize";
    271275
     
    304308      evaluator.Successor = comparator1;
    305309      conditionalSelector.Successor = rightReducer1;
    306       rightReducer1.Successor = subScopesCounter1;
     310      rightReducer1.Successor = uniformSubScopesProcessor3;
     311      uniformSubScopesProcessor3.Operator = subScopesRemover;
     312      uniformSubScopesProcessor3.Successor = duplicateSelector;
     313      duplicateSelector.Successor = leftReducer;
     314      leftReducer.Successor = subScopesCounter1;
    307315      subScopesCounter1.Successor = intCounter1;
    308       intCounter1.Successor = uniformSubScopesProcessor3;
    309       uniformSubScopesProcessor3.Operator = subScopesRemover;
    310       uniformSubScopesProcessor3.Successor = comparator2;
     316      intCounter1.Successor = comparator2;
    311317      comparator2.Successor = conditionalBranch1;
    312318      conditionalBranch1.TrueBranch = bestSelector1;
Note: See TracChangeset for help on using the changeset viewer.