[11484] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12012] | 3 | * Copyright (C) 2002-2015 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;
|
---|
[11949] | 25 | using HeuristicLab.Optimization;
|
---|
[11485] | 26 |
|
---|
[11484] | 27 | namespace HeuristicLab.Problems.Programmable {
|
---|
[13345] | 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 {
|
---|
[11739] | 33 | get { return encoding; }
|
---|
[13345] | 34 | internal set {
|
---|
[11739] | 35 | if (value == null) throw new ArgumentNullException("The encoding must not be null.");
|
---|
| 36 | encoding = value;
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
[11484] | 39 |
|
---|
| 40 | public dynamic vars { get; set; }
|
---|
| 41 | public abstract void Initialize();
|
---|
[11485] | 42 |
|
---|
[11768] | 43 | protected CompiledProblemDefinition() { }
|
---|
[13345] | 44 | protected CompiledProblemDefinition(TEncoding encoding)
|
---|
[11768] | 45 | : base() {
|
---|
[11739] | 46 | Encoding = encoding;
|
---|
| 47 | }
|
---|
[11484] | 48 | }
|
---|
[13348] | 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);
|
---|
[13361] | 64 |
|
---|
| 65 | public bool IsBetter(double quality, double bestQuality) {
|
---|
| 66 | return Maximization ? quality > bestQuality : quality < bestQuality;
|
---|
| 67 | }
|
---|
[13348] | 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 | }
|
---|
[11484] | 87 | }
|
---|