Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3187 for trunk


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
Files:
26 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearch.cs

    r3145 r3187  
    6565      get { return (ValueParameter<IntValue>)Parameters["MaximumIterations"]; }
    6666    }
     67    private ValueParameter<IntValue> SampleSizeParameter {
     68      get { return (ValueParameter<IntValue>)Parameters["SampleSize"]; }
     69    }
    6770    #endregion
    6871
     
    9194      get { return MaximumIterationsParameter.Value; }
    9295      set { MaximumIterationsParameter.Value = value; }
     96    }
     97    public IntValue SampleSize {
     98      get { return SampleSizeParameter.Value; }
     99      set { SampleSizeParameter.Value = value; }
    93100    }
    94101    private RandomCreator RandomCreator {
     
    113120      Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move."));
    114121      Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000)));
     122      Parameters.Add(new ValueParameter<IntValue>("SampleSize", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators.", new IntValue(100)));
    115123
    116124      RandomCreator randomCreator = new RandomCreator();
     
    158166      ParameterizeMoveMakers();
    159167      UpdateMoveGenerator();
     168      UpdateMoveParameters();
    160169      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    161170      base.OnProblemChanged();
     
    189198        op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
    190199      }
    191       IMoveGenerator oldMoveGenerator = MoveGenerator;
    192200      UpdateMoveGenerator();
    193       if (oldMoveGenerator == MoveGenerator) // in this case MoveGeneratorParameter_ValueChanged did not fire
    194         UpdateMoveParameters();
     201      UpdateMoveParameters();
    195202      ParameterizeMainLoop();
    196203      ParameterizeMoveEvaluators();
  • trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs

    r3145 r3187  
    191191      ParameterizeSolutionsCreator();
    192192      ParameterizeMainLoop();
     193      UpdateMoveGenerator();
     194      UpdateMoveParameters();
    193195      ParameterizeMoveEvaluators();
    194196      ParameterizeMoveMakers();
    195197      ParameterizeMoveGenerators();
    196       UpdateMoveGenerator();
    197198      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    198199      base.OnProblemChanged();
     
    226227        op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
    227228      }
    228       IMultiMoveGenerator oldMoveGenerator = MoveGenerator;
    229229      UpdateMoveGenerator();
    230       if (oldMoveGenerator == MoveGenerator) // in this case MoveGeneratorParameter_ValueChanged did not fire
    231         UpdateMoveParameters();
     230      UpdateMoveParameters();
    232231      ParameterizeMainLoop();
    233232      ParameterizeMoveEvaluators();
  • trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs

    r3145 r3187  
    188188      ParameterizeSolutionsCreator();
    189189      ParameterizeMainLoop();
     190      UpdateMoveGenerator();
     191      UpdateMoveParameters();
    190192      ParameterizeMoveGenerators();
    191193      ParameterizeMoveEvaluator();
    192194      ParameterizeMoveMaker();
    193       UpdateMoveGenerator();
    194195      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    195196      base.OnProblemChanged();
     
    227228        op.MoveTabuParameter.ActualNameChanged += new EventHandler(TabuMoveEvaluator_MoveTabuParameter_ActualNameChanged);
    228229      }
    229       IMoveGenerator oldMoveGenerator = MoveGenerator;
    230230      UpdateMoveGenerator();
    231       if (oldMoveGenerator == MoveGenerator) // in this case MoveGeneratorParameter_ValueChanged did not fire
    232         UpdateMoveParameters();
     231      UpdateMoveParameters();
    233232      ParameterizeMainLoop();
    234233      ParameterizeMoveGenerators();
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj

    r3182 r3187  
    103103    <Compile Include="Crossovers\UniformSomePositionsArithmeticCrossover.cs" />
    104104    <Compile Include="HeuristicLabEncodingsRealVectorEncodingPlugin.cs" />
     105    <Compile Include="Interfaces\IAdditiveRealVectorMoveOperator.cs" />
    105106    <Compile Include="Interfaces\IRealVectorBoundsChecker.cs" />
     107    <Compile Include="Interfaces\IRealVectorMoveGenerator.cs" />
     108    <Compile Include="Interfaces\IRealVectorMoveOperator.cs" />
     109    <Compile Include="Moves\Polynomial\StochasticPolynomialMultiMoveGenerator.cs" />
     110    <Compile Include="Moves\AdditiveMoveMaker.cs" />
     111    <Compile Include="Moves\AdditiveMove.cs" />
     112    <Compile Include="Moves\AdditiveMoveGenerator.cs" />
    106113    <Compile Include="RealVector.cs" />
    107114    <Compile Include="Manipulators\BreederGeneticAlgorithmManipulator.cs" />
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/PolynomialAllPositionManipulator.cs

    r3060 r3187  
    4848    /// </summary>
    4949    /// <remarks>
    50     /// The manipulated value is not restricted by the (possibly) specified lower and upper bounds. Use the <see cref="BoundsChecker"/> to correct the values after performing the mutation.
     50    /// If there are bounds specified the manipulated value is restricted by the given lower and upper bounds.
    5151    /// </remarks>
    5252    public ValueLookupParameter<DoubleValue> MaximumManipulationParameter {
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/PolynomialOnePositionManipulator.cs

    r3060 r3187  
    4747    /// </summary>
    4848    /// <remarks>
    49     /// The manipulated value is not restricted by the (possibly) specified lower and upper bounds. Use the <see cref="BoundsChecker"/> to correct the values after performing the mutation.
     49    /// If there are bounds specified the manipulated value is restricted by the given lower and upper bounds.
    5050    /// </remarks>
    5151    public ValueLookupParameter<DoubleValue> MaximumManipulationParameter {
     
    7373      if (contiguity.Value < 0) throw new ArgumentException("PolynomialOnePositionManipulator: Contiguity value is smaller than 0", "contiguity");
    7474      int index = random.Next(vector.Length);
     75      vector[index] += Apply(random, contiguity.Value) * maxManipulation.Value;
     76    }
     77
     78    public static double Apply(IRandom random, double contiguity) {
    7579      double u = random.NextDouble(), delta = 0;
    7680
    7781      if (u < 0.5) {
    78         delta = Math.Pow(2 * u, 1.0 / (contiguity.Value + 1)) - 1.0;
     82        delta = Math.Pow(2 * u, 1.0 / (contiguity + 1)) - 1.0;
    7983      } else if (u > 0.5) {
    80         delta = 1.0 - Math.Pow(2.0 - 2.0 * u, 1.0 / contiguity.Value + 1);
    81       } else if (u == 0.5) delta = 0;
     84        delta = 1.0 - Math.Pow(2.0 - 2.0 * u, 1.0 / contiguity + 1);
     85      } else delta = 0;
    8286
    83       vector[index] += delta * maxManipulation.Value;
     87      return delta;
    8488    }
    8589
  • 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.