Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.Binary/3.3/BinaryProblem.cs @ 11987

Last change on this file since 11987 was 11987, checked in by abeham, 9 years ago

#2282:

  • Renamed BinaryVectorProblem to BinaryProblem
  • Removed IBinaryVectorProblem interface
  • Derived BinaryProblem from SingleObjectiveBasicProblem
  • Changed bool[] datatype to BinaryVector
File size: 2.0 KB
Line 
1#region License Information
2
3/* HeuristicLab
4 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
5 *
6 * This file is part of HeuristicLab.
7 *
8 * HeuristicLab is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * HeuristicLab is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#endregion
23
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Encodings.BinaryVectorEncoding;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Problems.Binary {
33  [StorableClass]
34  public abstract class BinaryProblem : SingleObjectiveBasicProblem<BinaryVectorEncoding> {
35
36    public virtual int Length {
37      get { return Encoding.Length; }
38      set { Encoding.Length = value; }
39    }
40
41    [StorableConstructor]
42    protected BinaryProblem(bool deserializing) : base(deserializing) { }
43    protected BinaryProblem(BinaryProblem original, Cloner cloner) : base(original, cloner) { }
44    protected BinaryProblem() : base() { }
45
46    public virtual bool IsBetter(double quality, double bestQuality) {
47      return (Maximization && quality > bestQuality || !Maximization && quality < bestQuality);
48    }
49
50    public sealed override double Evaluate(Individual individual, IRandom random) {
51      return Evaluate(individual.BinaryVector(), random);
52    }
53
54    public abstract double Evaluate(BinaryVector vector, IRandom random);
55  }
56}
Note: See TracBrowser for help on using the repository browser.