Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/29/15 17:09:30 (9 years ago)
Author:
pfleck
Message:

#2350 Added Termination Criteria to Steady-State ALPS.

Location:
branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3/AlpsSsGeneticAlgorithm.cs

    r12271 r12534  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using HeuristicLab.Common;
     
    4344      get { return (IValueParameter<IntValue>)Parameters["LayerSize"]; }
    4445    }
    45     private IValueParameter<IntValue> MaximumIterationsParameter {
    46       get { return (IValueParameter<IntValue>)Parameters["MaximumIterations"]; }
    47     }
    4846    public IConstrainedValueParameter<ISelector> SelectorParameter {
    4947      get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
     
    7472      set { LayerSizeParameter.Value = value; }
    7573    }
    76     public IntValue MaximumIterations {
    77       get { return MaximumIterationsParameter.Value; }
    78       set { MaximumIterationsParameter.Value = value; }
     74    public int MaximumIterations {
     75      get { return iterationsTerminator.Threshold.Value; }
     76      set { iterationsTerminator.Threshold.Value = value; }
    7977    }
    8078
     
    108106      get { return OperatorGraph.Iterate().OfType<AlpsSsGeneticAlgorithmMainLoop>().First(); }
    109107    }
     108
     109    [Storable]
     110    private ComparisonTerminator<IntValue> iterationsTerminator;
    110111
    111112    [StorableConstructor]
     
    114115    private AlpsSsGeneticAlgorithm(AlpsSsGeneticAlgorithm original, Cloner cloner)
    115116      : base(original, cloner) {
     117      iterationsTerminator = cloner.Clone(original.iterationsTerminator);
    116118      Initialize();
    117119    }
     
    123125      : base() {
    124126      Parameters.Add(new ValueParameter<IntValue>("LayerSize", "The size of the population of solutions each layer.", new IntValue(100)));
    125       Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of iterations that should be processed.", new IntValue(1000)));
    126127      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
    127128      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
     
    275276          @operator.IterationsParameter.ActualName = "Iteration";
    276277          @operator.IterationsParameter.Hidden = true;
    277           @operator.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
     278          @operator.MaximumIterationsParameter.ActualName = iterationsTerminator.ThresholdParameter.Name;
    278279          @operator.MaximumIterationsParameter.Hidden = true;
    279280        }
     
    307308
    308309    #region Updates
     310    protected override void UpdateTerminators() {
     311      var newTerminators = new Dictionary<ITerminator, bool> {
     312        {iterationsTerminator, !Terminators.Operators.Contains(iterationsTerminator) || Terminators.Operators.ItemChecked(iterationsTerminator)},
     313      };
     314
     315      base.UpdateTerminators();
     316
     317      foreach (var newTerminator in newTerminators)
     318        Terminators.Operators.Insert(0, newTerminator.Key, newTerminator.Value);
     319    }
     320    protected override void CreateTerminators() {
     321      iterationsTerminator = new ComparisonTerminator<IntValue>("Iterations", ComparisonType.Less, new IntValue(1000)) { Name = "Iterations" };
     322      base.CreateTerminators();
     323    }
    309324    private void UpdateCrossovers() {
    310325      var oldCrossover = CrossoverParameter.Value;
  • branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3/AlpsSsGeneticAlgorithmMainLoop.cs

    r12270 r12534  
    2020#endregion
    2121
    22 using System.Linq;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
     
    2928using HeuristicLab.Parameters;
    3029using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Selection;
    3230
    3331namespace HeuristicLab.Algorithms.ALPS.SteadyState {
     
    107105      var layerAnalyzer = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
    108106      var analyzer = new Placeholder() { Name = "Analyzer (Placeholder)" };
    109       var iterationsComparator = new Comparator() { Name = "Iterations >= MaximumIterations" };
    110       var terminateBranch = new ConditionalBranch() { Name = "Terminate?" };
     107      var termination = new TerminationOperator();
    111108
    112109
     
    253250
    254251      analyzer.OperatorParameter.ActualName = "Analyzer";
    255       analyzer.Successor = iterationsComparator;
    256 
    257       iterationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
    258       iterationsComparator.LeftSideParameter.ActualName = "Iterations";
    259       iterationsComparator.RightSideParameter.ActualName = MaximumIterationsParameter.Name;
    260       iterationsComparator.ResultParameter.ActualName = "Terminate";
    261       iterationsComparator.Successor = terminateBranch;
    262 
    263       terminateBranch.ConditionParameter.ActualName = "Terminate";
    264       terminateBranch.FalseBranch = initializeBatchIteration;
     252      analyzer.Successor = termination;
     253
     254      termination.ContinueBranch = initializeBatchIteration;
    265255    }
    266256  }
Note: See TracChangeset for help on using the changeset viewer.