Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/12/10 11:34:13 (14 years ago)
Author:
cneumuel
Message:

#1215

  • enabled multiple problems
  • enabled n repetitions
  • improved results output
  • reduced memory footprint significantly
  • removed viewhost icons for less screen space waste
Location:
branches/HeuristicLab.MetaOptimization
Files:
13 edited

Legend:

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

    r5023 r5087  
    1717using System.Text;
    1818using HeuristicLab.Selection;
     19using HeuristicLab.Algorithms.EvolutionStrategy;
    1920
    2021namespace HeuristicLab.MetaOptimization.Test {
    2122  class Program {
    22     private static int metaAlgorithmPopulationSize = 40;
     23    private static int metaAlgorithmPopulationSize = 50;
    2324    private static int metaAlgorithmMaxGenerations = 30;
    24 
    25     private static int baseAlgorithmMaxGenerations = 100;
     25    private static int metaProblemRepetitions = 3;
     26
     27    private static int baseAlgorithmMaxGenerations = 250;
    2628
    2729    static void Main(string[] args) {
     30      //TestShorten();
     31
    2832      //TestIntSampling();
    2933      //TestDoubleSampling();
    3034
    3135      GeneticAlgorithm baseLevelAlgorithm = new GeneticAlgorithm();
     36
    3237      MetaOptimizationProblem metaOptimizationProblem = new MetaOptimizationProblem();
    33       GeneticAlgorithm metaLevelAlgorithm = GetMetaAlgorithm(metaOptimizationProblem);
    34 
    35       IValueConfiguration algorithmVc = SetupAlgorithm(baseLevelAlgorithm, metaOptimizationProblem);
     38      ((MetaOptimizationEvaluator)metaOptimizationProblem.Evaluator).Repetitions.Value = metaProblemRepetitions;
     39      GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem);
     40      //EvolutionStrategy metaLevelAlgorithm = GetMetaES(metaOptimizationProblem);
     41
     42      IValueConfiguration algorithmVc = SetupGAAlgorithm(baseLevelAlgorithm, metaOptimizationProblem);
    3643
    3744      //Console.WriteLine("Press enter to start");
    3845      //Console.ReadLine();
    3946      //TestConfiguration(algorithmVc, baseLevelAlgorithm);
    40 
     47     
    4148      //Console.WriteLine("Press enter to start");
    4249      //Console.ReadLine();
     
    6976    }
    7077
    71     private static GeneticAlgorithm GetMetaAlgorithm(MetaOptimizationProblem metaOptimizationProblem) {
     78    private static GeneticAlgorithm GetMetaGA(MetaOptimizationProblem metaOptimizationProblem) {
    7279      GeneticAlgorithm metaLevelAlgorithm = new GeneticAlgorithm();
    7380      metaLevelAlgorithm.PopulationSize.Value = metaAlgorithmPopulationSize;
     
    8390    }
    8491
    85     private static IValueConfiguration SetupAlgorithm(GeneticAlgorithm baseLevelAlgorithm, MetaOptimizationProblem metaOptimizationProblem) {
    86       baseLevelAlgorithm.Problem = new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
    87         Evaluator = new GriewankEvaluator(),
    88         ProblemSize = new IntValue(1000)
    89       };
     92    private static EvolutionStrategy GetMetaES(MetaOptimizationProblem metaOptimizationProblem) {
     93      EvolutionStrategy metaLevelAlgorithm = new EvolutionStrategy();
     94      metaLevelAlgorithm.PopulationSize.Value = metaAlgorithmPopulationSize;
     95      metaLevelAlgorithm.MaximumGenerations.Value = metaAlgorithmMaxGenerations;
     96
     97      metaLevelAlgorithm.Problem = metaOptimizationProblem;
     98      metaLevelAlgorithm.Engine = new SequentialEngine.SequentialEngine();
     99
     100      metaLevelAlgorithm.Mutator = new ParameterConfigurationManipulator();
     101      //metaLevelAlgorithm.MutationProbability.Value = 0.15;
     102
     103      return metaLevelAlgorithm;
     104    }
     105
     106    private static IValueConfiguration SetupGAAlgorithm(GeneticAlgorithm baseLevelAlgorithm, MetaOptimizationProblem metaOptimizationProblem) {
     107      baseLevelAlgorithm.Problem = new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem();
    90108      baseLevelAlgorithm.MaximumGenerations.Value = baseAlgorithmMaxGenerations;
    91109
    92110      metaOptimizationProblem.Algorithm = baseLevelAlgorithm;
    93111      IValueConfiguration algorithmVc = metaOptimizationProblem.AlgorithmParameterConfiguration;
    94       metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem());
     112
     113      metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
     114        Evaluator = new GriewankEvaluator(),
     115        ProblemSize = new IntValue(500)
     116      });
     117      metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
     118        Evaluator = new GriewankEvaluator(),
     119        ProblemSize = new IntValue(1000)
     120      });
    95121
    96122      ConfigurePopulationSize(algorithmVc);
     
    189215          vc.Optimize = true;
    190216          ConfigureTournamentGroupSize(vc);
     217        } else if (vc.ActualValue.ValueDataType == typeof(RandomSelector)) {
     218          selectionOperatorPc.ValueConfigurations.SetItemCheckedState(vc, true);
    191219        } else {
    192           selectionOperatorPc.ValueConfigurations.SetItemCheckedState(vc, false);
     220          selectionOperatorPc.ValueConfigurations.SetItemCheckedState(vc, true);
    193221        }
    194222      }
     
    235263    }
    236264
    237     private static void TestOptimization(GeneticAlgorithm metaLevelAlgorithm) {
     265    private static void TestOptimization(EngineAlgorithm metaLevelAlgorithm) {
    238266      ContentManager.Initialize(new PersistenceContentManager());
    239267      string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Results");
    240       if(!Directory.Exists(path))
     268      if (!Directory.Exists(path))
    241269        Directory.CreateDirectory(path);
    242       string id = DateTime.Now.ToString("MM.dd.yy - HH;mm;ss,ffff");
    243       string resultPath = Path.Combine(path, string.Format("Test - {0} - Result.hl", id));
    244       string outputPath = Path.Combine(path, string.Format("Test - {0} - Console.txt", id));
     270      string id = DateTime.Now.ToString("yyyy.MM.dd - HH;mm;ss,ffff");
     271      string resultPath = Path.Combine(path, string.Format("{0} - Result.hl", id));
     272      string outputPath = Path.Combine(path, string.Format("{0} - Console.txt", id));
     273
    245274
    246275      using (var sw = new StreamWriter(outputPath)) {
     276        sw.AutoFlush = true;
     277
     278        StringBuilder sb1 = new StringBuilder();
     279        sb1.AppendLine(string.Format("Meta.PopulationSize: {0}", metaAlgorithmPopulationSize));
     280        sb1.AppendLine(string.Format("Meta.MaxGenerations: {0}", metaAlgorithmMaxGenerations));
     281        sb1.AppendLine(string.Format("Meta.Repetitions   : {0}", metaProblemRepetitions));
     282        sb1.AppendLine(string.Format("Base.MaxGenerations: {0}", baseAlgorithmMaxGenerations));
     283        sw.WriteLine(sb1.ToString());
     284        Console.WriteLine(sb1.ToString());
     285
    247286        metaLevelAlgorithm.Start();
    248287        int i = 0;
     
    250289        do {
    251290          Thread.Sleep(500);
    252           try {
    253             if (metaLevelAlgorithm.Results.ContainsKey("Generations") && ((IntValue)metaLevelAlgorithm.Results["Generations"].Value).Value != currentGeneration) {
    254               StringBuilder sb = new StringBuilder();
    255               sb.AppendLine(DateTime.Now.ToLongTimeString());
    256               sb.AppendLine("=================================");
    257 
    258               foreach (var result in metaLevelAlgorithm.Results) {
    259                 sb.AppendLine(result.ToString());
    260                 if (result.Name == "Population") {
    261                   RunCollection rc = (RunCollection)result.Value;
    262                   var orderedRuns = rc.OrderBy(x => x.Results["BestQuality"]);
    263                  
    264                   sb.AppendLine("Qality PoSi MutRa Eli GrSi MutOp");
    265                   foreach (IRun run in orderedRuns) {
    266                     sb.AppendLine(string.Format("{0} {1} {2} {3} {4} {5}",
    267                       ((DoubleValue)run.Results["BestQuality"]).Value.ToString("#0.00").PadLeft(7, ' '),
    268                       ((IntValue)run.Parameters["PopulationSize"]).Value.ToString().PadLeft(3, ' ').PadRight(3, ' '),
    269                       ((DoubleValue)run.Parameters["MutationProbability"]).Value.ToString("0.00").PadLeft(5, ' '),
    270                       ((IntValue)run.Parameters["Elites"]).Value.ToString().PadLeft(3, ' '),
    271                       ((TournamentSelector)run.Parameters["Selector"]).GroupSizeParameter.Value.ToString().PadLeft(4, ' '),
    272                       run.Parameters["Mutator"]));
     291          if (metaLevelAlgorithm.Results.ContainsKey("Generations") && ((IntValue)metaLevelAlgorithm.Results["Generations"].Value).Value != currentGeneration) {
     292            while (metaLevelAlgorithm.Results.Count < 3) Thread.Sleep(100);
     293            StringBuilder sb = new StringBuilder();
     294            sb.AppendLine(DateTime.Now.ToLongTimeString());
     295            sb.AppendLine("=================================");
     296
     297            foreach (var result in metaLevelAlgorithm.Results) {
     298              sb.AppendLine(result.ToString());
     299              if (result.Name == "Population") {
     300                RunCollection rc = (RunCollection)result.Value;
     301                var orderedRuns = rc.OrderBy(x => x.Results["RunsAverageQuality"]);
     302
     303                sb.AppendLine("Qual.  PoSi MutRa Eli GrSi MutOp");
     304                foreach (IRun run in orderedRuns) {
     305                  string selector;
     306                  if (run.Parameters["Selector"] is TournamentSelector) {
     307                    selector = string.Format("{0} ({1})", run.Parameters["Selector"].ToString(), ((TournamentSelector)run.Parameters["Selector"]).GroupSizeParameter.Value.ToString());
     308                  } else {
     309                    selector = string.Format("{0}", run.Parameters["Selector"].ToString());
    273310                  }
     311
     312                  sb.AppendLine(string.Format("{0} {1} {2} {3} {4} {5}",
     313                    ((DoubleValue)run.Results["RunsAverageQuality"]).Value.ToString("#0.00").PadLeft(7, ' '),
     314                    ((IntValue)run.Parameters["PopulationSize"]).Value.ToString().PadLeft(3, ' ').PadRight(3, ' '),
     315                    ((DoubleValue)run.Parameters["MutationProbability"]).Value.ToString("0.00").PadLeft(5, ' '),
     316                    ((IntValue)run.Parameters["Elites"]).Value.ToString().PadLeft(3, ' '),
     317                    Shorten(selector, 20).PadRight(20, ' '),
     318                    run.Parameters["Mutator"].ToString()));
    274319                }
    275               } // foreach
    276               Console.Clear();
    277               Console.WriteLine(sb.ToString());
    278               sw.WriteLine(sb.ToString());
    279               sw.Flush();
    280               currentGeneration = ((IntValue)metaLevelAlgorithm.Results["Generations"].Value).Value;
    281             } // if
    282             if (i % 30 == 0) GC.Collect();
    283             i++;
    284           }
    285           catch { }
     320              }
     321            } // foreach
     322            Console.Clear();
     323            Console.WriteLine(sb.ToString());
     324            sw.WriteLine(sb.ToString());
     325            currentGeneration = ((IntValue)metaLevelAlgorithm.Results["Generations"].Value).Value;
     326          } // if
     327          if (i % 30 == 0) GC.Collect();
     328          i++;
    286329        } while (metaLevelAlgorithm.ExecutionState != ExecutionState.Stopped);
    287330      }
     
    290333      Console.WriteLine("Storing...");
    291334
    292       ContentManager.Save(metaLevelAlgorithm, resultPath, true);
     335      ContentManager.Save((IStorableContent)metaLevelAlgorithm, resultPath, true);
    293336      Console.WriteLine("Finished");
     337    }
     338
     339    private static void TestShorten() {
     340      int n = 8;
     341      Console.WriteLine(Shorten("1", n));
     342      Console.WriteLine(Shorten("12", n));
     343      Console.WriteLine(Shorten("123", n));
     344      Console.WriteLine(Shorten("1234", n));
     345      Console.WriteLine(Shorten("12345", n));
     346      Console.WriteLine(Shorten("123456", n));
     347      Console.WriteLine(Shorten("1234567", n));
     348      Console.WriteLine(Shorten("12345678", n));
     349      Console.WriteLine(Shorten("123456789", n));
     350      Console.WriteLine(Shorten("1234567890", n));
     351      Console.WriteLine(Shorten("12345678901", n));
     352    }
     353
     354    private static string Shorten(string s, int n) {
     355      string placeholder = "..";
     356      if (s.Length <= n) return s;
     357      int len = n / 2 - placeholder.Length / 2;
     358      string start = s.Substring(0, len);
     359      string end = s.Substring(s.Length - len, len);
     360      return start + placeholder + end;
    294361    }
    295362
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/OptimizableView.Designer.cs

    r4981 r5087  
    4141      this.viewHost.Size = new System.Drawing.Size(513, 345);
    4242      this.viewHost.TabIndex = 0;
     43      this.viewHost.ViewsLabelVisible = false;
    4344      this.viewHost.ViewType = null;
    4445      //
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/OptimizableView.cs

    r4997 r5087  
    5353                Content.ActualValue.ValueDataType == typeof(DoubleValue) ||
    5454                Content.ActualValue.ValueDataType == typeof(PercentValue)) {
     55              this.viewHost.ViewsLabelVisible = true;
    5556              this.viewHost.Content = ((IValueConfiguration)Content).RangeConstraint;
    5657            } else if(Content.ActualValue.ValueDataType == typeof(BoolValue)) {
    5758              this.viewHost.Content = null; // no configuration required
    5859            } else {
     60              this.viewHost.ViewsLabelVisible = false;
    5961              this.viewHost.Content = ((IValueConfiguration)Content).ParameterConfigurations;
    6062            }
     
    6365          }
    6466        } else {
     67          this.viewHost.ViewsLabelVisible = false;
    6568          this.viewHost.Content = Content.ActualValue;
    6669        }
    6770      }
     71      SetEnabledStateOfControls();
    6872    }
    6973    void Content_IsOptimizabeChanged(object sender, EventArgs e) {
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ValueConfigurationViews/ValueConfigurationCheckedItemList.cs

    r4982 r5087  
    2424    public ValueConfigurationCheckedItemCollectionView() {
    2525      InitializeComponent();
     26      this.viewHost.ViewsLabelVisible = false;
    2627    }
    2728
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ValueConfigurationViews/ValueView.Designer.cs

    r4839 r5087  
    6262      this.valueViewHost.Size = new System.Drawing.Size(470, 219);
    6363      this.valueViewHost.TabIndex = 3;
     64      this.valueViewHost.ViewsLabelVisible = false;
    6465      this.valueViewHost.ViewType = null;
    6566      //
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ValueConfigurationViews/ValueView.resx

    r4839 r5087  
    166166        fNTws+7PbaOWo6fHXMf6Hwc/vj/OGn/2S8Yv7ycKnpCfVEyqTDZPmU2dmnafvvF05dOJZ+nPFmYKf5X+
    167167        tfa5zvMffnP8rX82YnbiBf/Fp99LXsq/PPRq2aueuYC5R69TXy/MF72Rf3P4LeNt37vwd5MLWe+x7ys/
    168         6H7o/ujz8cGn1E+f/gUDmPP8usTo0wAAAAlwSFlzAAALDgAACw4BQL7hQQAAAbVJREFUOE+lk7lLA0EU
     168        6H7o/ujz8cGn1E+f/gUDmPP8usTo0wAAAAlwSFlzAAALDQAACw0B7QfALAAAAbVJREFUOE+lk7lLA0EU
    169169        xuMRcdeYyIBRQcmxURTiEXE8ECQqpAkpJJVNihSKjVjbW1lJChuxtBGUNGKRwj9AvA9QEMRGS01M4YYZ
    170170        v9nN5twgavGDt/tmvn3HtxbOueU/6JcpGQEpMAfqfyMoLjeAZbYU5iw2ryJe0N6ZVUZJI3JesGrkhYB4
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestParameterConfigurationAnalyzer.cs

    r5023 r5087  
    4040    }
    4141
    42     public BestParameterConfigurationAnalyzer() : base() {
     42    public BestParameterConfigurationAnalyzer()
     43      : base() {
    4344      Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "TODO The TSP solutions given in path representation from which the best solution should be analyzed."));
    4445      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "TODO The qualities of the TSP solutions which should be analyzed."));
     
    6364      ItemArray<ParameterConfigurationTree> parameterTrees = ParameterConfigurationParameter.ActualValue;
    6465
    65       int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     66      int idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
    6667
    67       EngineAlgorithm bestAlg = ((EngineAlgorithm)((ParameterConfigurationTree)parameterTrees[i]).ActualValue.Value);
    68       Run bestRun = new Run(bestAlg);
    69       ((ParameterConfigurationTree)parameterTrees[i]).CollectResultValues(bestRun.Results);
    7068
    71       if (bestKnownQuality == null || qualities[i].Value < bestKnownQuality.Value) { // todo: respect Maximization:true/false
    72         BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
     69      ParameterConfigurationTree best = (ParameterConfigurationTree)parameterTrees[idxBest];
     70      IRun bestRun = new Run();
     71      best.CollectResultValues(bestRun.Results);
     72      best.CollectParameterValues(bestRun.Parameters);
     73
     74      if (bestKnownQuality == null || qualities[idxBest].Value < bestKnownQuality.Value) { // todo: respect Maximization:true/false
     75        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[idxBest].Value);
     76
    7377        BestKnownSolutionParameter.ActualValue = bestRun;
    7478      }
    7579
    76       IRun best = BestSolutionParameter.ActualValue;
    77       if (best == null) {
     80      if (BestSolutionParameter.ActualValue == null) {
    7881        BestSolutionParameter.ActualValue = bestRun;
    7982        results.Add(new Result("Best Parameter Settings", bestRun));
     
    8487
    8588      // population
     89
     90      int i = 0;
    8691      RunCollection rc = new RunCollection();
    8792      foreach (ParameterConfigurationTree pt in parameterTrees.OrderByDescending(x => x.BestQuality.Value)) { // todo: respect Maximization:true/false
    88         IAlgorithm alg = (IAlgorithm)pt.ActualValue.Value;
    89         alg.StoreAlgorithmInEachRun = false;
    90         IRun run = new Run(alg);
     93        IRun run = new Run();
     94        run.Name = string.Format("Individuum ({0})", i);
    9195        pt.CollectResultValues(run.Results);
     96        pt.CollectParameterValues(run.Parameters);
    9297        rc.Add(run);
     98        i++;
    9399      }
    94100      if (PopulationParameter.ActualValue == null) {
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ParameterConfigurationTree.cs

    r5023 r5087  
    1313  [StorableClass]
    1414  public class ParameterConfigurationTree : ValueConfiguration {
    15     [Storable]
    16     public EngineAlgorithm Algorithm {
    17       get { return (EngineAlgorithm)base.ActualValue.Value; }
    18       set {
    19         base.ActualValue.Value = value;
    20       }
    21     }
     15    //[Storable]
     16    //public EngineAlgorithm Algorithm {
     17    //  get { return (EngineAlgorithm)base.ActualValue.Value; }
     18    //  set {
     19    //    base.ActualValue.Value = value;
     20    //  }
     21    //}
    2222
    2323    [Storable]
     
    4848      set { worstQuality = value; }
    4949    }
    50    
     50
    5151    [Storable]
    5252    private DoubleValue qualityVariance;
     
    5555      set { qualityVariance = value; }
    5656    }
    57    
     57
    5858    [Storable]
    5959    private DoubleValue qualityStandardDeviation;
     
    6262      set { qualityStandardDeviation = value; }
    6363    }
    64    
     64
    6565    [Storable]
    6666    private TimeSpanValue averageExecutionTime;
     
    7878
    7979    [Storable]
    80     public RunCollection Runs { get; set; }
    81    
     80    protected RunCollection runs;
     81    public RunCollection Runs {
     82      get { return runs; }
     83      set { runs = value; }
     84     }
     85
     86    protected IDictionary<string, IItem> parameters;
     87    public IDictionary<string, IItem> Parameters {
     88      get { return parameters; }
     89      set { parameters = value; }
     90    }
     91
    8292    #region constructors and cloning
    83     public ParameterConfigurationTree(EngineAlgorithm algorithm) : base(algorithm, algorithm.GetType()) {
     93    public ParameterConfigurationTree(EngineAlgorithm algorithm)
     94      : base(null, algorithm.GetType()) {
    8495      this.Optimize = true; // root must always be optimized
    8596      this.BestQuality = new DoubleValue();
     97      this.parameters = new Dictionary<string, IItem>();
     98
     99      PopulateParameterConfigurations(algorithm);
     100      Initialize();
    86101    }
    87102    public ParameterConfigurationTree() {
     
    90105    [StorableConstructor]
    91106    protected ParameterConfigurationTree(bool deserializing) : base(deserializing) { }
    92     protected ParameterConfigurationTree(ParameterConfigurationTree original, Cloner cloner) : base(original, cloner) {
     107    protected ParameterConfigurationTree(ParameterConfigurationTree original, Cloner cloner)
     108      : base(original, cloner) {
    93109      this.bestQuality = cloner.Clone(original.BestQuality);
    94       this.Algorithm.Prepare();
    95       this.Algorithm.Runs.Clear();
     110      this.parameters = new Dictionary<string, IItem>();
     111      foreach (var p in original.parameters) {
     112        this.parameters.Add(p.Key, cloner.Clone(p.Value));
     113      }
    96114      Initialize();
    97115    }
     
    121139    }
    122140
     141    public virtual void CollectParameterValues(IDictionary<string, IItem> values) {
     142      foreach (var p in parameters) {
     143        values.Add(p);
     144      }
     145    }
     146
    123147    #region Events
    124148    //public event EventHandler AlgorithmChanged;
     
    134158
    135159    //private void RegisterAlgorithmEvents() {
    136      
     160
    137161    //}
    138162    //private void DeregisterAlgorithmEvents() {
     
    151175    #endregion
    152176
     177    public override void Parameterize(IParameterizedItem item) {
     178      base.Parameterize(item);
     179      this.parameters.Clear();
     180      ((IAlgorithm)item).CollectParameterValues(this.Parameters);
     181    }
    153182  }
    154183}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ParameterConfigurations/ParameterConfiguration.cs

    r5023 r5087  
    281281    public void Randomize(IRandom random) {
    282282      if (Optimize) {
     283        foreach (var vc in this.ValueConfigurations.CheckedItems) {
     284          vc.Randomize(random);
     285        }
    283286        actualValueConfigurationIndex = random.Next(ValueConfigurations.CheckedItems.Count());
    284         this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).Randomize(random);
    285287        this.ActualValue = this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ActualValue;
    286288      }
     
    294296        actualValueConfigurationIndex = random.Next(ValueConfigurations.CheckedItems.Count());
    295297        this.ActualValue = this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ActualValue;
    296         this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).Mutate(random);
    297298      }
    298299    }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ValueConfigurations/ValueConfiguration.cs

    r5023 r5087  
    3434          if (optimize) {
    3535            ClearParameterConfigurations();
    36             PopulateParameterConfigurations();
     36            if (this.actualValue.Value is IParameterizedNamedItem) PopulateParameterConfigurations(this.actualValue.Value as IParameterizedNamedItem);
    3737          } else {
    3838            ClearParameterConfigurations();
     
    5353    [Storable]
    5454    protected ConstrainedValue actualValue;
    55     public ConstrainedValue ActualValue {
     55    public virtual ConstrainedValue ActualValue {
    5656      get { return actualValue; }
    5757      set {
     
    5959          ClearParameterConfigurations();
    6060          this.actualValue = value;
    61           PopulateParameterConfigurations();
     61          if (this.actualValue.Value is IParameterizedNamedItem) PopulateParameterConfigurations(this.actualValue.Value as IParameterizedNamedItem);
    6262          OnValueChanged();
    6363          OnToStringChanged();
     
    112112    #endregion
    113113
    114     protected virtual void PopulateParameterConfigurations() {
    115       if (this.actualValue.Value is IParameterizedNamedItem) {
    116         var parameterizedItem = this.actualValue.Value as IParameterizedNamedItem;
    117         foreach (var childParameter in parameterizedItem.Parameters) {
    118           var pc = ParameterConfiguration.Create(parameterizedItem, childParameter);
    119           if (pc != null) this.parameterConfigurations.Add(pc);
    120         }
     114    protected virtual void PopulateParameterConfigurations(IParameterizedNamedItem parameterizedItem) {
     115      foreach (var childParameter in parameterizedItem.Parameters) {
     116        var pc = ParameterConfiguration.Create(parameterizedItem, childParameter);
     117        if (pc != null) this.parameterConfigurations.Add(pc);
    121118      }
    122119    }
     
    195192    }
    196193
    197     public void Parameterize(IParameterizedItem item) {
     194    public virtual void Parameterize(IParameterizedItem item) {
    198195      foreach (IParameterConfiguration pc in this.ParameterConfigurations) {
    199196        pc.Parameterize((IValueParameter)item.Parameters[pc.ParameterName]);
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/MetaOptimizationEvaluator.cs

    r5023 r5087  
    6363
    6464    public override IOperation Apply() {
    65       EngineAlgorithm algorithm = (EngineAlgorithm)ParameterConfigurationParameter.ActualValue.ActualValue.Value;
     65      EngineAlgorithm algorithm = AlgorithmParameter.ActualValue;
     66      IItemList<ISingleObjectiveProblem> problems = ProblemsParameter.ActualValue;
    6667
    6768      // set parameters
    6869      ParameterConfigurationParameter.ActualValue.Parameterize(algorithm);
     70      algorithm.Problem = problems.First();
     71      algorithm.StoreAlgorithmInEachRun = false;
    6972
    7073      algorithmStopped = false;
     
    7376      List<double> qualities = new List<double>();
    7477      List<TimeSpan> executionTimes = new List<TimeSpan>();
     78      algorithm.Engine = new SequentialEngine.SequentialEngine();
    7579      algorithm.Prepare(true);
    7680
    77       for (int i = 0; i < Repetitions.Value; i++) {
    78         algorithm.Engine = new SequentialEngine.SequentialEngine();
    79         algorithm.Prepare();
    80         algorithm.Start();
    81         while (!algorithmStopped) {
    82           Thread.Sleep(200); // 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)
     81      foreach (ISingleObjectiveProblem problem in problems) {
     82        algorithm.Problem = problem;
     83
     84        for (int i = 0; i < Repetitions.Value; i++) {
     85          algorithm.Prepare();
     86          algorithm.Start();
     87          while (!algorithmStopped) {
     88            Thread.Sleep(200); // 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)
     89          }
     90          qualities.Add(((DoubleValue)algorithm.Results["BestQuality"].Value).Value);
     91          executionTimes.Add(algorithm.ExecutionTime);
     92
     93          // parameters will be stored in ParameterConfigurationTree anyway. they would be redundant in runs
     94          algorithm.Runs.Last().Parameters.Clear();
     95          // but keep the problem, since this differs in runs
     96          algorithm.Runs.Last().Parameters.Add("Problem", problem);
     97          algorithmStopped = false;
    8398        }
    84         qualities.Add(((DoubleValue)algorithm.Results["BestQuality"].Value).Value);
    85         executionTimes.Add(algorithm.ExecutionTime);
    8699
    87         algorithmStopped = false;
    88100      }
     101
     102
    89103      algorithm.Stopped -= new EventHandler(ActualValue_Stopped);
     104      algorithm.Prepare();
    90105
    91106      qualities = qualities.OrderBy(x => x).ToList();  // todo: respect Maximization:true/false
    92      
     107
    93108      ParameterConfigurationParameter.ActualValue.AverageExecutionTime = new TimeSpanValue(TimeSpan.FromMilliseconds(executionTimes.Average(t => t.TotalMilliseconds)));
    94109      ParameterConfigurationParameter.ActualValue.Repetitions = Repetitions;
     
    102117      double quality = ParameterConfigurationParameter.ActualValue.AverageQuality.Value; // todo: also include other measures (executiontime, variance)
    103118      this.QualityParameter.ActualValue = new DoubleValue(quality);
    104      
     119
    105120      return base.Apply();
    106121    }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj

    r5023 r5087  
    7979    </Reference>
    8080    <Reference Include="HeuristicLab.SequentialEngine-3.3">
    81       <HintPath>..\..\HeuristicLab.MetaOptimization.Test\bin\Debug\HeuristicLab.SequentialEngine-3.3.dll</HintPath>
     81      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.SequentialEngine-3.3.dll</HintPath>
    8282    </Reference>
    8383    <Reference Include="System" />
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs

    r5009 r5087  
    151151    }
    152152    void BaseLevelAlgorithmParameter_ValueChanged(object sender, EventArgs e) {
    153       Algorithm.ProblemChanged += new EventHandler(BaseLevelAlgorithm_ProblemChanged); // when to deregister?
    154       BaseLevelAlgorithm_ProblemChanged(sender, e);
     153      AlgorithmParameterConfiguration = new ParameterConfigurationTree(Algorithm);
     154
     155      //Algorithm.ProblemChanged += new EventHandler(BaseLevelAlgorithm_ProblemChanged); // when to deregister?
     156      //BaseLevelAlgorithm_ProblemChanged(sender, e);
    155157    }
    156158
    157159    void BaseLevelAlgorithm_ProblemChanged(object sender, EventArgs e) {
    158       if (Algorithm != null && Algorithm.Problem != null) {
    159         AlgorithmParameterConfiguration = new ParameterConfigurationTree(Algorithm);
    160       }
     160      //if (Algorithm != null && Algorithm.Problem != null) {
     161      //  AlgorithmParameterConfiguration = new ParameterConfigurationTree(Algorithm);
     162      //}
    161163    }
    162164    #endregion
Note: See TracChangeset for help on using the changeset viewer.