Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/29/13 13:14:58 (11 years ago)
Author:
mkommend
Message:

#2038: Added possibility to reevaluate elites in the GA.

File:
1 edited

Legend:

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

    r9456 r9553  
    6363    public ValueLookupParameter<IntValue> ElitesParameter {
    6464      get { return (ValueLookupParameter<IntValue>)Parameters["Elites"]; }
     65    }
     66    public IValueLookupParameter<BoolValue> ReevaluateElitesParameter {
     67      get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; }
    6568    }
    6669    public ValueLookupParameter<IntValue> MaximumGenerationsParameter {
     
    112115      Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization."));
    113116      Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
     117      Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
    114118      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed."));
    115119      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
     
    143147      Placeholder analyzer2 = new Placeholder();
    144148      ConditionalBranch conditionalBranch = new ConditionalBranch();
     149      ConditionalBranch reevaluateElitesBranch = new ConditionalBranch();
     150      UniformSubScopesProcessor uniformSubScopesProcessor3 = new UniformSubScopesProcessor();
     151      Placeholder evaluator2 = new Placeholder();
     152      SubScopesCounter subScopesCounter2 = new SubScopesCounter();
    145153
    146154      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class GeneticAlgorithm expects this to be called Generations
     
    193201
    194202      conditionalBranch.ConditionParameter.ActualName = "Terminate";
     203
     204      reevaluateElitesBranch.ConditionParameter.ActualName = "ReevaluateElites";
     205      reevaluateElitesBranch.Name = "Reevaluate elites ?";
     206
     207      uniformSubScopesProcessor3.Parallel.Value = true;
     208
     209      evaluator2.Name = "Evaluator";
     210      evaluator2.OperatorParameter.ActualName = "Evaluator";
     211
     212      subScopesCounter2.Name = "Increment EvaluatedSolutions";
     213      subScopesCounter2.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
     214
    195215      #endregion
    196216
     
    221241      subScopesProcessor2.Successor = mergingReducer;
    222242      bestSelector.Successor = rightReducer;
    223       rightReducer.Successor = null;
     243      rightReducer.Successor = reevaluateElitesBranch;
     244      reevaluateElitesBranch.TrueBranch = uniformSubScopesProcessor3;
     245      uniformSubScopesProcessor3.Operator = evaluator;
     246      uniformSubScopesProcessor3.Successor = subScopesCounter2;
     247      reevaluateElitesBranch.FalseBranch = null;
     248      reevaluateElitesBranch.Successor = null;
    224249      mergingReducer.Successor = intCounter;
    225250      intCounter.Successor = comparator;
     
    232257    }
    233258
     259    [StorableHook(HookType.AfterDeserialization)]
     260    private void AfterDeserialization() {
     261      if (!Parameters.ContainsKey("ReevaluateElites")) {
     262        Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
     263      }
     264    }
     265
    234266    public override IOperation Apply() {
    235267      if (CrossoverParameter.ActualValue == null)
Note: See TracChangeset for help on using the changeset viewer.