Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5184


Ignore:
Timestamp:
12/30/10 22:50:59 (14 years ago)
Author:
cneumuel
Message:

#1215

  • enhanced combinations generator (now with batchruns!)
  • fixed ActualNames for metaopt-alg
  • added penalty for invalid solution-candidates (algs which throw exceptions)
  • migrated to .NET 4.0
Location:
branches/HeuristicLab.MetaOptimization
Files:
1 added
21 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/HeuristicLab.MetaOptimization.Test.csproj

    r5110 r5184  
    1111    <RootNamespace>HeuristicLab.MetaOptimization.Test</RootNamespace>
    1212    <AssemblyName>HeuristicLab.MetaOptimization.Test</AssemblyName>
    13     <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
     13    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    1414    <TargetFrameworkProfile>
    1515    </TargetFrameworkProfile>
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs

    r5144 r5184  
    1717using HeuristicLab.Random;
    1818using HeuristicLab.Selection;
     19using HeuristicLab.Parameters;
    1920
    2021namespace HeuristicLab.MetaOptimization.Test {
    2122  class Program {
    22     private static int metaAlgorithmPopulationSize = 50;
    23     private static int metaAlgorithmMaxGenerations = 30;
    24     private static int metaProblemRepetitions = 6;
    25 
    26     private static int baseAlgorithmMaxGenerations = 250;
     23    private static int metaAlgorithmPopulationSize = 10;
     24    private static int metaAlgorithmMaxGenerations = 10;
     25    private static int metaProblemRepetitions = 1;
     26
     27    private static int baseAlgorithmMaxGenerations = 10;
    2728
    2829    static void Main(string[] args) {
     
    3637      //TestCombinations2();
    3738      //TestCombinations3();
    38       TestCombinations4();
     39      //TestEnumeratorCollectionEnumerator();
     40      //TestCombinations4();
    3941
    4042      GeneticAlgorithm baseLevelAlgorithm = new GeneticAlgorithm();
     
    6567    private static void TestToString(IValueConfiguration algorithmVc) {
    6668      var random = new MersenneTwister();
    67       Console.WriteLine(algorithmVc.ToParameterInfoString());
     69      Console.WriteLine(algorithmVc.ParameterInfoString);
    6870      algorithmVc.Randomize(random);
    69       Console.WriteLine(algorithmVc.ToParameterInfoString());
     71      Console.WriteLine(algorithmVc.ParameterInfoString);
    7072      algorithmVc.Randomize(random);
    71       Console.WriteLine(algorithmVc.ToParameterInfoString());
     73      Console.WriteLine(algorithmVc.ParameterInfoString);
    7274      algorithmVc.Randomize(random);
    7375    }
     
    114116    }
    115117
     118    private static void TestEnumeratorCollectionEnumerator() {
     119      IEnumerable<int> list1 = new int[] { 1, 2, 3, 4, 5 };
     120      IEnumerable<int> list2 = new int[] { 10, 20, 30 };
     121      IEnumerable<int> list3 = new int[] { 300, 400, 500 };
     122
     123      var enumerators = new List<IEnumerator>();
     124
     125      EnumeratorCollectionEnumerator<int> enu = new EnumeratorCollectionEnumerator<int>();
     126      enu.AddEnumerator(list1.GetEnumerator());
     127      enu.AddEnumerator(list2.GetEnumerator());
     128      enu.AddEnumerator(list3.GetEnumerator());
     129      enu.Reset();
     130      while (enu.MoveNext()) {
     131        Console.WriteLine(enu.Current);
     132      }
     133    }
     134
    116135    private static void TestCombinations4() {
    117136      GeneticAlgorithm ga = new GeneticAlgorithm();
    118137      ga.Problem = new SingleObjectiveTestFunctionProblem();
     138      ga.Engine = new SequentialEngine.SequentialEngine();
     139
    119140      ParameterConfigurationTree vc = new ParameterConfigurationTree(ga);
    120141
    121       //ConfigurePopulationSize(vc, 20, 100, 20);
     142      ConfigurePopulationSize(vc, 20, 100, 20);
    122143      //ConfigureMutationRate(vc, 0.10, 0.60, 0.10);
    123       ConfigureMutationOperator(vc);
    124       ConfigureSelectionOperator(vc, false);
    125 
    126       //foreach (var combination in vc.IterateCombinations()) {
    127       //  Console.WriteLine(combination.ToParameterInfoString());
    128       //}
     144      //ConfigureMutationOperator(vc);
     145      ConfigureSelectionOperator(vc, true);
    129146
    130147      int count = 0;
     
    134151        var current = (IValueConfiguration)enumerator.Current;
    135152        count++;
    136         Console.WriteLine(current.ToParameterInfoString());
     153        Console.WriteLine(current.ParameterInfoString);
    137154      }
    138155      Console.WriteLine("You are about to create {0} algorithms.", count);
    139 
     156     
    140157      Experiment experiment = vc.GenerateExperiment(ga);
    141       foreach (var opt in experiment.Optimizers) {
    142         Console.WriteLine(opt.Name);
     158      //foreach (var opt in experiment.Optimizers) {
     159      //  Console.WriteLine(opt.Name);
     160      //}
     161
     162      experiment.Prepare();
     163      experiment.Start();
     164
     165      while (experiment.ExecutionState != ExecutionState.Stopped) {
     166        Thread.Sleep(500);
    143167      }
    144168    }
     
    220244      metaLevelAlgorithm.Problem = metaOptimizationProblem;
    221245      metaLevelAlgorithm.Engine = new SequentialEngine.SequentialEngine();
    222 
    223       metaLevelAlgorithm.Mutator = new ParameterConfigurationManipulator();
     246     
     247      metaLevelAlgorithm.Mutator = ((OptionalConstrainedValueParameter<IManipulator>)((IAlgorithm)metaLevelAlgorithm).Parameters["Mutator"]).ValidValues.Last();
     248     
    224249      metaLevelAlgorithm.MutationProbability.Value = 0.15;
    225250
     
    235260      metaLevelAlgorithm.Engine = new SequentialEngine.SequentialEngine();
    236261
    237       metaLevelAlgorithm.Mutator = new ParameterConfigurationManipulator();
    238       //metaLevelAlgorithm.MutationProbability.Value = 0.15;
     262      metaLevelAlgorithm.Mutator = ((OptionalConstrainedValueParameter<IManipulator>)((IAlgorithm)metaLevelAlgorithm).Parameters["Mutator"]).ValidValues.Last();
    239263
    240264      return metaLevelAlgorithm;
     
    257281      });
    258282
    259       ConfigurePopulationSize(algorithmVc, 20, 100, 1);
    260       ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.01);
    261       ConfigureMutationOperator(algorithmVc);
    262       ConfigureElites(algorithmVc);
    263       ConfigureSelectionOperator(algorithmVc, true);
     283      ConfigurePopulationSize(algorithmVc, 0, 10, 1);
     284      //ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.01);
     285      //ConfigureMutationOperator(algorithmVc);
     286      ConfigureElites(algorithmVc, 0, 10, 1);
     287      //ConfigureSelectionOperator(algorithmVc, true);
    264288      return algorithmVc;
    265289    }
     
    369393
    370394      groupSizePc.ValueConfigurations.First().Optimize = true;
    371       groupSizePc.ValueConfigurations.First().RangeConstraint.LowerBound = new IntValue(0);
    372       groupSizePc.ValueConfigurations.First().RangeConstraint.UpperBound = new IntValue(100);
     395      groupSizePc.ValueConfigurations.First().RangeConstraint.LowerBound = new IntValue(2);
     396      groupSizePc.ValueConfigurations.First().RangeConstraint.UpperBound = new IntValue(10);
    373397      groupSizePc.ValueConfigurations.First().RangeConstraint.StepSize = new IntValue(1);
    374398    }
     
    394418    }
    395419
    396     private static void ConfigureElites(IValueConfiguration algorithmVc) {
     420    private static void ConfigureElites(IValueConfiguration algorithmVc, int from, int to, int stepSize) {
    397421      var elitesPc = algorithmVc.ParameterConfigurations.Where(x => x.Name == "Elites").SingleOrDefault();
    398422      elitesPc.Optimize = true;
    399423      var elitesVc = elitesPc.ValueConfigurations.First();
    400424      elitesVc.Optimize = true;
    401       elitesVc.RangeConstraint.LowerBound = new IntValue(0);
    402       elitesVc.RangeConstraint.UpperBound = new IntValue(20);
    403       elitesVc.RangeConstraint.StepSize = new IntValue(1);
     425      elitesVc.RangeConstraint.LowerBound = new IntValue(from);
     426      elitesVc.RangeConstraint.UpperBound = new IntValue(to);
     427      elitesVc.RangeConstraint.StepSize = new IntValue(stepSize);
    404428    }
    405429
     
    423447        sw.WriteLine(sb1.ToString());
    424448        Console.WriteLine(sb1.ToString());
     449        metaLevelAlgorithm.Stopped += new EventHandler(metaLevelAlgorithm_Stopped);
     450        metaLevelAlgorithm.Paused += new EventHandler(metaLevelAlgorithm_Paused);
     451        metaLevelAlgorithm.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(metaLevelAlgorithm_ExceptionOccurred);
    425452
    426453        metaLevelAlgorithm.Start();
     
    478505    }
    479506
     507    private static void metaLevelAlgorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) {
     508      Console.WriteLine("metaLevelAlgorithm_ExceptionOccurred");
     509    }
     510
     511    private static void metaLevelAlgorithm_Paused(object sender, EventArgs e) {
     512      Console.WriteLine("metaLevelAlgorithm_Paused");
     513    }
     514
     515    private static void metaLevelAlgorithm_Stopped(object sender, EventArgs e) {
     516      Console.WriteLine("metaLevelAlgorithm_Stopped");
     517    }
     518
    480519    private static void TestShorten() {
    481520      int n = 8;
     
    554593    }
    555594
    556     public IEnumerable<Node> IterateCombinations() {
    557       foreach (int val in PossibleValues) {
    558         this.ActualValue = val;
    559         if (ChildNodes.Count > 0) {
    560           List<IEnumerable<Node>> lists = new List<IEnumerable<Node>>();
    561           List<IEnumerator<Node>> enumerators = new List<IEnumerator<Node>>();
    562 
    563           foreach (Node child in ChildNodes) {
    564             IEnumerable<Node> combinations = child.IterateCombinations();
    565             IEnumerator<Node> enumerator = combinations.GetEnumerator();
    566             enumerator.MoveNext(); // initialize
    567             lists.Add(combinations);
    568             enumerators.Add(enumerator);
    569           }
    570 
    571 
    572           bool abort = false;
    573           while (!abort) {
    574             abort = true;
    575             foreach (var enumerator in enumerators) {
    576               if (enumerator.MoveNext()) {
    577                 abort = false;
    578                 yield return this;
    579               }
    580             }
    581           }
    582 
    583         } else {
    584           yield return this;
    585         }
    586       }
    587     }
    588 
    589595    public override string ToString() {
    590596      StringBuilder sb = new StringBuilder();
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/app.config

    r5144 r5184  
    1313    </assemblyBinding>
    1414  </runtime>
    15 <startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
     15<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/HeuristicLab.Problems.MetaOptimization.Views-3.3.csproj

    r5144 r5184  
    1111    <RootNamespace>HeuristicLab.Problems.MetaOptimization.Views</RootNamespace>
    1212    <AssemblyName>HeuristicLab.Problems.MetaOptimization.Views-3.3</AssemblyName>
    13     <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
     13    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    1414    <FileAlignment>512</FileAlignment>
    1515    <TargetFrameworkProfile />
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/MetaOptimizationProblemView.cs

    r5144 r5184  
    6262        }
    6363        if (result == System.Windows.Forms.DialogResult.OK) {
    64           Experiment experiment = Content.ParameterConfigurationTree.GenerateExperiment(Content.Algorithm);
     64          Experiment experiment;
     65          if (Content.Repetitions.Value > 1) {
     66            experiment = Content.ParameterConfigurationTree.GenerateExperiment(Content.Algorithm, true, Content.Repetitions.Value);
     67          } else {
     68            experiment = Content.ParameterConfigurationTree.GenerateExperiment(Content.Algorithm);
     69          }
    6570          MainFormManager.MainForm.ShowContent(experiment);
    6671        }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ValueConfigurationViews/ValueConfigurationCheckedItemList.cs

    r5110 r5184  
    7373      if (objectSelectorDialog.ShowDialog(this) == DialogResult.OK) {
    7474        try {
    75           IItem value = objectSelectorDialog.Item;
     75          IItem value = (IItem)objectSelectorDialog.Item.Clone();
    7676          return new ValueConfiguration(value, value.GetType());
    7777        }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Creators/RandomParameterConfigurationCreator.cs

    r5009 r5184  
    2121    }
    2222    public ILookupParameter<ParameterConfigurationTree> InitialParameterConfigurationParameter {
    23       get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["InitialParameterConfigurationTree"]; }
     23      get { return (ILookupParameter<ParameterConfigurationTree>)Parameters[MetaOptimizationProblem.ParameterConfigurationTreeParameterName]; }
    2424    }
    2525
    26     public ILookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter {
    27       get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; }
     26    public IValueLookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter {
     27      get { return (IValueLookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTreeSolutionCandidate"]; }
    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<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."));
     35      Parameters.Add(new LookupParameter<ParameterConfigurationTree>(MetaOptimizationProblem.ParameterConfigurationTreeParameterName, "The parameter configuration tree on which the new solution will be based on."));
     36      Parameters.Add(new ValueLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTreeSolutionCandidate", "The new random parameter set."));
    3737    }
    3838    public override IDeepCloneable Clone(Cloner cloner) {
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/Crossovers/ParameterConfigurationCrossover.cs

    r5112 r5184  
    1515  [Item("ParameterConfigurationCrossover", "TODO")]
    1616  [StorableClass]
    17   public class ParameterConfigurationCrossover : SingleSuccessorOperator, IParameterConfigurationOperator, ICrossover {
     17  public class ParameterConfigurationCrossover : SingleSuccessorOperator, IParameterConfigurationOperator, IParameterConfigurationCrossover {
    1818    public override bool CanChangeName {
    1919      get { return false; }
     
    2323      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
    2424    }
    25     public ILookupParameter<ItemArray<IValueConfiguration>> ParentsParameter {
    26       get { return (ScopeTreeLookupParameter<IValueConfiguration>)Parameters["Parents"]; }
     25    public ILookupParameter<ItemArray<ParameterConfigurationTree>> ParentsParameter {
     26      get { return (ScopeTreeLookupParameter<ParameterConfigurationTree>)Parameters["Parents"]; }
    2727    }
    28     public ILookupParameter<IValueConfiguration> ChildParameter {
    29       get { return (ILookupParameter<IValueConfiguration>)Parameters["Child"]; }
     28    public ILookupParameter<ParameterConfigurationTree> ChildParameter {
     29      get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["Child"]; }
    3030    }
    3131
     
    4343      : base() {
    4444      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic crossover operators."));
    45       Parameters.Add(new ScopeTreeLookupParameter<IValueConfiguration>("Parents", "The parent vectors which should be crossed."));
    46       ParentsParameter.ActualName = "ParameterConfigurationTree";
    47       Parameters.Add(new LookupParameter<IValueConfiguration>("Child", "The child vector resulting from the crossover."));
    48       ChildParameter.ActualName = "ParameterConfigurationTree";
     45      Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("Parents", "The parent vectors which should be crossed."));
     46      Parameters.Add(new LookupParameter<ParameterConfigurationTree>("Child", "The child vector resulting from the crossover."));
    4947
    5048      Parameters.Add(new ValueLookupParameter<IIntValueCrossover>(MetaOptimizationProblem.IntValueCrossoverParameterName, ""));
     
    5654
    5755    public override IOperation Apply() {
    58       IValueConfiguration child1 = (IValueConfiguration)ParentsParameter.ActualValue[0].Clone();
    59       IValueConfiguration child2 = (IValueConfiguration)ParentsParameter.ActualValue[1];
     56      ParameterConfigurationTree child1 = (ParameterConfigurationTree)ParentsParameter.ActualValue[0].Clone();
     57      ParameterConfigurationTree child2 = (ParameterConfigurationTree)ParentsParameter.ActualValue[1];
    6058
    6159      //child1.Cross(child2, RandomParameter.ActualValue);
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterCombinationsEnumerator.cs

    r5144 r5184  
    1010    private IOptimizable node;
    1111    private List<IEnumerator> enumerators;
    12     IEnumerator valueEnumerator;
     12    private EnumeratorCollectionEnumerator<IItem> valueEnumerator;
     13    private bool initialized = false;
    1314
    1415    public ParameterCombinationsEnumerator(IOptimizable node) {
     
    2122    }
    2223    object IEnumerator.Current {
    23       get { return Current; }
     24      get {
     25        if (!initialized)
     26          throw new SystemException("Enumeration not started. Call MoveNext!");
     27        return Current;
     28      }
    2429    }
    2530
     
    2732
    2833    public bool MoveNext() {
    29       int i = 0;
    30       bool ok = false;
    31       while (!ok && i < enumerators.Count) {
    32         if (enumerators[i].MoveNext()) {
    33           ok = true;
     34      if (!initialized) {
     35        foreach (var enu in enumerators) {
     36          enu.Reset();
     37          if (!enu.MoveNext())
     38            return false;
     39        }
     40        initialized = true;
     41      } else {
     42        int i = 0;
     43        bool ok = false;
     44        while (!ok && i < enumerators.Count) {
     45          if (enumerators[i].MoveNext()) {
     46            ok = true;
     47          } else {
     48            i++;
     49          }
     50        }
     51
     52        if (ok) {
     53          for (int k = i - 1; k >= 0; k--) {
     54            enumerators[k].Reset();
     55            enumerators[k].MoveNext();
     56          }
    3457        } else {
    35           i++;
     58          return false;
    3659        }
    37       }
    38 
    39       if (ok) {
    40         for (int k = i - 1; k >= 0; k--) {
    41           enumerators[k].Reset();
    42           enumerators[k].MoveNext();
    43         }
    44       } else {
    45         return false;
    4660      }
    4761
     
    6175      enumerators.Clear();
    6276      valueEnumerator = null;
     77      initialized = false;
    6378
    6479      var pc = node as IParameterConfiguration;
    6580      if (pc != null) {
    66         valueEnumerator = pc.ValueConfigurations.CheckedItems.ToArray().GetEnumerator();
    67         //valueEnumerator.Reset();
    68         enumerators.Add(valueEnumerator);
     81        valueEnumerator = new EnumeratorCollectionEnumerator<IItem>();
    6982
    7083        foreach (var valueConfiguration in pc.ValueConfigurations.CheckedItems) {
     
    7285            var enumerator = new ParameterCombinationsEnumerator(valueConfiguration);
    7386            enumerator.Reset();
    74             enumerator.MoveNext();
    75             enumerators.Add(enumerator);
     87            valueEnumerator.AddEnumerator(enumerator);
     88          } else {
     89            valueEnumerator.AddEnumerator(new List<IItem> { valueConfiguration }.GetEnumerator());
    7690          }
    7791        }
     92        valueEnumerator.Reset();
     93        enumerators.Add(valueEnumerator);
    7894      }
    7995
     
    8197      if (vc != null) {
    8298        if (vc.RangeConstraint != null) {
    83           valueEnumerator = vc.RangeConstraint.GetCombinations().ToArray().GetEnumerator();
    84           //valueEnumerator.Reset();
    85           //enumerator.MoveNext();
     99          valueEnumerator = new EnumeratorCollectionEnumerator<IItem>();
     100          valueEnumerator.AddEnumerator(vc.RangeConstraint.GetCombinations().GetEnumerator());
     101          valueEnumerator.Reset();
    86102          enumerators.Add(valueEnumerator);
    87103        } else {
     
    90106              var enumerator = new ParameterCombinationsEnumerator(parameterConfiguration);
    91107              enumerator.Reset();
    92               enumerator.MoveNext();
    93108              enumerators.Add(enumerator);
    94109            }
     
    97112      }
    98113    }
     114  }
    99115
     116  /// <summary>
     117  /// Enumerator which can enumerate all elements of a list of enumerators
     118  /// </summary>
     119  /// <typeparam name="T"></typeparam>
     120  public class EnumeratorCollectionEnumerator<T> : IEnumerator<T> {
     121    private List<IEnumerator<T>> enumerators = new List<IEnumerator<T>>();
     122    private IEnumerator<IEnumerator<T>> currentEnumerator;
     123
     124    public EnumeratorCollectionEnumerator() { }
     125
     126    public void AddEnumerator(IEnumerator<T> enumerator) {
     127      enumerators.Add(enumerator);
     128    }
     129
     130    public void Dispose() {  }
     131
     132    public T Current {
     133      get { return currentEnumerator.Current.Current; }
     134    }
     135
     136    object IEnumerator.Current {
     137      get { return this.Current; }
     138    }
     139
     140    public bool MoveNext() {
     141      bool ok = currentEnumerator.Current.MoveNext();
     142      if (!ok) {
     143        ok = currentEnumerator.MoveNext();
     144        if (!ok)
     145          return false;
     146        else
     147          return this.MoveNext();
     148      }
     149      return true;
     150    }
     151
     152    public void Reset() {
     153      foreach (var enu in enumerators) {
     154        enu.Reset();
     155      }
     156      currentEnumerator = enumerators.GetEnumerator();
     157      currentEnumerator.Reset();
     158      currentEnumerator.MoveNext();
     159    }
    100160  }
    101161}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurationTree.cs

    r5144 r5184  
    1414  [StorableClass]
    1515  public class ParameterConfigurationTree : ValueConfiguration, IEnumerable {
    16     //[Storable]
    17     //public EngineAlgorithm Algorithm {
    18     //  get { return (EngineAlgorithm)base.ActualValue.Value; }
    19     //  set {
    20     //    base.ActualValue.Value = value;
    21     //  }
    22     //}
    23 
    2416    [Storable]
    2517    private DoubleValue bestQuality;
     
    8375      get { return runs; }
    8476      set { runs = value; }
    85      }
    86 
     77    }
     78
     79    [Storable]
    8780    protected IDictionary<string, IItem> parameters;
    8881    public IDictionary<string, IItem> Parameters {
     
    109102      : base(original, cloner) {
    110103      this.bestQuality = cloner.Clone(original.BestQuality);
     104      this.averageQuality = cloner.Clone(original.averageQuality);
     105      this.worstQuality = cloner.Clone(original.worstQuality);
     106      this.qualityStandardDeviation = cloner.Clone(original.qualityStandardDeviation);
     107      this.qualityVariance = cloner.Clone(original.qualityVariance);
     108      this.averageExecutionTime = cloner.Clone(original.averageExecutionTime);
     109      this.repetitions = cloner.Clone(original.repetitions);
     110      this.runs = cloner.Clone(original.runs);
    111111      this.parameters = new Dictionary<string, IItem>();
    112112      foreach (var p in original.parameters) {
     
    182182    }
    183183
    184     public Experiment GenerateExperiment(IAlgorithm algorithm) {
     184    public Experiment GenerateExperiment(IAlgorithm algorithm, bool createBatchRuns, int repetitions) {
    185185      Experiment experiment = new Experiment();
    186186      foreach (IValueConfiguration combination in this) {
    187187        IAlgorithm clonedAlg = (IAlgorithm)algorithm.Clone();
    188         clonedAlg.Name = combination.ToParameterInfoString();
     188        clonedAlg.Name = combination.ParameterInfoString;
    189189        combination.Parameterize(clonedAlg);
    190         experiment.Optimizers.Add(clonedAlg);
     190        clonedAlg.StoreAlgorithmInEachRun = false;
     191        if (createBatchRuns) {
     192          BatchRun batchRun = new BatchRun(string.Format("BatchRun: {0}", combination.ParameterInfoString));
     193          batchRun.Algorithm = clonedAlg;
     194          batchRun.Repetitions = repetitions;
     195          experiment.Optimizers.Add(batchRun);
     196        } else {
     197          experiment.Optimizers.Add(clonedAlg);
     198        }
    191199      }
    192200      return experiment;
     201    }
     202
     203    public Experiment GenerateExperiment(IAlgorithm algorithm) {
     204      return GenerateExperiment(algorithm, false, 0);
    193205    }
    194206
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs

    r5144 r5184  
    300300    }
    301301
    302     public string ToParameterInfoString() {
    303       StringBuilder sb = new StringBuilder();
    304       if (this.Optimize) {
    305         sb.Append(string.Format("{0}: {1}", parameterName, this.ActualValue.Value));
    306         //sb.Append(" (");
    307         //var subParams = new List<string>();
    308         //if (this.ActualValue.Value is IParameterizedItem) {
    309         //  subParams.Add(this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ToParameterInfoString());
    310         //}
    311         //sb.Append(string.Join(", ", subParams.ToArray()));
    312         //sb.Append(")");
    313       }
    314       return sb.ToString();
     302    public string ParameterInfoString {
     303      get {
     304        StringBuilder sb = new StringBuilder();
     305        if (this.Optimize) {
     306          sb.Append(string.Format("{0}: {1}", parameterName, this.ActualValue.Value != null ? this.ActualValue.Value.ToString() : "null"));
     307
     308          if (this.ActualValue.Value is IParameterizedItem) {
     309            string subParams = this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ParameterInfoString;
     310            if (!string.IsNullOrEmpty(subParams)) {
     311              sb.Append(" (");
     312              sb.Append(subParams);
     313              sb.Append(")");
     314            }
     315          }
     316        }
     317        return sb.ToString();
     318      }
    315319    }
    316320
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/DoubleValueRange.cs

    r5144 r5184  
    4444
    4545      while (value <= UpperBound.Value) {
    46         //yield return new DoubleValue(value);
    4746        solutions.Add(new DoubleValue(value));
    4847        value += StepSize.Value;
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/IntValueRange.cs

    r5144 r5184  
    4444
    4545      while (value <= this.UpperBound.Value) {
    46         //yield return new IntValue(value);
    4746        solutions.Add(new IntValue(value));
    4847        value += this.StepSize.Value;
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/PercentValueRange.cs

    r5144 r5184  
    3939
    4040      while (value <= UpperBound.Value) {
    41         //yield return new PercentValue(value);
    4241        solutions.Add(new PercentValue(value));
    4342        value += StepSize.Value;
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/ValueConfiguration.cs

    r5144 r5184  
    9595        RangeConstraint = new DoubleValueRange(new DoubleValue(0), (DoubleValue)value, new DoubleValue(0.01));
    9696      } else if (actualValue.ValueDataType == typeof(PercentValue)) {
    97         RangeConstraint = new PercentValueRange(new PercentValue(0), new PercentValue(1), new PercentValue(0.001));
     97        RangeConstraint = new PercentValueRange(new PercentValue(0), new PercentValue(1), new PercentValue(0.01));
    9898      } else if (actualValue.ValueDataType == typeof(BoolValue)) {
    9999        this.IsOptimizable = false; // there is nothing to configure for bools
     
    211211    }
    212212
    213     public string ToParameterInfoString() {
    214       StringBuilder sb = new StringBuilder();
    215       if (this.Optimize) {
    216         if (this.ParameterConfigurations.Count > 0) {
    217           var parameterInfos = new List<string>();
    218           foreach (var pc in this.ParameterConfigurations) {
    219             if (pc.Optimize) parameterInfos.Add(pc.ToParameterInfoString());
    220           }
    221           sb.Append(string.Join(", ", parameterInfos.ToArray()));
    222         }
    223       }
    224       return sb.ToString();
     213    public string ParameterInfoString {
     214      get {
     215        StringBuilder sb = new StringBuilder();
     216        if (this.Optimize) {
     217          if (this.ParameterConfigurations.Count > 0) {
     218            var parameterInfos = new List<string>();
     219            foreach (var pc in this.ParameterConfigurations) {
     220              if (pc.Optimize) parameterInfos.Add(pc.ParameterInfoString);
     221            }
     222            sb.Append(string.Join(", ", parameterInfos.ToArray()));
     223          }
     224        }
     225        return sb.ToString();
     226      }
    225227    }
    226228
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/ParameterConfigurationEvaluator.cs

    r5111 r5184  
    1919  public class ParameterConfigurationEvaluator : SingleSuccessorOperator, IParameterConfigurationEvaluator {
    2020    private bool algorithmStopped;
     21    private bool algorithmExceptionOccured;
    2122
    2223    public ILookupParameter<DoubleValue> QualityParameter {
     
    6970
    7071      algorithmStopped = false;
    71       algorithm.Stopped += new EventHandler(ActualValue_Stopped);
     72      algorithmExceptionOccured = false;
     73      algorithm.Stopped += new EventHandler(algorithm_Stopped);
     74      algorithm.Paused += new EventHandler(algorithm_Paused);
     75      algorithm.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(algorithm_ExceptionOccurred);
    7276
    7377      List<double> qualities = new List<double>();
     
    8589            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)
    8690          }
    87           qualities.Add(((DoubleValue)algorithm.Results["BestQuality"].Value).Value);
    88           executionTimes.Add(algorithm.ExecutionTime);
    8991
    90           // parameters will be stored in ParameterConfigurationTree anyway. they would be redundant in runs
    91           algorithm.Runs.Last().Parameters.Clear();
    92           // but keep the problem, since this differs in runs
    93           algorithm.Runs.Last().Parameters.Add("Problem", problem);
     92          if (algorithmExceptionOccured) {
     93            // this parametercombination was bad. set penalty for this solution
     94            qualities.Add(double.MaxValue); // todo: respect Maximization
     95            executionTimes.Add(algorithm.ExecutionTime);
     96          } else {
     97            qualities.Add(((DoubleValue)algorithm.Results["BestQuality"].Value).Value);
     98            executionTimes.Add(algorithm.ExecutionTime);
     99
     100            // parameters will be stored in ParameterConfigurationTree anyway. they would be redundant in runs
     101            algorithm.Runs.Last().Parameters.Clear();
     102            // but keep the problem, since this differs in runs
     103            algorithm.Runs.Last().Parameters.Add("Problem", problem);
     104          }
    94105          algorithmStopped = false;
     106          algorithmExceptionOccured = false;
    95107        }
    96 
    97108      }
    98109
    99 
    100       algorithm.Stopped -= new EventHandler(ActualValue_Stopped);
     110      algorithm.Stopped -= new EventHandler(algorithm_Stopped);
     111      algorithm.Paused -= new EventHandler(algorithm_Paused);
     112      algorithm.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(algorithm_ExceptionOccurred);
    101113      algorithm.Prepare();
    102114
     
    104116
    105117      ParameterConfigurationParameter.ActualValue.AverageExecutionTime = new TimeSpanValue(TimeSpan.FromMilliseconds(executionTimes.Average(t => t.TotalMilliseconds)));
    106       ParameterConfigurationParameter.ActualValue.Repetitions = Repetitions;
     118      ParameterConfigurationParameter.ActualValue.Repetitions = (IntValue)Repetitions.Clone();
    107119      ParameterConfigurationParameter.ActualValue.BestQuality = new DoubleValue(qualities.First());
    108120      ParameterConfigurationParameter.ActualValue.AverageQuality = new DoubleValue(qualities.Average());
     
    110122      ParameterConfigurationParameter.ActualValue.QualityVariance = new DoubleValue(qualities.Variance());
    111123      ParameterConfigurationParameter.ActualValue.QualityStandardDeviation = new DoubleValue(qualities.StandardDeviation());
    112       ParameterConfigurationParameter.ActualValue.Runs = algorithm.Runs;
     124      ParameterConfigurationParameter.ActualValue.Runs = (RunCollection)algorithm.Runs.Clone();
    113125
    114126      double quality = ParameterConfigurationParameter.ActualValue.AverageQuality.Value; // todo: also include other measures (executiontime, variance)
     
    116128
    117129      return base.Apply();
     130    }
     131
     132    private void algorithm_Paused(object sender, EventArgs e) {
     133      algorithmStopped = true;
     134    }
     135
     136    private void algorithm_Stopped(object sender, EventArgs e) {
     137      algorithmStopped = true;
     138    }
     139
     140    void algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) {
     141      algorithmExceptionOccured = true;
    118142    }
    119143
     
    128152    }
    129153
    130     void ActualValue_Stopped(object sender, EventArgs e) {
    131       algorithmStopped = true;
    132     }
     154
    133155  }
    134156}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj

    r5144 r5184  
    1111    <RootNamespace>HeuristicLab.Problems.MetaOptimization</RootNamespace>
    1212    <AssemblyName>HeuristicLab.Problems.MetaOptimization-3.3</AssemblyName>
    13     <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
     13    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    1414    <FileAlignment>512</FileAlignment>
    1515    <TargetFrameworkProfile />
     
    147147    <Compile Include="Encoding\ValueConfigurations\ValueConfiguration.cs" />
    148148    <Compile Include="Encoding\ValueConfigurations\CheckedValueConfigurationCollection.cs" />
     149    <Compile Include="Interfaces\IParameterConfigurationCrossover.cs" />
    149150    <Compile Include="Interfaces\ICheckedValueConfigurationCollection.cs" />
    150151    <Compile Include="Operators\Crossovers\DiscreteIntValueCrossover.cs" />
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IOptimizable.cs

    r5144 r5184  
    1818    void Mutate(IRandom random, MutateDelegate mutate, ParameterConfigurationManipulator pcmanip);
    1919    void Cross(IRandom random, IOptimizable other, CrossDelegate cross, ParameterConfigurationCrossover pccross);
    20     string ToParameterInfoString();
     20    string ParameterInfoString { get; }
    2121
    2222    event EventHandler IsOptimizableChanged;
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterConfigurationCreator.cs

    r4839 r5184  
    22
    33namespace HeuristicLab.Problems.MetaOptimization {
    4   public interface IParameterConfigurationCreator : ISolutionCreator {
     4  public interface IParameterConfigurationCreator : ISolutionCreator, IParameterConfigurationOperator {
    55  }
    66}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterConfigurationEvaluator.cs

    r5111 r5184  
    55  /// An interface which represents an evaluation operator for Meta Optimization Problems.
    66  /// </summary>
    7   public interface IParameterConfigurationEvaluator : ISingleObjectiveEvaluator { }
     7  public interface IParameterConfigurationEvaluator : ISingleObjectiveEvaluator, IParameterConfigurationOperator { }
    88}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs

    r5144 r5184  
    4040    public const string ProblemTypeParameterName = "ProblemType";
    4141    public const string ProblemsParameterName = "Problems";
    42     public const string ParameterConfigurationTreeParameterName = "ParameterConfigurationTree";
     42    public const string ParameterConfigurationTreeParameterName = "InitialParameterConfigurationTree";
    4343    public const string RepetitionsParameterName = "Repetitions";
    4444
     
    9595      set { RepetitionsParameter.Value = value; }
    9696    }
     97    private BestParameterConfigurationAnalyzer BestParameterConfigurationAnalyzer {
     98      get { return Operators.OfType<BestParameterConfigurationAnalyzer>().FirstOrDefault(); }
     99    }
    97100    #endregion
    98101
     
    101104      Parameters.Add(new ValueParameter<ISingleObjectiveProblem>(ProblemTypeParameterName, "The problem type.", new SingleObjectiveTestFunctionProblem()));
    102105      Parameters.Add(new ValueParameter<ConstrainedItemList<ISingleObjectiveProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ConstrainedItemList<ISingleObjectiveProblem>()));
    103       Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfigurationTreeParameterName, "List of algorithm parameters that should be optimized."));
     106      Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfigurationTreeParameterName, "Tree of algorithm parameters that should be optimized."));
    104107      Parameters.Add(new ValueParameter<IntValue>(RepetitionsParameterName, "The number of evaluations for each problem.", new IntValue(3)));
    105108
     
    109112      Parameters.Add(new ConstrainedValueParameter<IDoubleValueManipulator>(DoubleValueManipulatorParameterName, "", validDoubleManipulators, new NormalDoubleValueManipulator()));
    110113
    111 
    112114      Maximization = new BoolValue(false);
    113115      SolutionCreator = new RandomParameterConfigurationCreator();
     
    116118      InitializeOperators();
    117119      RegisterParameterEvents();
     120      ParameterizeAnalyzer();
    118121      ParameterizeSolutionCreator();
    119122      ParameterizeEvaluator();
     
    158161    }
    159162    private void ParameterizeAnalyzer() {
     163      if (BestParameterConfigurationAnalyzer != null) {
     164        BestParameterConfigurationAnalyzer.ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
     165      }
    160166    }
    161167    private void ParameterizeOperators() {
    162      
     168      foreach (IParameterConfigurationCrossover op in Operators.OfType<IParameterConfigurationCrossover>()) {
     169        op.ParentsParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
     170        op.ChildParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
     171      }
     172      foreach (IParameterConfigurationManipulator op in Operators.OfType<IParameterConfigurationManipulator>()) {
     173        op.ParameterConfigurationTreeParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
     174      }
    163175    }
    164176
Note: See TracChangeset for help on using the changeset viewer.