Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ScopedAlgorithms/HeuristicLab.Problems.Programmable/3.3/CompiledProblemDefinition.cs @ 15666

Last change on this file since 15666 was 13361, checked in by mkommend, 9 years ago

#2521: Adapted real vector encoding, test function problems, P3, CMA-ES and optimization.

File size: 3.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using HeuristicLab.Core;
25using HeuristicLab.Optimization;
26
27namespace HeuristicLab.Problems.Programmable {
28  public abstract class CompiledProblemDefinition<TEncoding, TSolution> : IProblemDefinition<TEncoding, TSolution>
29    where TEncoding : class, IEncoding<TSolution>
30    where TSolution : class, ISolution {
31    private TEncoding encoding;
32    public TEncoding Encoding {
33      get { return encoding; }
34      internal set {
35        if (value == null) throw new ArgumentNullException("The encoding must not be null.");
36        encoding = value;
37      }
38    }
39
40    public dynamic vars { get; set; }
41    public abstract void Initialize();
42
43    protected CompiledProblemDefinition() { }
44    protected CompiledProblemDefinition(TEncoding encoding)
45      : base() {
46      Encoding = encoding;
47    }
48  }
49
50  public abstract class CompiledSingleObjectiveProblemDefinition<TEncoding, TSolution> : CompiledProblemDefinition<TEncoding, TSolution>, ISingleObjectiveProblemDefinition<TEncoding, TSolution>
51    where TEncoding : class, IEncoding<TSolution>
52    where TSolution : class, ISolution {
53
54    protected CompiledSingleObjectiveProblemDefinition() : base() { }
55
56    protected CompiledSingleObjectiveProblemDefinition(TEncoding encoding)
57      : base(encoding) { }
58
59    #region ISingleObjectiveProblemDefinition<TEncoding,TSolution> Members
60    public abstract bool Maximization { get; }
61    public abstract double Evaluate(TSolution individual, IRandom random);
62    public abstract void Analyze(TSolution[] individuals, double[] qualities, ResultCollection results, IRandom random);
63    public abstract IEnumerable<TSolution> GetNeighbors(TSolution individual, IRandom random);
64
65    public bool IsBetter(double quality, double bestQuality) {
66      return Maximization ? quality > bestQuality : quality < bestQuality;
67    }
68    #endregion
69  }
70
71  public abstract class CompiledMultiObjectiveProblemDefinition<TEncoding, TSolution> : CompiledProblemDefinition<TEncoding, TSolution>, IMultiObjectiveProblemDefinition<TEncoding, TSolution>
72    where TEncoding : class, IEncoding<TSolution>
73    where TSolution : class, ISolution {
74
75    protected CompiledMultiObjectiveProblemDefinition() : base() { }
76
77    protected CompiledMultiObjectiveProblemDefinition(TEncoding encoding)
78      : base(encoding) { }
79
80    #region ISingleObjectiveProblemDefinition<TEncoding,TSolution> Members
81    public abstract bool[] Maximization { get; }
82    public abstract double[] Evaluate(TSolution individual, IRandom random);
83    public abstract void Analyze(TSolution[] individuals, double[][] qualities, ResultCollection results, IRandom random);
84    public abstract IEnumerable<TSolution> GetNeighbors(TSolution individual, IRandom random);
85    #endregion
86  }
87}
Note: See TracBrowser for help on using the repository browser.