Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/22/10 22:58:43 (15 years ago)
Author:
abeham
Message:

Added move operators for real encoding and test functions #890

Location:
trunk/sources/HeuristicLab.Problems.TestFunctions/3.3
Files:
17 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/SumSquaresEvaluator.cs

    r3161 r3187  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
     23using HeuristicLab.Core;
     24using HeuristicLab.Data;
     25using HeuristicLab.Encodings.RealVectorEncoding;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2527
    26 namespace HeuristicLab.TestFunctions {
     28namespace HeuristicLab.Problems.TestFunctions {
    2729  /// <summary>
    2830  /// Sum Squares Function<br/>
     
    3032  /// Optimum: 0.0 at (0.0, 0.0, ..., 0.0)
    3133  /// </summary>
    32   public class SumSquaresEvaluator : TestFunctionEvaluatorBase {
    33     /// <inheritdoc select="summary"/>
    34     public override string Description {
    35       get { return
    36 @"Sum Squares Function
    37 
    38 Domain:  [-10.0 , 10.0]^n
    39 Optimum: 0.0 at (0.0, 0.0, ..., 0.0)";
    40           }
     34  [Item("SumSquaresEvaluator", "Evaluates the sum squares function on a given point. The optimum of this function is 0 at the origin.")]
     35  [StorableClass]
     36  public class SumSquaresEvaluator : SingleObjectiveTestFunctionProblemEvaluator {
     37    /// <summary>
     38    /// Returns false as the Rosenbrock function is a minimization problem.
     39    /// </summary>
     40    public override bool Maximization {
     41      get { return false; }
     42    }
     43    /// <summary>
     44    /// Gets the optimum function value (0).
     45    /// </summary>
     46    public override double BestKnownQuality {
     47      get { return 0; }
     48    }
     49    /// <summary>
     50    /// Gets the lower and upper bound of the function.
     51    /// </summary>
     52    public override DoubleMatrix Bounds {
     53      get { return new DoubleMatrix(new double[,] { { -10, 10 } }); }
     54    }
     55    /// <summary>
     56    /// Gets the minimum problem size (1).
     57    /// </summary>
     58    public override int MinimumProblemSize {
     59      get { return 1; }
     60    }
     61    /// <summary>
     62    /// Gets the (theoretical) maximum problem size (2^31 - 1).
     63    /// </summary>
     64    public override int MaximumProblemSize {
     65      get { return int.MaxValue; }
    4166    }
    4267
     
    4671    /// <param name="point">N-dimensional point for which the test function should be evaluated.</param>
    4772    /// <returns>The result value of the Sum Squares function at the given point.</returns>
    48     public static double Apply(double[] point) {
     73    public static double Apply(RealVector point) {
    4974      double result = 0;
    5075      for (int i = 0; i < point.Length; i++) {
     
    6085    /// <param name="point">N-dimensional point for which the test function should be evaluated.</param>
    6186    /// <returns>The result value of the Sum Squares function at the given point.</returns>
    62     protected override double EvaluateFunction(double[] point) {
     87    protected override double EvaluateFunction(RealVector point) {
    6388      return Apply(point);
    6489    }
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/HeuristicLab.Problems.TestFunctions-3.3.csproj

    r3170 r3187  
    9595    <Compile Include="Evaluators\SingleObjectiveTestFunctionProblemEvaluator.cs" />
    9696    <Compile Include="Evaluators\SphereEvaluator.cs" />
     97    <Compile Include="Evaluators\SumSquaresEvaluator.cs" />
    9798    <Compile Include="Evaluators\ZakharovEvaluator.cs" />
    9899    <Compile Include="HeuristicLabProblemsTestFunctionsPlugin.cs" />
     100    <Compile Include="Interfaces\ISingleObjectiveTestFunctionAdditiveMoveEvaluator.cs" />
     101    <Compile Include="Interfaces\ISingleObjectiveTestFunctionMoveEvaluator.cs" />
    99102    <Compile Include="Interfaces\ISingleObjectiveTestFunctionProblemEvaluator.cs" />
    100103    <Compile Include="Interfaces\ISingleObjectiveTestFunctionProblemSolutionsVisualizer.cs" />
     104    <Compile Include="MoveEvaluators\AckleyAdditiveMoveEvaluator.cs" />
     105    <Compile Include="MoveEvaluators\BealeAdditiveMoveEvaluator.cs" />
     106    <Compile Include="MoveEvaluators\BoothAdditiveMoveEvaluator.cs" />
     107    <Compile Include="MoveEvaluators\ZakharovAdditiveMoveEvaluator.cs" />
     108    <Compile Include="MoveEvaluators\SumSquaresAdditiveMoveEvaluator.cs" />
     109    <Compile Include="MoveEvaluators\SphereAdditiveMoveEvaluator.cs" />
     110    <Compile Include="MoveEvaluators\SchwefelAdditiveMoveEvaluator.cs" />
     111    <Compile Include="MoveEvaluators\MatyasAdditiveMoveEvaluator.cs" />
     112    <Compile Include="MoveEvaluators\RosenbrockAdditiveMoveEvaluator.cs" />
     113    <Compile Include="MoveEvaluators\RastriginAdditiveMoveEvaluator.cs" />
     114    <Compile Include="MoveEvaluators\LevyAdditiveMoveEvaluator.cs" />
     115    <Compile Include="MoveEvaluators\GriewangkAdditiveMoveEvaluator.cs" />
     116    <Compile Include="MoveEvaluators\AdditiveMoveEvaluator.cs" />
     117    <Compile Include="MoveEvaluators\RealVectorAdditiveMoveWrapper.cs" />
    101118    <Compile Include="SingleObjectiveTestFunctionProblem.cs" />
    102119    <None Include="HeuristicLab.snk" />
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r3182 r3187  
    123123      set { BestKnownQualityParameter.Value = value; }
    124124    }
    125     private List<IRealVectorOperator> operators;
     125    private List<IOperator> operators;
    126126    public IEnumerable<IOperator> Operators {
    127       get { return operators.Cast<IOperator>(); }
     127      get { return operators; }
    128128    }
    129129    #endregion
     
    197197    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
    198198      ParameterizeEvaluator();
     199      UpdateMoveEvaluators();
    199200      Maximization.Value = Evaluator.Maximization;
    200201      BoundsParameter.Value = Evaluator.Bounds;
     
    226227        Bounds[e.Value, 0] = Bounds[e.Value, 1] - 0.1;
    227228    }
    228     private void BoundsParameter_NameChanged(object sender, EventArgs e) {
    229       ParameterizeOperators();
     229    private void MoveGenerator_AdditiveMoveParameter_ActualNameChanged(object sender, EventArgs e) {
     230      string name = ((ILookupParameter<AdditiveMove>)sender).ActualName;
     231      foreach (IAdditiveRealVectorMoveOperator op in Operators.OfType<IAdditiveRealVectorMoveOperator>()) {
     232        op.AdditiveMoveParameter.ActualName = name;
     233      }
    230234    }
    231235    #endregion
     
    237241      ProblemSizeParameter.ValueChanged += new EventHandler(ProblemSizeParameter_ValueChanged);
    238242      ProblemSize.ValueChanged += new EventHandler(ProblemSize_ValueChanged);
    239       BoundsParameter.NameChanged += new EventHandler(BoundsParameter_NameChanged);
    240243      BoundsParameter.ValueChanged += new EventHandler(BoundsParameter_ValueChanged);
    241244      Bounds.ToStringChanged += new EventHandler(Bounds_ToStringChanged);
     
    248251    }
    249252    private void InitializeOperators() {
    250       operators = new List<IRealVectorOperator>();
     253      operators = new List<IOperator>();
    251254      if (ApplicationManager.Manager != null) {
    252         operators.AddRange(ApplicationManager.Manager.GetInstances<IRealVectorOperator>());
     255        foreach (IRealVectorOperator op in ApplicationManager.Manager.GetInstances<IRealVectorOperator>())
     256          operators.Add(op);
     257        UpdateMoveEvaluators();
    253258        ParameterizeOperators();
    254259      }
    255       //InitializeMoveGenerators();
    256     }
    257     /*private void InitializeMoveGenerators() {
    258       foreach (ITwoOptPermutationMoveOperator op in Operators.OfType<ITwoOptPermutationMoveOperator>()) {
     260      InitializeMoveGenerators();
     261    }
     262    private void InitializeMoveGenerators() {
     263      foreach (IAdditiveRealVectorMoveOperator op in Operators.OfType<IAdditiveRealVectorMoveOperator>()) {
    259264        if (op is IMoveGenerator) {
    260           op.TwoOptMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_TwoOptMoveParameter_ActualNameChanged);
     265          op.AdditiveMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_AdditiveMoveParameter_ActualNameChanged);
    261266        }
    262267      }
    263       foreach (IThreeOptPermutationMoveOperator op in Operators.OfType<IThreeOptPermutationMoveOperator>()) {
    264         if (op is IMoveGenerator) {
    265           op.ThreeOptMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_ThreeOptMoveParameter_ActualNameChanged);
    266         }
    267       }
    268     }*/
     268    }
     269    private void UpdateMoveEvaluators() {
     270      if (ApplicationManager.Manager != null) {
     271        foreach (ISingleObjectiveTestFunctionMoveEvaluator op in Operators.OfType<ISingleObjectiveTestFunctionMoveEvaluator>().ToList())
     272          operators.Remove(op);
     273        foreach (ISingleObjectiveTestFunctionMoveEvaluator op in ApplicationManager.Manager.GetInstances<ISingleObjectiveTestFunctionMoveEvaluator>())
     274          if (op.EvaluatorType == Evaluator.GetType()) {
     275            operators.Add(op);
     276          }
     277        ParameterizeOperators();
     278        OnOperatorsChanged();
     279      }
     280    }
    269281    private void ParameterizeSolutionCreator() {
    270282      SolutionCreator.LengthParameter.Value = new IntValue(ProblemSize.Value);
     
    289301        op.BoundsParameter.ActualName = BoundsParameter.Name;
    290302      }
    291       /*foreach (IPermutationMoveOperator op in Operators.OfType<IPermutationMoveOperator>()) {
    292         op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
    293       }
    294       foreach (ITSPPathMoveEvaluator op in Operators.OfType<ITSPPathMoveEvaluator>()) {
    295         op.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
    296         op.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
    297         op.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
    298       }*/
     303      foreach (IRealVectorMoveOperator op in Operators.OfType<IRealVectorMoveOperator>()) {
     304        op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
     305      }
     306      foreach (IRealVectorMoveGenerator op in Operators.OfType<IRealVectorMoveGenerator>()) {
     307        op.BoundsParameter.ActualName = BoundsParameter.Name;
     308      }
     309      foreach (ISingleObjectiveTestFunctionAdditiveMoveEvaluator op in Operators.OfType<ISingleObjectiveTestFunctionAdditiveMoveEvaluator>()) {
     310        op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     311        op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
     312      }
    299313    }
    300314    #endregion
Note: See TracChangeset for help on using the changeset viewer.