1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Optimization;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Problems.Programmable {
|
---|
29 | public abstract class CompiledProblemDefinition<TEncoding, TEncodedSolution> : IProblemDefinition<TEncoding, TEncodedSolution>
|
---|
30 | where TEncoding : class, IEncoding<TEncodedSolution>
|
---|
31 | where TEncodedSolution : class, IEncodedSolution {
|
---|
32 | private TEncoding encoding;
|
---|
33 | public TEncoding Encoding {
|
---|
34 | get { return encoding; }
|
---|
35 | internal set {
|
---|
36 | if (value == null) throw new ArgumentNullException("The encoding must not be null.");
|
---|
37 | encoding = value;
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 | public dynamic vars { get; set; }
|
---|
42 | public abstract void Initialize();
|
---|
43 |
|
---|
44 | protected CompiledProblemDefinition() { }
|
---|
45 | protected CompiledProblemDefinition(TEncoding encoding)
|
---|
46 | : base() {
|
---|
47 | Encoding = encoding;
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | public abstract class CompiledSingleObjectiveProblemDefinition<TEncoding, TEncodedSolution> : CompiledProblemDefinition<TEncoding, TEncodedSolution>, ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>
|
---|
52 | where TEncoding : class, IEncoding<TEncodedSolution>
|
---|
53 | where TEncodedSolution : class, IEncodedSolution {
|
---|
54 | protected CompiledSingleObjectiveProblemDefinition() : base() { }
|
---|
55 |
|
---|
56 | protected CompiledSingleObjectiveProblemDefinition(TEncoding encoding)
|
---|
57 | : base(encoding) { }
|
---|
58 |
|
---|
59 | #region ISingleObjectiveProblemDefinition<TEncoding,TEncodedSolution> Members
|
---|
60 | public abstract bool Maximization { get; }
|
---|
61 | public abstract double Evaluate(TEncodedSolution individual, IRandom random);
|
---|
62 | public abstract void Analyze(TEncodedSolution[] individuals, double[] qualities, ResultCollection results, IRandom random);
|
---|
63 | public abstract IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution 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, TEncodedSolution> : CompiledProblemDefinition<TEncoding, TEncodedSolution>, IMultiObjectiveProblemDefinition<TEncoding, TEncodedSolution>
|
---|
72 | where TEncoding : class, IEncoding<TEncodedSolution>
|
---|
73 | where TEncodedSolution : class, IEncodedSolution {
|
---|
74 | protected CompiledMultiObjectiveProblemDefinition() : base() { }
|
---|
75 |
|
---|
76 | protected CompiledMultiObjectiveProblemDefinition(TEncoding encoding)
|
---|
77 | : base(encoding) { }
|
---|
78 |
|
---|
79 | #region ISingleObjectiveProblemDefinition<TEncoding,TEncodedSolution> Members
|
---|
80 | public int Objectives => Maximization.Length;
|
---|
81 | public abstract bool[] Maximization { get; }
|
---|
82 | public abstract IReadOnlyList<double[]> BestKnownFront { get; }
|
---|
83 | public abstract double[] ReferencePoint { get; }
|
---|
84 | public abstract double[] Evaluate(TEncodedSolution individual, IRandom random);
|
---|
85 | public abstract void Analyze(TEncodedSolution[] individuals, double[][] qualities, ResultCollection results, IRandom random);
|
---|
86 | public abstract IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution individual, IRandom random);
|
---|
87 | #endregion
|
---|
88 | }
|
---|
89 | } |
---|