#region License Information /* HeuristicLab * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Text; using HeuristicLab.Core; using HeuristicLab.Data; namespace HeuristicLab.TestFunctions { /// /// Injects the necessary variables for optimizing a test function /// public class TestFunctionInjector : OperatorBase { /// public override string Description { get { return @"Injects the necessary variables for optimizing a test function"; } } /// /// Gets or sets the boolean flag whether it is an optimization problem or not. /// public bool Maximization { get { return GetVariable("Maximization").GetValue().Data; } set { GetVariable("Maximization").Value = new BoolData(value); } } /// /// Gets or sets the lower bound. /// public double LowerBound { get { return GetVariable("LowerBound").GetValue().Data; } set { GetVariable("LowerBound").Value = new DoubleData(value); } } /// /// Gets or sets the upper bound. /// public double UpperBound { get { return GetVariable("UpperBound").GetValue().Data; } set { GetVariable("UpperBound").Value = new DoubleData(value); } } /// /// Gets or sets the dimension. /// public int Dimension { get { return GetVariable("Dimension").GetValue().Data; } set { GetVariable("Dimension").Value = new IntData(value); } } /// /// Initializes a new instance of with four variable infos /// (Maximization, LowerBound, UpperBound and Dimension). /// public TestFunctionInjector() : base() { AddVariable(new Variable("Maximization", new BoolData(false))); AddVariable(new Variable("LowerBound", new DoubleData(-32.76))); AddVariable(new Variable("UpperBound", new DoubleData(32.76))); AddVariable(new Variable("Dimension", new IntData(2))); } /// /// Injects the necessary variables for optimizing a test function. /// /// The scope where to inject the variables. /// null. public override IOperation Apply(IScope scope) { scope.AddVariable((IVariable)GetVariable("Maximization").Clone()); scope.AddVariable((IVariable)GetVariable("LowerBound").Clone()); scope.AddVariable((IVariable)GetVariable("UpperBound").Clone()); scope.AddVariable((IVariable)GetVariable("Dimension").Clone()); return null; } /// /// Creates a new instance of to represent the current /// instance visually. /// /// The newly created view as . public override IView CreateView() { return new TestFunctionInjectorView(this); } } }