Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9553 for trunk/sources


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

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

Location:
trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3
Files:
2 edited

Legend:

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

    r9456 r9553  
    7979      get { return (ValueParameter<IntValue>)Parameters["Elites"]; }
    8080    }
     81    private IFixedValueParameter<BoolValue> ReevaluateElitesParameter {
     82      get { return (IFixedValueParameter<BoolValue>)Parameters["ReevaluateElites"]; }
     83    }
    8184    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
    8285      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
     
    119122      get { return ElitesParameter.Value; }
    120123      set { ElitesParameter.Value = value; }
     124    }
     125    public bool ReevaluteElites {
     126      get { return ReevaluateElitesParameter.Value.Value; }
     127      set { ReevaluateElitesParameter.Value.Value = value; }
    121128    }
    122129    public MultiAnalyzer Analyzer {
     
    151158      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
    152159      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
     160      Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false)) { Hidden = true });
    153161      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
    154162      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
     
    207215    [StorableHook(HookType.AfterDeserialization)]
    208216    private void AfterDeserialization() {
     217      if (!Parameters.ContainsKey("ReevaluateElites")) {
     218        Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", (BoolValue)new BoolValue(false).AsReadOnly()) { Hidden = true });
     219      }
    209220      Initialize();
    210221    }
  • 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.