Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone3/sources/HeuristicLab.Selection/3.3/StochasticSelectorBase.cs @ 4483

Last change on this file since 4483 was 1530, checked in by gkronber, 16 years ago

Moved source files of plugins Hive ... Visualization.Test into version-specific sub-folders. #576

File size: 3.3 KB
Line 
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;
27using HeuristicLab.Operators;
28
29namespace HeuristicLab.Selection {
30  /// <summary>
31  /// Base class for all selectors that use a random number generator.
32  /// </summary>
33  public abstract class StochasticSelectorBase : SelectorBase {
34    /// <summary>
35    /// Initializes a new instance of <see cref="StochasticSelectorBase"/> with two variable infos
36    /// (<c>Random</c> and <c>Selected</c>).
37    /// </summary>
38    public StochasticSelectorBase()
39      : base() {
40      AddVariableInfo(new VariableInfo("Random", "Pseudo random number generator", typeof(IRandom), VariableKind.In));
41      AddVariableInfo(new VariableInfo("Selected", "Number of selected sub-scopes", typeof(IntData), VariableKind.In));
42    }
43
44    /// <summary>
45    /// Copies or moves randomly chosen sub scopes from the given <paramref name="source"/> to the specified
46    /// <paramref name="target"/>.
47    /// </summary>
48    /// <remarks>Calls <see cref="Select(HeuristicLab.Core.IRandom, HeuristicLab.Core.IScope, int,
49    /// HeuristicLab.Core.IScope, bool)"/></remarks>
50    /// <param name="source">The source scope from where to copy/move the sub scopes.</param>
51    /// <param name="target">The target scope where to add the sub scopes.</param>
52    /// <param name="copySelected">Boolean flag whether the sub scopes shall be moved or copied.</param>
53    protected sealed override void Select(IScope source, IScope target, bool copySelected) {
54      IRandom random = GetVariableValue<IRandom>("Random", source, true);
55      IntData selected = GetVariableValue<IntData>("Selected", source, true);
56
57      Select(random, source, selected.Data, target, copySelected);
58    }
59
60    /// <summary>
61    /// Copies or moves randomly chosen sub scopes from the given <paramref name="source"/> to the specified
62    /// <paramref name="target"/>.
63    /// </summary>
64    /// <param name="random">The random number generator.</param>
65    /// <param name="source">The source scope from where to copy/move the sub scopes.</param>
66    /// <param name="selected">The number of sub scopes to copy/move.</param>
67    /// <param name="target">The target scope where to add the sub scopes.</param>
68    /// <param name="copySelected">Boolean flag whether the sub scopes shall be moved or copied.</param>
69    protected abstract void Select(IRandom random, IScope source, int selected, IScope target, bool copySelected);
70  }
71}
Note: See TracBrowser for help on using the repository browser.