Changeset 5009


Ignore:
Timestamp:
12/01/10 20:37:36 (11 years ago)
Author:
cneumuel
Message:

#1215 worked on metaoptimization

Location:
branches/HeuristicLab.MetaOptimization
Files:
4 added
1 deleted
20 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs

    r4997 r5009  
    55using HeuristicLab.Core;
    66using HeuristicLab.PluginInfrastructure;
     7using HeuristicLab.Parameters;
    78using HeuristicLab.Problems.MetaOptimization;
    89using HeuristicLab.Data;
    910using System;
     11using System.Threading;
     12using HeuristicLab.Random;
     13using HeuristicLab.Optimization;
    1014
    1115namespace HeuristicLab.MetaOptimization.Test {
    1216  class Program {
     17    private static int metaAlgorithmPopulationSize = 20;
     18    private static int metaAlgorithmMaxGenerations = 100;
     19
     20    private static int baseAlgorithmPopulationSize = 20;
     21    private static int baseAlgorithmMaxGenerations = 30;
     22
    1323    static void Main(string[] args) {
    1424      //TestIntSampling();
     
    1727      GeneticAlgorithm baseLevelAlgorithm = new GeneticAlgorithm();
    1828      MetaOptimizationProblem metaOptimizationProblem = new MetaOptimizationProblem();
     29      GeneticAlgorithm metaLevelAlgorithm = GetMetaAlgorithm(metaOptimizationProblem);
     30
     31      IValueConfiguration algorithmVc = SetupAlgorithm(baseLevelAlgorithm, metaOptimizationProblem);
     32
     33      Console.WriteLine("Press enter to start");
     34      Console.ReadLine();
     35      TestConfiguration(algorithmVc, baseLevelAlgorithm);
     36
     37      Console.WriteLine("Press enter to start");
     38      Console.ReadLine();
     39      TestOptimization(metaLevelAlgorithm);
     40
     41      //TestMemoryLeak(metaLevelAlgorithm);
     42
     43      Console.ReadLine();
     44    }
     45
     46    private static void TestMemoryLeak(GeneticAlgorithm metaLevelAlgorithm) {
     47      IValueConfiguration algorithmVc = ((MetaOptimizationProblem)metaLevelAlgorithm.Problem).AlgorithmParameterConfiguration;
     48
     49      Console.WriteLine("Starting Memory Test...");
     50      Console.ReadLine();
     51
     52      for (int i = 0; i < 1000; i++) {
     53        var clone = algorithmVc.Clone();
     54      }
     55
     56      Console.WriteLine("Finished. Now GC...");
     57      Console.ReadLine();
     58
     59      GC.Collect();
     60
     61      Console.WriteLine("Finished!");
     62      Console.ReadLine();
     63    }
     64
     65    private static GeneticAlgorithm GetMetaAlgorithm(MetaOptimizationProblem metaOptimizationProblem) {
     66      GeneticAlgorithm metaLevelAlgorithm = new GeneticAlgorithm();
     67      metaLevelAlgorithm.PopulationSize.Value = metaAlgorithmPopulationSize;
     68      metaLevelAlgorithm.MaximumGenerations.Value = metaAlgorithmMaxGenerations;
     69
     70      metaLevelAlgorithm.Problem = metaOptimizationProblem;
     71      metaLevelAlgorithm.Engine = new SequentialEngine.SequentialEngine();
     72      return metaLevelAlgorithm;
     73    }
     74
     75    private static IValueConfiguration SetupAlgorithm(GeneticAlgorithm baseLevelAlgorithm, MetaOptimizationProblem metaOptimizationProblem) {
     76      baseLevelAlgorithm.Problem = new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() { ProblemSize = new IntValue(2000) };
     77      baseLevelAlgorithm.PopulationSize.Value = baseAlgorithmPopulationSize;
     78      baseLevelAlgorithm.MaximumGenerations.Value = baseAlgorithmMaxGenerations;
     79
    1980      metaOptimizationProblem.Algorithm = baseLevelAlgorithm;
    2081      IValueConfiguration algorithmVc = metaOptimizationProblem.AlgorithmParameterConfiguration;
    21 
    22       //ConfigurePopulationSize(algorithmVc);
     82      metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem());
     83
     84      ConfigurePopulationSize(algorithmVc);
    2385      ConfigureMutationRate(algorithmVc);
    24 
    25       GeneticAlgorithm metaLevelAlgorithm = new GeneticAlgorithm();
    26       metaLevelAlgorithm.PopulationSize.Value = 10;
    27 
     86      ConfigureMutationOperator(algorithmVc);
     87      return algorithmVc;
     88    }
     89
     90    private static void TestConfiguration(IValueConfiguration algorithmVc, GeneticAlgorithm baseLevelAlgorithm) {
     91      IRandom rand = new MersenneTwister();
    2892      // set random values
    2993      for (int i = 0; i < 10; i++) {
    3094        IValueConfiguration clonedVc = (IValueConfiguration)algorithmVc.Clone();
    31         clonedVc.Randomize();
    32         clonedVc.Parameterize();
     95        clonedVc.Randomize(rand);
     96        clonedVc.Parameterize((GeneticAlgorithm)clonedVc.ActualValue.Value);
    3397        GeneticAlgorithm newAlg = (GeneticAlgorithm)clonedVc.ActualValue.Value;
    34         //Console.WriteLine(string.Format("PopSize: original: {0}, randomized: {1}", baseLevelAlgorithm.PopulationSize, newAlg.PopulationSize));
     98        Console.WriteLine(string.Format("PopSize: original: {0}, randomized: {1}", baseLevelAlgorithm.PopulationSize, newAlg.PopulationSize));
    3599        Console.WriteLine(string.Format("MutRate: original: {0}, randomized: {1}", baseLevelAlgorithm.MutationProbability, newAlg.MutationProbability));
     100        Console.WriteLine(string.Format("MutOp: original: {0}, randomized: {1}", baseLevelAlgorithm.Mutator, newAlg.Mutator));
    36101      }
    37102
     
    39104      for (int i = 0; i < 10; i++) {
    40105        IValueConfiguration clonedVc = (IValueConfiguration)algorithmVc.Clone();
    41         clonedVc.Mutate();
    42         clonedVc.Parameterize();
     106        clonedVc.Mutate(rand);
     107        clonedVc.Parameterize((GeneticAlgorithm)clonedVc.ActualValue.Value);
    43108        GeneticAlgorithm newAlg = (GeneticAlgorithm)clonedVc.ActualValue.Value;
    44         //Console.WriteLine(string.Format("PopSize: original: {0}, mutated: {1}", baseLevelAlgorithm.PopulationSize, newAlg.PopulationSize));
     109        Console.WriteLine(string.Format("PopSize: original: {0}, mutated: {1}", baseLevelAlgorithm.PopulationSize, newAlg.PopulationSize));
    45110        Console.WriteLine(string.Format("MutRate: original: {0}, mutated: {1}", baseLevelAlgorithm.MutationProbability, newAlg.MutationProbability));
     111        Console.WriteLine(string.Format("MutOp: original: {0}, mutated: {1}", baseLevelAlgorithm.Mutator, newAlg.Mutator));
    46112      }
    47113
     
    49115      for (int i = 0; i < 10; i++) {
    50116        IValueConfiguration clonedVc1 = (IValueConfiguration)algorithmVc.Clone();
    51         clonedVc1.Randomize();
    52         clonedVc1.Parameterize();
     117        clonedVc1.Randomize(rand);
     118        clonedVc1.Parameterize(baseLevelAlgorithm);
    53119
    54120        IValueConfiguration clonedVc2 = (IValueConfiguration)algorithmVc.Clone();
     
    58124        var popSizeBefore = first.PopulationSize.Value;
    59125        var mutRateBefore = first.MutationProbability.Value;
    60         clonedVc1.Cross(clonedVc2);
    61         clonedVc1.Parameterize();
    62 
    63         //Console.WriteLine(string.Format("PopSize: first: {0}, second: {1}, crossed: {2}", popSizeBefore, second.PopulationSize, first.PopulationSize));
     126        var mutOpBefore = first.Mutator;
     127
     128        clonedVc1.Cross(clonedVc2, rand);
     129        clonedVc1.Parameterize((GeneticAlgorithm)clonedVc2.ActualValue.Value);
     130
     131        Console.WriteLine(string.Format("PopSize: first: {0}, second: {1}, crossed: {2}", popSizeBefore, second.PopulationSize, first.PopulationSize));
    64132        Console.WriteLine(string.Format("MutRate: first: {0}, second: {1}, crossed: {2}", mutRateBefore, second.MutationProbability, first.MutationProbability));
    65       }
    66 
    67       Debugger.Break();
     133        Console.WriteLine(string.Format("MutRate: first: {0}, second: {1}, crossed: {2}", mutOpBefore, second.Mutator, first.Mutator));
     134      }
     135    }
     136
     137    private static void ConfigureMutationOperator(IValueConfiguration algorithmVc) {
     138      var mutationOperator = algorithmVc.ParameterConfigurations.Where(x => x.Name == "Mutator").SingleOrDefault();
     139      mutationOperator.Optimize = true;
     140
     141      // uncheck multiMutator to avoid Michalewicz issue
     142      var multiMutator = mutationOperator.ValueConfigurations.Where(x => x.ActualValue.Value.ItemName.StartsWith("Multi")).SingleOrDefault();
     143      if (multiMutator != null) {
     144        mutationOperator.ValueConfigurations.SetItemCheckedState(multiMutator, false);
     145      }
    68146    }
    69147
     
    86164      mutationRateVc.RangeConstraint.UpperBound = new PercentValue(1.0);
    87165      mutationRateVc.RangeConstraint.StepSize = new PercentValue(0.01);
     166    }
     167
     168    private static void TestOptimization(GeneticAlgorithm metaLevelAlgorithm) {
     169      metaLevelAlgorithm.Start();
     170      do {
     171        Thread.Sleep(1000);
     172        Console.Clear();
     173        try {
     174          foreach (var result in metaLevelAlgorithm.Results) {
     175            Console.WriteLine(result.ToString());
     176            if (result.Name == "Population") {
     177              RunCollection rc = (RunCollection)result.Value;
     178              var orderedRuns = rc.OrderBy(x => x.Results["BestQuality"]);
     179              foreach (IRun run in orderedRuns) {
     180                Console.WriteLine("Q: {0} PoSi: {1} MuRa: {2} MuOp: {3}",
     181                  ((DoubleValue)run.Results["BestQuality"]).Value.ToString("0.00").PadLeft(4, ' '),
     182                  ((IntValue)run.Parameters["PopulationSize"]).Value.ToString().PadLeft(3, ' '),
     183                  ((DoubleValue)run.Parameters["MutationProbability"]).Value.ToString("0.00").PadRight(3, ' '),
     184                  run.Parameters["Mutator"]);
     185              }
     186            }
     187          }
     188        }
     189        catch { }
     190      } while (metaLevelAlgorithm.ExecutionState != ExecutionState.Stopped);
     191
     192      Console.WriteLine("Finished");
    88193    }
    89194
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/RootValueConfigurationView.cs

    r4982 r5009  
    1616  /// </summary>
    1717  [View("ParameterConfiguration View")]
    18   [Content(typeof(RootValueConfiguration), true)]
     18  [Content(typeof(ParameterConfigurationTree), true)]
    1919  public partial class RootValueConfigurationView : ItemView {
    2020    /// <summary>
     
    2323    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
    2424    /// No own data storage present.</remarks>
    25     public new RootValueConfiguration Content {
    26       get { return (RootValueConfiguration)base.Content; }
     25    public new ParameterConfigurationTree Content {
     26      get { return (ParameterConfigurationTree)base.Content; }
    2727      set { base.Content = value; }
    2828    }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestParameterConfigurationAnalyzer.cs

    r4839 r5009  
    77using HeuristicLab.Parameters;
    88using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     9using System.Collections.Generic;
     10using System;
    911
    1012namespace HeuristicLab.Problems.MetaOptimization {
     
    1214  /// TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.
    1315  /// </summary>
    14   [Item("BestQualityAnalyzer", "TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")]
     16  [Item("BestParameterConfigurationAnalyzer", "TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")]
    1517  [StorableClass]
    1618  public sealed class BestParameterConfigurationAnalyzer : SingleSuccessorOperator, IAnalyzer {
    1719    // Wagner: Spezielle View für die Lösungen (ParameterConfigurations): So wie bei Runs: die zu Optimierenden Parameter(-werte) der besten solution anzeigen
    1820
    19     public ScopeTreeLookupParameter<IParameterConfiguration> ParameterVectorParameter {
    20       get { return (ScopeTreeLookupParameter<IParameterConfiguration>)Parameters["ParameterConfiguration"]; }
     21    public ScopeTreeLookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter {
     22      get { return (ScopeTreeLookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; }
    2123    }
    2224    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
    2325      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    2426    }
    25     public LookupParameter<IParameterConfiguration> BestSolutionParameter {
    26       get { return (LookupParameter<IParameterConfiguration>)Parameters["BestSolution"]; }
     27    public LookupParameter<IRun> BestSolutionParameter {
     28      get { return (LookupParameter<IRun>)Parameters["BestSolution"]; }
    2729    }
    2830    public ValueLookupParameter<ResultCollection> ResultsParameter {
     
    3234      get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    3335    }
    34     public LookupParameter<IParameterConfiguration> BestKnownSolutionParameter {
    35       get { return (LookupParameter<IParameterConfiguration>)Parameters["BestKnownSolution"]; }
     36    public LookupParameter<IRun> BestKnownSolutionParameter {
     37      get { return (LookupParameter<IRun>)Parameters["BestKnownSolution"]; }
     38    }
     39    public LookupParameter<RunCollection> PopulationParameter {
     40      get { return (LookupParameter<RunCollection>)Parameters["Population"]; }
    3641    }
    3742
    3843    public BestParameterConfigurationAnalyzer() : base() {
    39       Parameters.Add(new ScopeTreeLookupParameter<IParameterConfiguration>("ParameterConfiguration", "TODO The TSP solutions given in path representation from which the best solution should be analyzed."));
     44      Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "TODO The TSP solutions given in path representation from which the best solution should be analyzed."));
    4045      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "TODO The qualities of the TSP solutions which should be analyzed."));
    41       Parameters.Add(new LookupParameter<IParameterConfiguration>("BestSolution", "TODO The best TSP solution."));
     46      Parameters.Add(new LookupParameter<IRun>("BestSolution", "TODO The best TSP solution."));
    4247      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "TODO The result collection where the best TSP solution should be stored."));
    4348      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "TODO The quality of the best known solution of this TSP instance."));
    44       Parameters.Add(new LookupParameter<IParameterConfiguration>("BestKnownSolution", "TODO The best known solution of this TSP instance."));
     49      Parameters.Add(new LookupParameter<IRun>("BestKnownSolution", "TODO The best known solution of this TSP instance."));
     50      Parameters.Add(new LookupParameter<RunCollection>("Population", "TODO The best known solution of this TSP instance."));
    4551    }
    4652
     
    5662      ResultCollection results = ResultsParameter.ActualValue;
    5763      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
    58       ItemArray<IParameterConfiguration> parameterVectors = ParameterVectorParameter.ActualValue;
     64      ItemArray<ParameterConfigurationTree> parameterConfigurations = ParameterConfigurationParameter.ActualValue;
    5965
    6066      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
    6167
     68      EngineAlgorithm bestAlg = ((EngineAlgorithm)((ParameterConfigurationTree)parameterConfigurations[i]).ActualValue.Value);
     69      Run bestRun = new Run(bestAlg);
     70
    6271      if (bestKnownQuality == null || qualities[i].Value < bestKnownQuality.Value) {
    6372        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
    64         BestKnownSolutionParameter.ActualValue = (IParameterConfiguration)parameterVectors[i].Clone();
     73        BestKnownSolutionParameter.ActualValue = bestRun;
    6574      }
    6675
    67       // todo: more
     76      IRun best = BestSolutionParameter.ActualValue;
     77      if (best == null) {
     78        BestSolutionParameter.ActualValue = bestRun;
     79        results.Add(new Result("Best Parameter Settings", bestRun));
     80      } else {
     81        BestSolutionParameter.ActualValue = bestRun;
     82        results["Best Parameter Settings"].Value = bestRun;
     83      }
     84
     85      RunCollection rc = new RunCollection();
     86     
     87      foreach (ParameterConfigurationTree pc in parameterConfigurations.OrderBy(x => x.Quality.Value*-1)) {
     88        IAlgorithm alg = (IAlgorithm)pc.ActualValue.Value;
     89        alg.StoreAlgorithmInEachRun = false;
     90        IRun run = new Run(alg);
     91        rc.Add(run);
     92      }
     93      if (PopulationParameter.ActualValue == null) {
     94        PopulationParameter.ActualValue = rc;
     95        results.Add(new Result("Population", rc));
     96      } else {
     97        PopulationParameter.ActualValue = rc;
     98        results["Population"].Value = rc;
     99      }
     100      GC.Collect();
    68101
    69102      return base.Apply();
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Creators/RandomParameterConfigurationCreator.cs

    r4997 r5009  
    2020      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
    2121    }
    22     public ILookupParameter<IValueConfiguration> ValueConfigurationParameter {
    23       get { return (ILookupParameter<IValueConfiguration>)Parameters["ValueConfiguration"]; }
     22    public ILookupParameter<ParameterConfigurationTree> InitialParameterConfigurationParameter {
     23      get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["InitialParameterConfigurationTree"]; }
    2424    }
    2525
    26     public ILookupParameter<IValueConfiguration> NewValueConfigurationParameter {
    27       get { return (ILookupParameter<IValueConfiguration>)Parameters["NewValueConfiguration"]; }
     26    public ILookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter {
     27      get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; }
    2828    }
    2929
     
    3333    public RandomParameterConfigurationCreator() : base() {
    3434      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used to initialize the new random permutation."));
    35       Parameters.Add(new LookupParameter<IValueConfiguration>("ValueConfiguration", "The new random parameter set."));
     35      Parameters.Add(new LookupParameter<ParameterConfigurationTree>("InitialParameterConfigurationTree", "The parameter configuration tree on which the new solution will be based on."));
     36      Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "The new random parameter set."));
    3637    }
    3738    public override IDeepCloneable Clone(Cloner cloner) {
     
    4041
    4142    public override IOperation Apply() {
    42       NewValueConfigurationParameter.ActualValue = (IValueConfiguration)ValueConfigurationParameter.ActualValue.Clone();
    43       NewValueConfigurationParameter.ActualValue.Randomize();
    44       NewValueConfigurationParameter.ActualValue.Parameterize();
     43      ParameterConfigurationParameter.ActualValue = (ParameterConfigurationTree)InitialParameterConfigurationParameter.ActualValue.Clone();
     44      ParameterConfigurationParameter.ActualValue.Randomize(RandomParameter.ActualValue);
    4545      return base.Apply();
    4646    }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/Crossovers/ParameterConfigurationCrossover.cs

    r4997 r5009  
    1313  ///
    1414  /// </summary>
    15   [Item("ParameterVectorCrossover", "TODO")]
     15  [Item("ParameterConfigurationCrossover", "TODO")]
    1616  [StorableClass]
    1717  public class ParameterConfigurationCrossover : SingleSuccessorOperator, IParameterConfigurationOperator, ICrossover {
     
    2323      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
    2424    }
    25     public ILookupParameter<ItemArray<IParameterConfiguration>> ParentsParameter {
    26       get { return (ScopeTreeLookupParameter<IParameterConfiguration>)Parameters["Parents"]; }
     25    public ILookupParameter<ItemArray<IValueConfiguration>> ParentsParameter {
     26      get { return (ScopeTreeLookupParameter<IValueConfiguration>)Parameters["Parents"]; }
    2727    }
    28     public ILookupParameter<IParameterConfiguration> ChildParameter {
    29       get { return (ILookupParameter<IParameterConfiguration>)Parameters["Child"]; }
     28    public ILookupParameter<IValueConfiguration> ChildParameter {
     29      get { return (ILookupParameter<IValueConfiguration>)Parameters["Child"]; }
    3030    }
    3131
     
    4747      : base() {
    4848      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic crossover operators."));
    49       Parameters.Add(new ScopeTreeLookupParameter<IParameterConfiguration>("Parents", "The parent vectors which should be crossed."));
    50       ParentsParameter.ActualName = "ParameterConfiguration";
    51       Parameters.Add(new LookupParameter<IParameterConfiguration>("Child", "The child vector resulting from the crossover."));
    52       ChildParameter.ActualName = "ParameterConfiguration";
     49      Parameters.Add(new ScopeTreeLookupParameter<IValueConfiguration>("Parents", "The parent vectors which should be crossed."));
     50      ParentsParameter.ActualName = "ParameterConfigurationTree";
     51      Parameters.Add(new LookupParameter<IValueConfiguration>("Child", "The child vector resulting from the crossover."));
     52      ChildParameter.ActualName = "ParameterConfigurationTree";
    5353    }
    5454    public override IDeepCloneable Clone(Cloner cloner) {
     
    5757
    5858    public override IOperation Apply() {
     59      IValueConfiguration child1 = (IValueConfiguration)ParentsParameter.ActualValue[0].Clone();
     60      IValueConfiguration child2 = (IValueConfiguration)ParentsParameter.ActualValue[1];
    5961
    60       IParameterConfiguration child = (IParameterConfiguration)ParentsParameter.ActualValue[0].Clone();
    61       // todo
    62       //for (int i = 0; i < child.Parameters.Count; i++) {
    63       //  if (child.Parameters[i].Parameter.DataType == typeof(IntValue)) {
    64       //    child.Parameters[i].Parameter.ActualValue = CrossInteger(ParentsParameter.ActualValue[0].Parameters[i], ParentsParameter.ActualValue[1].Parameters[i]);
    65       //  }
    66       //}
    67 
    68       this.ChildParameter.ActualValue = child;
     62      child1.Cross(child2, RandomParameter.ActualValue);
     63      this.ChildParameter.ActualValue = child1;
    6964      return base.Apply();
    7065    }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ParameterConfigurations/ParameterConfiguration.cs

    r4997 r5009  
    66using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    77using HeuristicLab.PluginInfrastructure;
     8using HeuristicLab.Parameters;
     9using HeuristicLab.Data;
     10using System.Collections;
    811
    912namespace HeuristicLab.Problems.MetaOptimization {
     
    4750    }
    4851
     52    [Storable]
    4953    protected Type parameterDataType;
    5054    public Type ParameterDataType {
     
    5256    }
    5357
    54     protected IEnumerable<IItem> validValues;
    55     public IEnumerable<IItem> ValidValues {
     58    [Storable]
     59    protected IItemSet<IItem> validValues;
     60    public IItemSet<IItem> ValidValues {
    5661      get { return validValues; }
    5762      protected set {
     
    6267    }
    6368
     69    [Storable]
    6470    protected Type valueDataType;
    6571    public Type ValueDataType {
     
    6874    }
    6975
     76    [Storable]
    7077    protected ICheckedValueConfigurationCollection valueConfigurations;
    7178    public ICheckedValueConfigurationCollection ValueConfigurations {
     
    8087    }
    8188
     89    [Storable]
    8290    protected int actualValueConfigurationIndex = 0;
    8391
     92    [Storable]
    8493    protected ConstrainedValue actualValue;
    8594    public ConstrainedValue ActualValue {
     
    8998   
    9099    // store parameter reference only for name/description/image/...
    91     private IValueParameter parameter;
     100    //[Storable]
     101    //private IValueParameter parameter;
    92102
    93103    #region Constructors and Cloning
     
    95105      this.ParameterName = parameterName;
    96106      this.parameterDataType = valueParameter.GetType();
    97       this.parameter = valueParameter;
     107      //this.parameter = valueParameter;
    98108      this.valueDataType = valueParameter.DataType;
    99       this.validValues = GetValidValues();
     109      this.validValues = GetValidValues(valueParameter);
    100110      this.ValueConfigurations = new CheckedValueConfigurationCollection(this.valueDataType);
    101111      this.ActualValue = new ConstrainedValue(valueParameter.Value, valueParameter.DataType);
     
    111121      this.parameterName = original.ParameterName;
    112122      this.parameterDataType = original.parameterDataType;
    113       this.parameter = cloner.Clone(original.parameter);
     123      //this.parameter = cloner.Clone(original.parameter);
    114124      this.valueDataType = original.ValueDataType;
    115       this.validValues = original.ValidValues.Select(x => cloner.Clone(x));
    116       this.ValueConfigurations = cloner.Clone(original.ValueConfigurations);
     125      this.validValues = cloner.Clone(original.ValidValues);
     126      this.valueConfigurations = cloner.Clone(original.ValueConfigurations);
    117127      this.ActualValue = cloner.Clone(original.ActualValue);
    118128      this.optimize = original.optimize;
     129      if (this.valueConfigurations != null) RegisterValueConfigurationEvents();
    119130    }
    120131    public override IDeepCloneable Clone(Cloner cloner) {
    121132      return new ParameterConfiguration(this, cloner);
     133    }
     134    [StorableHook(HookType.AfterDeserialization)]
     135    private void AfterDeserialization() {
     136      if (this.valueConfigurations != null) RegisterValueConfigurationEvents();
    122137    }
    123138    #endregion
     
    147162    }
    148163
    149     private IEnumerable<IItem> GetValidValues() {
    150       return ApplicationManager.Manager.GetInstances(valueDataType).Select(x => (IItem)x).OrderBy(x => x.ItemName).ToArray();
     164    private IItemSet<IItem> GetValidValues(IValueParameter parameter) {
     165      if (IsSubclassOfRawGeneric(typeof(OptionalConstrainedValueParameter<>), parameter.GetType())) {
     166        var x = (IEnumerable)parameter.GetType().GetProperty("ValidValues").GetValue(parameter, new object[] { });
     167        return new ItemSet<IItem>(x.Cast<IItem>());
     168      } else {
     169        return new ItemSet<IItem>(ApplicationManager.Manager.GetInstances(valueDataType).Select(x => (IItem)x).OrderBy(x => x.ItemName));
     170      }
     171    }
     172
     173    private static bool IsSubclassOfRawGeneric(Type generic, Type toCheck) {
     174      while (toCheck != typeof(object)) {
     175        var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck;
     176        if (generic == cur) {
     177          return true;
     178        }
     179        toCheck = toCheck.BaseType;
     180      }
     181      return false;
    151182    }
    152183
     
    167198    }
    168199    public virtual string Description {
    169       get { return parameter.Description; }
     200      get { return base.ItemDescription; }
    170201      set { throw new NotSupportedException(); }
    171202    }
     
    177208    }
    178209    public override string ItemDescription {
    179       get { return parameter != null ? parameter.Description : base.ItemDescription; }
     210      //get { return parameter != null ? parameter.Description : base.ItemDescription; }
     211      get { return base.ItemDescription; }
    180212    }
    181213    public override System.Drawing.Image ItemImage {
    182       get { return parameter != null ? parameter.ItemImage : base.ItemImage; }
     214      //get { return parameter != null ? parameter.ItemImage : base.ItemImage; }
     215      get { return base.ItemImage; }
    183216    }
    184217    public override string ItemName {
    185       get { return parameter != null ?parameter.ItemName : base.ItemName; }
     218      //get { return parameter != null ?parameter.ItemName : base.ItemName; }
     219      get { return base.ItemName; }
    186220    }
    187221    #endregion
     
    235269    }
    236270
    237     public void Parameterize() {
    238       this.parameter.ActualValue = this.ActualValue.Value;
    239     }
    240 
    241     public void Randomize() {
    242       if (Optimize) {
    243         Random rand = new Random(); // todo: use global random
    244         actualValueConfigurationIndex = rand.Next(ValueConfigurations.CheckedItems.Count());
    245         this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).Randomize();
     271    public void Parameterize(IValueParameter parameter) {
     272      parameter.ActualValue = this.ActualValue.Value;
     273    }
     274
     275    public void Randomize(IRandom random) {
     276      if (Optimize) {
     277        actualValueConfigurationIndex = random.Next(ValueConfigurations.CheckedItems.Count());
     278        this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).Randomize(random);
    246279        this.ActualValue = this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ActualValue;
    247280      }
    248281    }
    249282
    250     public void Mutate() {
     283    public void Mutate(IRandom random) {
    251284      if (Optimize) {
    252285        foreach (IValueConfiguration vc in this.ValueConfigurations.CheckedItems) {
    253           vc.Mutate();
    254         }
     286          vc.Mutate(random);
     287        }
     288        actualValueConfigurationIndex = random.Next(ValueConfigurations.CheckedItems.Count());
    255289        this.ActualValue = this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ActualValue;
    256       }
    257     }
    258 
    259     public void Cross(IOptimizable other) {
     290        this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).Mutate(random);
     291      }
     292    }
     293
     294    public void Cross(IOptimizable other, IRandom random) {
    260295      if (Optimize) {
    261296        IParameterConfiguration otherPc = (IParameterConfiguration)other;
    262297        for (int i = 0; i < this.ValueConfigurations.Count; i++) {
    263           this.ValueConfigurations.ElementAt(i).Cross(otherPc.ValueConfigurations.ElementAt(i));
     298          this.ValueConfigurations.ElementAt(i).Cross(otherPc.ValueConfigurations.ElementAt(i), random);
    264299        }
    265300        this.ActualValue = this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ActualValue;
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/RangeConstraints/ConstrainedValue.cs

    r4997 r5009  
    3838      this.value.ToStringChanged -= new EventHandler(value_ToStringChanged);
    3939    }
    40    
     40
     41    #region constructors and cloning
    4142    public ConstrainedValue() { }
     43    [StorableConstructor]
     44    protected ConstrainedValue(bool deserializing) : base(deserializing) { }
    4245    public ConstrainedValue(IItem value, Type valueDataType) {
    4346      this.Value = value;
     
    5154      return new ConstrainedValue(this, cloner);
    5255    }
     56    [StorableHook(HookType.AfterDeserialization)]
     57    private void AfterDeserialization() {
     58      if (this.value != null) RegisterEvents();
     59    }
     60    #endregion
    5361
    5462    void value_ToStringChanged(object sender, EventArgs e) {
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/RangeConstraints/DoubleValueRange.cs

    r4997 r5009  
    55using HeuristicLab.Data;
    66using HeuristicLab.Common;
     7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     8using HeuristicLab.Core;
    79
    810namespace HeuristicLab.Problems.MetaOptimization {
     11  [StorableClass]
    912  public class DoubleValueRange : Range<DoubleValue> {
    1013
    1114    public DoubleValueRange(DoubleValue lowerBound, DoubleValue upperBound, DoubleValue stepSize) : base(lowerBound, upperBound, stepSize) { }
    1215    public DoubleValueRange() { }
     16    [StorableConstructor]
     17    protected DoubleValueRange(bool deserializing) : base(deserializing) { }
    1318    protected DoubleValueRange(DoubleValueRange original, Cloner cloner) : base(original, cloner) { }
    1419    public override IDeepCloneable Clone(Cloner cloner) {
     
    1621    }
    1722
    18     public override DoubleValue GetRandomValue() {
    19       Random rand = new Random(); // todo: use common random
     23    public override DoubleValue GetRandomValue(IRandom random) {
    2024      double val;
    2125      do {
    22         val = Math.Round((rand.NextDouble() * (UpperBound.Value - LowerBound.Value) + LowerBound.Value) / StepSize.Value, 0) * StepSize.Value;
     26        val = Math.Round((random.NextDouble() * (UpperBound.Value - LowerBound.Value) + LowerBound.Value) / StepSize.Value, 0) * StepSize.Value;
    2327      } while (val < LowerBound.Value || val > UpperBound.Value);
    2428      return new DoubleValue(val);
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/RangeConstraints/IntValueRange.cs

    r4997 r5009  
    55using HeuristicLab.Data;
    66using HeuristicLab.Common;
     7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     8using HeuristicLab.Core;
    79
    810namespace HeuristicLab.Problems.MetaOptimization {
     11  [StorableClass]
    912  public class IntValueRange : Range<IntValue> {
    1013
    1114    public IntValueRange(IntValue lowerBound, IntValue upperBound, IntValue stepSize) : base(lowerBound, upperBound, stepSize) { }
    1215    public IntValueRange() { }
     16    [StorableConstructor]
     17    protected IntValueRange(bool deserializing) : base(deserializing) { }
    1318    protected IntValueRange(IntValueRange original, Cloner cloner) : base(original, cloner) { }
    1419    public override IDeepCloneable Clone(Cloner cloner) {
     
    1621    }
    1722
    18     public override IntValue GetRandomValue() {
    19       Random rand = new Random(); // todo: use common random
     23    public override IntValue GetRandomValue(IRandom random) {
    2024      int val;
    2125      do {
    22         val = rand.Next(LowerBound.Value / StepSize.Value, UpperBound.Value / StepSize.Value + 1) * StepSize.Value;
     26        val = random.Next(LowerBound.Value / StepSize.Value, UpperBound.Value / StepSize.Value + 1) * StepSize.Value;
    2327      } while (val < LowerBound.Value || val > UpperBound.Value);
    2428      return new IntValue(val);
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/RangeConstraints/PercentValueRange.cs

    r4997 r5009  
    55using HeuristicLab.Data;
    66using HeuristicLab.Common;
     7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     8using HeuristicLab.Core;
    79
    810namespace HeuristicLab.Problems.MetaOptimization {
     11  [StorableClass]
    912  public class PercentValueRange : Range<PercentValue> {
    1013
    1114    public PercentValueRange(PercentValue lowerBound, PercentValue upperBound, PercentValue stepSize) : base(lowerBound, upperBound, stepSize) { }
    1215    public PercentValueRange() { }
     16    [StorableConstructor]
     17    protected PercentValueRange(bool deserializing) : base(deserializing) { }
    1318    protected PercentValueRange(PercentValueRange original, Cloner cloner) : base(original, cloner) { }
    1419    public override IDeepCloneable Clone(Cloner cloner) {
     
    1621    }
    1722
    18     public override PercentValue GetRandomValue() {
    19       Random rand = new Random(); // todo: use common random
     23    public override PercentValue GetRandomValue(IRandom random) {
    2024      double val;
    2125      do {
    22         val = Math.Round((rand.NextDouble() * (UpperBound.Value - LowerBound.Value) + LowerBound.Value) / StepSize.Value, 0) * StepSize.Value;
     26        val = Math.Round((random.NextDouble() * (UpperBound.Value - LowerBound.Value) + LowerBound.Value) / StepSize.Value, 0) * StepSize.Value;
    2327      } while (val < LowerBound.Value || val > UpperBound.Value);
    2428      return new PercentValue(val);
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/RangeConstraints/Range.cs

    r4997 r5009  
    9292      this.StepSize = cloner.Clone(original.StepSize);
    9393    }
    94     #endregion
    9594
    9695    [StorableHook(HookType.AfterDeserialization)]
     
    106105      }
    107106    }
     107    #endregion
    108108
    109109    #region Events
     
    166166    }
    167167    public bool Validate(string value, out string errorMessage) {
    168       // TODO: check that upper is larger than lower
     168      // TODO: check that upper is larger than lower and that stepsize < upper-lower
    169169      T lower = (T)lowerBound.Clone();
    170170      T upper = (T)upperBound.Clone();
     
    191191    #endregion
    192192
     193    public abstract T GetRandomValue(IRandom random);
    193194
    194 
    195     public abstract T GetRandomValue();
    196 
    197     #region IRange Members
    198 
    199 
    200     IItem IRange.GetRandomValue() {
    201       return GetRandomValue();
     195    IItem IRange.GetRandomValue(IRandom random) {
     196      return GetRandomValue(random);
    202197    }
    203 
    204     #endregion
    205198  }
    206199}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ValueConfigurations/CheckedValueConfigurationCollection.cs

    r4982 r5009  
    4343      return new CheckedValueConfigurationCollection(this, cloner);
    4444    }
     45    [StorableHook(HookType.AfterDeserialization)]
     46    private void AfterDeserialization() {
     47      RegisterEvents();
     48    }
    4549
    4650    private void RegisterEvents() {
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ValueConfigurations/ValueConfiguration.cs

    r4997 r5009  
    99namespace HeuristicLab.Problems.MetaOptimization {
    1010  // TODO: ItemName/Descr, storability
     11  [StorableClass]
    1112  public class ValueConfiguration : Item, IValueConfiguration {
     13    [Storable]
    1214    protected bool isOptimizable;
    1315    public bool IsOptimizable {
     
    2123    }
    2224
     25    [Storable]
    2326    protected bool optimize;
    2427    public bool Optimize {
     
    3942    }
    4043
     44    [Storable]
    4145    protected IItemCollection<IParameterConfiguration> parameterConfigurations = new ItemCollection<IParameterConfiguration>();
    4246    public IItemCollection<IParameterConfiguration> ParameterConfigurations {
     
    4549    }
    4650
     51    [Storable]
    4752    protected ConstrainedValue actualValue;
    4853    public ConstrainedValue ActualValue {
     
    5964    }
    6065
     66    [Storable]
    6167    protected IRange rangeConstraint;
    6268    public IRange RangeConstraint {
     
    97103      return new ValueConfiguration(this, cloner);
    98104    }
     105    [StorableHook(HookType.AfterDeserialization)]
     106    private void AfterDeserialization() {
     107      RegisterEvents();
     108    }
    99109    #endregion
    100110
     
    181191      }
    182192    }
    183    
    184     public void Parameterize() {
     193
     194    public void Parameterize(IParameterizedItem item) {
    185195      foreach (IParameterConfiguration pc in this.ParameterConfigurations) {
    186         pc.Parameterize();
    187       }
    188     }
    189 
    190     public void Randomize() {
     196        pc.Parameterize((IValueParameter)item.Parameters[pc.ParameterName]);
     197      }
     198    }
     199
     200    public void Randomize(IRandom random) {
    191201      if (Optimize) {
    192202        if (rangeConstraint != null) {
    193           this.actualValue.Value = rangeConstraint.GetRandomValue();
     203          this.actualValue.Value = rangeConstraint.GetRandomValue(random);
    194204        } else {
    195205          foreach (IParameterConfiguration pc in this.ParameterConfigurations) {
    196             pc.Randomize();
    197           }
    198         }
    199       }
    200     }
    201 
    202     public void Mutate() {
     206            pc.Randomize(random);
     207          }
     208        }
     209      }
     210    }
     211
     212    public void Mutate(IRandom random) {
    203213      if (Optimize) {
    204214        if (rangeConstraint != null) {
    205           Random rand = new Random(); // todo: use common random
    206           // mutate every other value. todo: use some kind of mutation operator which is exchangable
    207           if(rand.NextDouble() > 0.5)
    208             this.actualValue.Value = rangeConstraint.GetRandomValue();
     215          if (random.NextDouble() > 0.5)
     216            this.actualValue.Value = rangeConstraint.GetRandomValue(random);
    209217        } else {
    210218          foreach (IParameterConfiguration pc in this.ParameterConfigurations) {
    211             pc.Mutate();
    212           }
    213         }
    214       }
    215     }
    216 
    217     public void Cross(IOptimizable other) {
     219            pc.Mutate(random);
     220          }
     221        }
     222      }
     223    }
     224
     225    public void Cross(IOptimizable other, IRandom random) {
    218226      if (Optimize) {
    219227        IValueConfiguration otherVc = (IValueConfiguration)other;
     
    233241              this.actualValue.Value = new BoolValue(false);
    234242            } else {
    235               Random rand = new Random(); // todo: use common random
    236               if(rand.NextDouble() > 0.5)
     243              if (random.NextDouble() > 0.5)
    237244                this.actualValue.Value = new BoolValue(true);
    238245              else
     
    244251        } else {
    245252          for (int i = 0; i < this.ParameterConfigurations.Count; i++) {
    246             this.ParameterConfigurations.ElementAt(i).Cross(otherVc.ParameterConfigurations.ElementAt(i));
     253            this.ParameterConfigurations.ElementAt(i).Cross(otherVc.ParameterConfigurations.ElementAt(i), random);
    247254          }
    248255        }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/MetaOptimizationEvaluator.cs

    r4997 r5009  
    2323      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
    2424    }
    25     public ILookupParameter<IAlgorithm> AlgorithmParameter {
    26       get { return (ILookupParameter<IAlgorithm>)Parameters["Algorithm"]; }
     25    public ILookupParameter<EngineAlgorithm> AlgorithmParameter {
     26      get { return (ILookupParameter<EngineAlgorithm>)Parameters["Algorithm"]; }
    2727    }
    28     public ILookupParameter<IItemList<IProblem>> ProblemsParameter {
    29       get { return (ILookupParameter<IItemList<IProblem>>)Parameters["Problems"]; }
     28    public ILookupParameter<IItemList<ISingleObjectiveProblem>> ProblemsParameter {
     29      get { return (ILookupParameter<IItemList<ISingleObjectiveProblem>>)Parameters["Problems"]; }
    3030    }
    31     public ILookupParameter<IValueConfiguration> ParameterConfigurationParameter {
    32       get { return (ILookupParameter<IValueConfiguration>)Parameters["ValueConfiguration"]; }
     31    public ILookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter {
     32      get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; }
    3333    }
    3434    public ValueParameter<IntValue> RepetitionsParameter {
     
    4141    }
    4242
    43     public MetaOptimizationEvaluator() : base() {
     43    public MetaOptimizationEvaluator()
     44      : base() {
    4445      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The evaluated quality of the ParameterVector."));
    45       Parameters.Add(new LookupParameter<IAlgorithm>("Algorithm", "Missing description."));
    46       Parameters.Add(new LookupParameter<IItemList<IProblem>>("Problems", "Missing description."));
    47       Parameters.Add(new LookupParameter<IValueConfiguration>("ValueConfiguration", "Missing description."));
     46      Parameters.Add(new LookupParameter<EngineAlgorithm>("Algorithm", "Missing description."));
     47      Parameters.Add(new LookupParameter<IItemList<ISingleObjectiveProblem>>("Problems", "Missing description."));
     48      Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "Missing description."));
    4849      Parameters.Add(new ValueParameter<IntValue>(RepetitionsParameterName, "Number of evaluations for one individual.", new IntValue(3)));
    4950    }
     
    6061
    6162    public override IOperation Apply() {
    62       AlgorithmParameter.ActualValue.Prepare();
    63       //ParameterizeAlgorithm();
    64       //ParameterConfigurationParameter.ActualValue.Parameterize(AlgorithmParameter.ActualValue);
     63      EngineAlgorithm algorithm = (EngineAlgorithm)ParameterConfigurationParameter.ActualValue.ActualValue.Value;
     64
     65      // set parameters
     66      ParameterConfigurationParameter.ActualValue.Parameterize(algorithm);
     67
    6568      algorithmStopped = false;
    66       AlgorithmParameter.ActualValue.Stopped += new EventHandler(ActualValue_Stopped);
     69      algorithm.Stopped += new EventHandler(ActualValue_Stopped);
    6770
    6871      double qualitySum = 0;
    6972
    70       foreach (IProblem problem in ProblemsParameter.ActualValue) {
    71         AlgorithmParameter.ActualValue.Problem = problem;
    72         AlgorithmParameter.ActualValue.Start();
    73         while (!algorithmStopped) {
    74           Thread.Sleep(1000); // wait for algorithm to complete; do not rely on Algorithm.ExecutionState here, because change of ExecutionState happens before Run is added (which causes problems because Algorithm might get cloned when its started already)
    75         }
    76         AlgorithmParameter.ActualValue.Stopped -= new EventHandler(ActualValue_Stopped);
    77         qualitySum += ((DoubleValue)AlgorithmParameter.ActualValue.Results["BestQuality"].Value).Value;
     73      //foreach (ISingleObjectiveProblem problem in ProblemsParameter.ActualValue) {
     74      algorithm.Engine = new SequentialEngine.SequentialEngine();
     75      //algorithm.Problem = problem;
     76      algorithm.Prepare();
     77      algorithm.Start();
     78      while (!algorithmStopped) {
     79        Thread.Sleep(1000); // wait for algorithm to complete; do not rely on Algorithm.ExecutionState here, because change of ExecutionState happens before Run is added (which causes problems because Algorithm might get cloned when its started already)
    7880      }
     81      double quality = ((DoubleValue)algorithm.Results["BestQuality"].Value).Value;
     82      ParameterConfigurationParameter.ActualValue.Quality.Value = quality;
     83      qualitySum += quality;
     84      //}
    7985
    80       double qualityAvg = qualitySum / ProblemsParameter.ActualValue.Count;
    81       this.QualityParameter.ActualValue = new DoubleValue(qualityAvg);
     86      algorithm.Stopped -= new EventHandler(ActualValue_Stopped);
     87
     88      //double qualityAvg = qualitySum / ProblemsParameter.ActualValue.Count;
     89      //this.QualityParameter.ActualValue = new DoubleValue(qualityAvg);
     90      this.QualityParameter.ActualValue = new DoubleValue(quality);
    8291
    8392      return base.Apply();
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj

    r4997 r5009  
    7878      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
    7979    </Reference>
     80    <Reference Include="HeuristicLab.SequentialEngine-3.3">
     81      <HintPath>..\..\HeuristicLab.MetaOptimization.Test\bin\Debug\HeuristicLab.SequentialEngine-3.3.dll</HintPath>
     82    </Reference>
    8083    <Reference Include="System" />
    8184    <Reference Include="System.Core" />
     
    9699    <Compile Include="Encodings\RangeConstraints\DoubleValueRange.cs" />
    97100    <Compile Include="Encodings\RangeConstraints\IntValueRange.cs" />
    98     <Compile Include="Encodings\ValueConfigurations\RootValueConfiguration.cs" />
     101    <Compile Include="Encodings\ParameterConfigurationTree.cs" />
    99102    <Compile Include="Encodings\ValueConfigurations\ValueConfiguration.cs" />
    100103    <Compile Include="Encodings\ValueConfigurations\CheckedValueConfigurationCollection.cs" />
     
    112115    <Compile Include="Interfaces\IValueConfiguration.cs" />
    113116    <Compile Include="Encodings\RangeConstraints\Range.cs" />
     117    <Compile Include="Interfaces\IParameterConfigurationManipulator.cs" />
     118    <Compile Include="Manipulators\ParameterConfigurationManipulator.cs" />
    114119    <Compile Include="Properties\AssemblyInfo.cs" />
    115120    <Compile Include="MetaOptimizationProblem.cs" />
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IOptimizable.cs

    r4997 r5009  
    1212    ConstrainedValue ActualValue { get; set; }
    1313
    14     void Parameterize();
    15     void Randomize();
    16     void Mutate();
    17     void Cross(IOptimizable other);
     14    void Randomize(IRandom random);
     15    void Mutate(IRandom random);
     16    void Cross(IOptimizable other, IRandom random);
    1817
    1918    event EventHandler IsOptimizableChanged;
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterConfiguration.cs

    r4997 r5009  
    1010    Type ParameterDataType { get; }
    1111    ICheckedValueConfigurationCollection ValueConfigurations { get; }
    12     IEnumerable<IItem> ValidValues { get; }
     12    IItemSet<IItem> ValidValues { get; }
     13
     14    void Parameterize(IValueParameter parameter);
    1315  }
    1416}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IRange.cs

    r4997 r5009  
    1414    event EventHandler StepSizeChanged;
    1515
    16     IItem GetRandomValue();
     16    IItem GetRandomValue(IRandom random);
    1717  }
    1818
     
    2121    new T UpperBound { get; set; }
    2222    new T StepSize { get; set; }
    23     new T GetRandomValue();
     23    new T GetRandomValue(IRandom random);
    2424  }
    2525}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IValueConfiguration.cs

    r4997 r5009  
    99    event EventHandler ValueChanged;
    1010
     11    void Parameterize(IParameterizedItem item);
    1112  }
    1213}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs

    r4997 r5009  
    3737    private const string AlgorithmParameterName = "Algorithm";
    3838    private const string ProblemsParameterName = "Problems";
    39     private const string AlgorithmParameterConfigurationParameterName = "AlgorithmParameterConfiguration";
    40     private const string ProblemParametersConfigurationParameterName = "ProblemParametersConfiguration";
     39    private const string AlgorithmParameterConfigurationParameterName = "InitialParameterConfigurationTree";
     40    //private const string ProblemParametersConfigurationParameterName = "ProblemParametersConfiguration";
    4141
    4242    #region Parameter Properties
    43     public ValueParameter<IAlgorithm> AlgorithmParameter {
    44       get { return (ValueParameter<IAlgorithm>)Parameters[AlgorithmParameterName]; }
     43    public IValueParameter<EngineAlgorithm> AlgorithmParameter {
     44      get { return (ValueParameter<EngineAlgorithm>)Parameters[AlgorithmParameterName]; }
    4545    }
    46     public ValueParameter<IItemList<ISingleObjectiveProblem>> ProblemsParameter {
     46    public IValueParameter<IItemList<ISingleObjectiveProblem>> ProblemsParameter {
    4747      get { return (ValueParameter<IItemList<ISingleObjectiveProblem>>)Parameters[ProblemsParameterName]; }
    4848    }
    49     public ValueParameter<IValueConfiguration> AlgorithmParameterConfigurationParameter {
    50       get { return (ValueParameter<IValueConfiguration>)Parameters[AlgorithmParameterConfigurationParameterName]; }
     49    public IValueParameter<ParameterConfigurationTree> AlgorithmParameterConfigurationParameter {
     50      get { return (ValueParameter<ParameterConfigurationTree>)Parameters[AlgorithmParameterConfigurationParameterName]; }
    5151    }
    5252    //public ValueParameter<IItemList<IParameterConfiguration>> ProblemParametersConfigurationParameter {
     
    5656
    5757    #region Properties
    58     public IAlgorithm Algorithm {
     58    public EngineAlgorithm Algorithm {
    5959      get { return AlgorithmParameter.Value; }
    6060      set { AlgorithmParameter.Value = value; }
     
    6464      set { ProblemsParameter.Value = value; }
    6565    }
    66     public IValueConfiguration AlgorithmParameterConfiguration {
     66    public ParameterConfigurationTree AlgorithmParameterConfiguration {
    6767      get { return AlgorithmParameterConfigurationParameter.Value; }
    6868      set { AlgorithmParameterConfigurationParameter.Value = value; }
     
    7474    #endregion
    7575
    76     public MetaOptimizationProblem()
    77       : base() {
    78       Parameters.Add(new ValueParameter<IAlgorithm>(AlgorithmParameterName, "The algorithm which's parameters should be optimized."));
    79       Parameters.Add(new ValueParameter<IItemList<IProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ItemList<IProblem>()));
    80       Parameters.Add(new ValueParameter<IValueConfiguration>(AlgorithmParameterConfigurationParameterName, "List of algorithm parameters that should be optimized."));
     76    public MetaOptimizationProblem() : base() {
     77      Parameters.Add(new ValueParameter<EngineAlgorithm>(AlgorithmParameterName, "The algorithm which's parameters should be optimized."));
     78      Parameters.Add(new ValueParameter<IItemList<ISingleObjectiveProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ItemList<ISingleObjectiveProblem>()));
     79      Parameters.Add(new ValueParameter<ParameterConfigurationTree>(AlgorithmParameterConfigurationParameterName, "List of algorithm parameters that should be optimized."));
    8180      //Parameters.Add(new ValueParameter<IItemList<IParameterConfiguration>>(ProblemParametersConfigurationParameterName, "List of problem parameters that should be optimized.", new ItemList<IParameterConfiguration>()));
    8281     
     
    122121    }
    123122    private void ParameterizeEvaluator() {
    124       ((MetaOptimizationEvaluator)Evaluator).ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ValueConfigurationParameter.ActualName;
     123      ((MetaOptimizationEvaluator)Evaluator).ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
    125124    }
    126125    private void ParameterizeAnalyzer() {
     
    152151    }
    153152    void BaseLevelAlgorithmParameter_ValueChanged(object sender, EventArgs e) {
    154       if (Algorithm != null) {
    155         Algorithm.ProblemChanged += new EventHandler(BaseLevelAlgorithm_ProblemChanged);
    156         AlgorithmParameterConfiguration = new RootValueConfiguration(Algorithm, Algorithm.GetType());
    157       }
     153      Algorithm.ProblemChanged += new EventHandler(BaseLevelAlgorithm_ProblemChanged); // when to deregister?
    158154      BaseLevelAlgorithm_ProblemChanged(sender, e);
    159155    }
    160156
    161157    void BaseLevelAlgorithm_ProblemChanged(object sender, EventArgs e) {
    162       //ClearProblemParameters();
    163       //if (Algorithm.Problem != null) {
    164       //  AddProblemParameters();
    165       //}
     158      if (Algorithm != null && Algorithm.Problem != null) {
     159        AlgorithmParameterConfiguration = new ParameterConfigurationTree(Algorithm);
     160      }
    166161    }
    167162    #endregion
Note: See TracChangeset for help on using the changeset viewer.