[11484] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17226] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[11484] | 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 |
|
---|
[11485] | 22 | using System;
|
---|
[13348] | 23 | using System.Collections.Generic;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
[17225] | 25 | using HeuristicLab.Data;
|
---|
[11949] | 26 | using HeuristicLab.Optimization;
|
---|
[11485] | 27 |
|
---|
[11484] | 28 | namespace HeuristicLab.Problems.Programmable {
|
---|
[16751] | 29 | public abstract class CompiledProblemDefinition<TEncoding, TEncodedSolution> : IProblemDefinition<TEncoding, TEncodedSolution>
|
---|
| 30 | where TEncoding : class, IEncoding<TEncodedSolution>
|
---|
| 31 | where TEncodedSolution : class, IEncodedSolution {
|
---|
[13345] | 32 | private TEncoding encoding;
|
---|
| 33 | public TEncoding Encoding {
|
---|
[11739] | 34 | get { return encoding; }
|
---|
[13345] | 35 | internal set {
|
---|
[11739] | 36 | if (value == null) throw new ArgumentNullException("The encoding must not be null.");
|
---|
| 37 | encoding = value;
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
[11484] | 40 |
|
---|
| 41 | public dynamic vars { get; set; }
|
---|
| 42 | public abstract void Initialize();
|
---|
[11485] | 43 |
|
---|
[11768] | 44 | protected CompiledProblemDefinition() { }
|
---|
[13345] | 45 | protected CompiledProblemDefinition(TEncoding encoding)
|
---|
[11768] | 46 | : base() {
|
---|
[11739] | 47 | Encoding = encoding;
|
---|
| 48 | }
|
---|
[11484] | 49 | }
|
---|
[13348] | 50 |
|
---|
[16751] | 51 | public abstract class CompiledSingleObjectiveProblemDefinition<TEncoding, TEncodedSolution> : CompiledProblemDefinition<TEncoding, TEncodedSolution>, ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>
|
---|
| 52 | where TEncoding : class, IEncoding<TEncodedSolution>
|
---|
| 53 | where TEncodedSolution : class, IEncodedSolution {
|
---|
[13348] | 54 | protected CompiledSingleObjectiveProblemDefinition() : base() { }
|
---|
| 55 |
|
---|
| 56 | protected CompiledSingleObjectiveProblemDefinition(TEncoding encoding)
|
---|
| 57 | : base(encoding) { }
|
---|
| 58 |
|
---|
[16751] | 59 | #region ISingleObjectiveProblemDefinition<TEncoding,TEncodedSolution> Members
|
---|
[13348] | 60 | public abstract bool Maximization { get; }
|
---|
[16751] | 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);
|
---|
[13361] | 64 |
|
---|
| 65 | public bool IsBetter(double quality, double bestQuality) {
|
---|
| 66 | return Maximization ? quality > bestQuality : quality < bestQuality;
|
---|
| 67 | }
|
---|
[13348] | 68 | #endregion
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[16751] | 71 | public abstract class CompiledMultiObjectiveProblemDefinition<TEncoding, TEncodedSolution> : CompiledProblemDefinition<TEncoding, TEncodedSolution>, IMultiObjectiveProblemDefinition<TEncoding, TEncodedSolution>
|
---|
| 72 | where TEncoding : class, IEncoding<TEncodedSolution>
|
---|
| 73 | where TEncodedSolution : class, IEncodedSolution {
|
---|
[13348] | 74 | protected CompiledMultiObjectiveProblemDefinition() : base() { }
|
---|
| 75 |
|
---|
| 76 | protected CompiledMultiObjectiveProblemDefinition(TEncoding encoding)
|
---|
| 77 | : base(encoding) { }
|
---|
| 78 |
|
---|
[16751] | 79 | #region ISingleObjectiveProblemDefinition<TEncoding,TEncodedSolution> Members
|
---|
[16806] | 80 | public int Objectives => Maximization.Length;
|
---|
[13348] | 81 | public abstract bool[] Maximization { get; }
|
---|
[17225] | 82 | public abstract IReadOnlyList<double[]> BestKnownFront { get; }
|
---|
| 83 | public abstract double[] ReferencePoint { get; }
|
---|
[16751] | 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);
|
---|
[13348] | 87 | #endregion
|
---|
| 88 | }
|
---|
[17225] | 89 | } |
---|