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.

File:
1 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;
Note: See TracChangeset for help on using the changeset viewer.