Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/25/17 16:21:48 (7 years ago)
Author:
gkronber
Message:

#2524: merged r14517, r14523, r14527 from trunk to branch

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs

    r14186 r15061  
    4848
    4949    private const string IterationsParameterName = "Iterations";
     50    private const string BestQualityResultName = "Best quality";
     51    private const string IterationsResultName = "Iterations";
    5052
    5153    public override Type ProblemType {
    5254      get { return typeof(BinaryProblem); }
    5355    }
     56
     57    public override bool SupportsPause { get { return false; } }
     58
    5459    public new BinaryProblem Problem {
    5560      get { return (BinaryProblem)base.Problem; }
     
    6570      set { IterationsParameter.Value.Value = value; }
    6671    }
     72
     73    #region ResultsProperties
     74    private double ResultsBestQuality {
     75      get { return ((DoubleValue)Results[BestQualityResultName].Value).Value; }
     76      set { ((DoubleValue)Results[BestQualityResultName].Value).Value = value; }
     77    }
     78    private int ResultsIterations {
     79      get { return ((IntValue)Results[IterationsResultName].Value).Value; }
     80      set { ((IntValue)Results[IterationsResultName].Value).Value = value; }
     81    }
     82    #endregion
    6783
    6884    [StorableConstructor]
     
    8096      Parameters.Add(new FixedValueParameter<IntValue>(IterationsParameterName, "", new IntValue(100)));
    8197    }
     98
     99
     100    protected override void Initialize(CancellationToken cancellationToken) {
     101      Results.Add(new Result(BestQualityResultName, new DoubleValue(double.NaN)));
     102      Results.Add(new Result(IterationsResultName, new IntValue(0)));
     103      base.Initialize(cancellationToken);
     104    }
    82105    protected override void Run(CancellationToken cancellationToken) {
    83       var BestQuality = new DoubleValue(double.NaN);
    84       Results.Add(new Result("Best quality", BestQuality));
    85       for (int iteration = 0; iteration < Iterations; iteration++) {
     106      while (ResultsIterations < Iterations) {
     107        cancellationToken.ThrowIfCancellationRequested();
     108
    86109        var solution = new BinaryVector(Problem.Length);
    87110        for (int i = 0; i < solution.Length; i++) {
     
    92115
    93116        fitness = ImproveToLocalOptimum(Problem, solution, fitness, random);
    94         if (double.IsNaN(BestQuality.Value) || Problem.IsBetter(fitness, BestQuality.Value)) {
    95           BestQuality.Value = fitness;
     117        if (double.IsNaN(ResultsBestQuality) || Problem.IsBetter(fitness, ResultsBestQuality)) {
     118          ResultsBestQuality = fitness;
    96119        }
     120
     121        ResultsIterations++;
    97122      }
    98123    }
  • stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs

    r14186 r15061  
    5656
    5757    // Tracks all solutions in Pyramid for quick membership checks
    58     private HashSet<BinaryVector> seen = new HashSet<BinaryVector>(new EnumerableBoolEqualityComparer());
     58    private readonly HashSet<BinaryVector> seen = new HashSet<BinaryVector>(new EnumerableBoolEqualityComparer());
    5959
    6060    #region ParameterNames
     
    152152    }
    153153    #endregion
     154
     155    public override bool SupportsPause { get { return true; } }
    154156
    155157    [StorableConstructor]
     
    213215    }
    214216
    215     protected override void Run(CancellationToken cancellationToken) {
     217    protected override void Initialize(CancellationToken cancellationToken) {
    216218      // Set up the algorithm
    217219      if (SetSeedRandomly) Seed = new System.Random().Next();
     
    242244      Results.Add(new Result("Stored Solutions", table));
    243245
     246      base.Initialize(cancellationToken);
     247    }
     248
     249    protected override void Run(CancellationToken cancellationToken) {
    244250      // Loop until iteration limit reached or canceled.
    245       for (ResultsIterations = 0; ResultsIterations < MaximumIterations; ResultsIterations++) {
     251      while (ResultsIterations < MaximumIterations) {
    246252        double fitness = double.NaN;
    247253
    248254        try {
    249255          fitness = iterate();
     256          ResultsIterations++;
    250257          cancellationToken.ThrowIfCancellationRequested();
    251258        } finally {
Note: See TracChangeset for help on using the changeset viewer.