Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Operators/SingleObjectiveEvaluatorBase.cs @ 885

Last change on this file since 885 was 801, checked in by vdorfer, 16 years ago

Created API documentation for HeuristicLab.Operators namespace (#331)

File size: 2.9 KB
RevLine 
[2]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.Text;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27
28namespace HeuristicLab.Operators {
[801]29  /// <summary>
30  /// Calculates the quality of a solution candidate.
31  /// </summary>
[2]32  public abstract class SingleObjectiveEvaluatorBase : OperatorBase {
[801]33    /// <summary>
34    /// Initializes a new instance of <see cref="SingleObjectiveEvaluatorBase"/> with one variable info
35    /// (<c>Quality</c>).
36    /// </summary>
[2]37    public SingleObjectiveEvaluatorBase()
38      : base() {
39      AddVariableInfo(new VariableInfo("Quality", "Quality value", typeof(DoubleData), VariableKind.New));
40    }
41
[801]42    /// <summary>
43    /// Evaluates the quality of a solution candidate.
44    /// </summary>
45    /// <remarks>Creates a new variable with the calculated quality if it not already exists, and
46    /// injects it in the given <paramref name="scope"/> if it is not a local one.</remarks>
47    /// <param name="scope">The scope where to evaluate the quality.</param>
48    /// <returns><c>null</c>.</returns>
[2]49    public override IOperation Apply(IScope scope) {
50      double qualityValue = Evaluate(scope);
51      DoubleData quality = GetVariableValue<DoubleData>("Quality", scope, false, false);
52      if (quality == null) {
53        quality = new DoubleData(qualityValue);
54        IVariableInfo qualityInfo = GetVariableInfo("Quality");
55        if (qualityInfo.Local)
56          AddVariable(new Variable(qualityInfo.ActualName, quality));
57        else
[77]58          scope.AddVariable(new Variable(scope.TranslateName(qualityInfo.FormalName), quality));
[2]59      } else {
60        quality.Data = qualityValue;
61      }
62      return null;
63    }
64
[801]65    /// <summary>
66    /// Calculates the quality of a solution candidate in the given <paramref name="scope"/>.
67    /// </summary>
68    /// <param name="scope">The scope where to calculate the quality.</param>
69    /// <returns>A double value that indicates the quality.</returns>
[2]70    protected abstract double Evaluate(IScope scope);
71  }
72}
Note: See TracBrowser for help on using the repository browser.