source: branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/CompiledProblemDefinition.cs @ 13348

Last change on this file since 13348 was 13348, checked in by mkommend, 4 years ago

#2521: Refactored single-objective programmable problem.

File size: 3.5 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 System.Threading;
25using HeuristicLab.Core;
26using HeuristicLab.Optimization;
27
28namespace HeuristicLab.Problems.Programmable {
29  public abstract class CompiledProblemDefinition<TEncoding, TSolution> : IProblemDefinition<TEncoding, TSolution>
30    where TEncoding : class, IEncoding<TSolution>
31    where TSolution : class, ISolution {
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, TSolution> : CompiledProblemDefinition<TEncoding, TSolution>, ISingleObjectiveProblemDefinition<TEncoding, TSolution>
52    where TEncoding : class, IEncoding<TSolution>
53    where TSolution : class, ISolution {
54
55    protected CompiledSingleObjectiveProblemDefinition() : base() { }
56
57    protected CompiledSingleObjectiveProblemDefinition(TEncoding encoding)
58      : base(encoding) { }
59
60    #region ISingleObjectiveProblemDefinition<TEncoding,TSolution> Members
61    public abstract bool Maximization { get; }
62    public abstract double Evaluate(TSolution individual, IRandom random);
63    public abstract void Analyze(TSolution[] individuals, double[] qualities, ResultCollection results, IRandom random);
64    public abstract IEnumerable<TSolution> GetNeighbors(TSolution individual, IRandom random);
65    #endregion
66  }
67
68  public abstract class CompiledMultiObjectiveProblemDefinition<TEncoding, TSolution> : CompiledProblemDefinition<TEncoding, TSolution>, IMultiObjectiveProblemDefinition<TEncoding, TSolution>
69    where TEncoding : class, IEncoding<TSolution>
70    where TSolution : class, ISolution {
71
72    protected CompiledMultiObjectiveProblemDefinition() : base() { }
73
74    protected CompiledMultiObjectiveProblemDefinition(TEncoding encoding)
75      : base(encoding) { }
76
77    #region ISingleObjectiveProblemDefinition<TEncoding,TSolution> Members
78    public abstract bool[] Maximization { get; }
79    public abstract double[] Evaluate(TSolution individual, IRandom random);
80    public abstract void Analyze(TSolution[] individuals, double[][] qualities, ResultCollection results, IRandom random);
81    public abstract IEnumerable<TSolution> GetNeighbors(TSolution individual, IRandom random);
82    #endregion
83  }
84}
Note: See TracBrowser for help on using the repository browser.