Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Operators.Metaprogramming/IntRangeVariableInjector.cs @ 1181

Last change on this file since 1181 was 1167, checked in by vdorfer, 16 years ago

Created API documentation for HeuristicLab.Operators.Metaprogramming and HeuristicLab.Logging namespace and changed a comment in HeuristicLab.Core namespace(#331)

File size: 3.3 KB
RevLine 
[489]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.Operators.Metaprogramming {
[1167]30  /// <summary>
31  /// Injects a new integer variable into the current scope being in a specified range.
32  /// </summary>
[489]33  public class IntRangeVariableInjector: OperatorBase {
[1167]34    /// <inheritdoc select="summary"/>
[489]35    public override string Description {
36      get { return "TASK."; }
37    }
38
[1167]39    /// <summary>
40    /// Initializes a new instance of <see cref="IntRangeVariableInjector"/> with four variable infos
41    /// (<c>VariableInjector</c>, <c>VariableName</c>, <c>Min</c> and <c>Max</c>).
42    /// </summary>
[489]43    public IntRangeVariableInjector()
44      : base() {
45      AddVariableInfo(new VariableInfo("VariableInjector", "The combined operator that should hold the generated variable injector", typeof(CombinedOperator), VariableKind.New));
46      AddVariableInfo(new VariableInfo("VariableName", "Name of the variable that should be injected", typeof(StringData), VariableKind.In));
47      AddVariableInfo(new VariableInfo("Min", "Minimal value of the injected variable", typeof(IntData), VariableKind.In));
48      AddVariableInfo(new VariableInfo("Max", "Maximal value of the injected variable", typeof(IntData), VariableKind.In));
49    }
50
[1167]51    /// <summary>
52    /// Injects a new integer variable in the given <paramref name="scope"/>.
53    /// </summary>
54    /// <param name="scope">The current scope where to inject the variable.</param>
55    /// <returns><c>null</c>.</returns>
[489]56    public override IOperation Apply(IScope scope) {
57      int min = GetVariableValue<IntData>("Min", scope, true).Data;
58      int max = GetVariableValue<IntData>("Max", scope, true).Data;
59      string variableName = GetVariableValue<StringData>("VariableName", scope, true).Data;
60
61      for(int i = min; i < max; i++) {
62        Scope subScope = new Scope(variableName + "<-" + i);
63
64        CombinedOperator combOp = new CombinedOperator();
65        VariableInjector varInjector = new VariableInjector();
66        varInjector.AddVariable(new Variable(variableName, new IntData(i)));
67
68        combOp.OperatorGraph.AddOperator(varInjector);
69        combOp.OperatorGraph.InitialOperator = varInjector;
70
71        subScope.AddVariable(new Variable(scope.TranslateName("VariableInjector"), combOp));
72        scope.AddSubScope(subScope);
73      }
74      return null;
75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.