Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5144


Ignore:
Timestamp:
12/21/10 01:13:49 (14 years ago)
Author:
cneumuel
Message:

#1215

  • added possibility to create all parameter combinations from a ParameterConfigurationTree and generate an experiment from them
Location:
branches/HeuristicLab.MetaOptimization
Files:
7 added
4 deleted
16 edited

Legend:

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

    r5111 r5144  
    1 using System.Collections.Generic;
    2 using System.Diagnostics;
     1using System;
     2using System.Collections;
     3using System.Collections.Generic;
     4using System.IO;
    35using System.Linq;
     6using System.Text;
     7using System.Threading;
     8using HeuristicLab.Algorithms.EvolutionStrategy;
    49using HeuristicLab.Algorithms.GeneticAlgorithm;
     10using HeuristicLab.Common;
    511using HeuristicLab.Core;
     12using HeuristicLab.Data;
     13using HeuristicLab.Optimization;
    614using HeuristicLab.PluginInfrastructure;
    7 using HeuristicLab.Parameters;
    815using HeuristicLab.Problems.MetaOptimization;
    9 using HeuristicLab.Data;
    10 using System;
    11 using System.Threading;
     16using HeuristicLab.Problems.TestFunctions;
    1217using HeuristicLab.Random;
    13 using HeuristicLab.Optimization;
    14 using HeuristicLab.Common;
    15 using System.IO;
    16 using HeuristicLab.Problems.TestFunctions;
    17 using System.Text;
    1818using HeuristicLab.Selection;
    19 using HeuristicLab.Algorithms.EvolutionStrategy;
    20 using HeuristicLab.PluginInfrastructure.Manager;
    2119
    2220namespace HeuristicLab.MetaOptimization.Test {
     
    3533      //TestTypeDiscovery();
    3634      //TestOperators();
    37      
     35      //TestCombinations();
     36      //TestCombinations2();
     37      //TestCombinations3();
     38      TestCombinations4();
     39
    3840      GeneticAlgorithm baseLevelAlgorithm = new GeneticAlgorithm();
    3941
     
    4547      IValueConfiguration algorithmVc = SetupGAAlgorithm(baseLevelAlgorithm, metaOptimizationProblem);
    4648
     49      //TestToString(algorithmVc);
     50
     51
    4752      //Console.WriteLine("Press enter to start");
    4853      //Console.ReadLine();
    4954      //TestConfiguration(algorithmVc, baseLevelAlgorithm);
    50      
     55
    5156      //Console.WriteLine("Press enter to start");
    5257      //Console.ReadLine();
     
    5863    }
    5964
     65    private static void TestToString(IValueConfiguration algorithmVc) {
     66      var random = new MersenneTwister();
     67      Console.WriteLine(algorithmVc.ToParameterInfoString());
     68      algorithmVc.Randomize(random);
     69      Console.WriteLine(algorithmVc.ToParameterInfoString());
     70      algorithmVc.Randomize(random);
     71      Console.WriteLine(algorithmVc.ToParameterInfoString());
     72      algorithmVc.Randomize(random);
     73    }
     74
     75    private static void TestCombinations() {
     76      Console.WriteLine("IntRange 3-18:3");
     77      IntValueRange intRange = new IntValueRange(new IntValue(3), new IntValue(18), new IntValue(3));
     78      foreach (var val in intRange.GetCombinations()) {
     79        Console.WriteLine(val);
     80      }
     81
     82      Console.WriteLine("DoubleRange 1.0-2.5:0.5");
     83      var dblRange = new DoubleValueRange(new DoubleValue(0.7), new DoubleValue(2.8), new DoubleValue(0.5));
     84      foreach (var val in dblRange.GetCombinations()) {
     85        Console.WriteLine(val);
     86      }
     87
     88      Console.WriteLine("PercentRange 33%-66%:33%");
     89      var pctRange = new PercentValueRange(new PercentValue(0.32), new PercentValue(0.98), new PercentValue(0.33));
     90      foreach (var val in pctRange.GetCombinations()) {
     91        Console.WriteLine(val);
     92      }
     93    }
     94
     95    private static void TestCombinations3() {
     96      Node root = new Node("root");
     97      root.ChildNodes.Add(new Node("root.n1"));
     98      root.ChildNodes.Add(new Node("root.n2"));
     99      Node n3 = new Node("root.n3");
     100      n3.ChildNodes.Add(new Node("root.n3.n1"));
     101      n3.ChildNodes.Add(new Node("root.n3.n2"));
     102      root.ChildNodes.Add(n3);
     103
     104      Console.WriteLine(root.ToString());
     105      Console.WriteLine("--");
     106      int cnt = 0;
     107      var enumerator = new NodeEnumerator(root);
     108      enumerator.Reset();
     109      while (enumerator.MoveNext()) {
     110        Console.WriteLine(enumerator.Current.ToString());
     111        cnt++;
     112      }
     113      Console.WriteLine("count: " + cnt);
     114    }
     115
     116    private static void TestCombinations4() {
     117      GeneticAlgorithm ga = new GeneticAlgorithm();
     118      ga.Problem = new SingleObjectiveTestFunctionProblem();
     119      ParameterConfigurationTree vc = new ParameterConfigurationTree(ga);
     120
     121      //ConfigurePopulationSize(vc, 20, 100, 20);
     122      //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      //}
     129
     130      int count = 0;
     131      IEnumerator enumerator = new ParameterCombinationsEnumerator(vc);
     132      enumerator.Reset();
     133      while (enumerator.MoveNext()) {
     134        var current = (IValueConfiguration)enumerator.Current;
     135        count++;
     136        Console.WriteLine(current.ToParameterInfoString());
     137      }
     138      Console.WriteLine("You are about to create {0} algorithms.", count);
     139
     140      Experiment experiment = vc.GenerateExperiment(ga);
     141      foreach (var opt in experiment.Optimizers) {
     142        Console.WriteLine(opt.Name);
     143      }
     144    }
     145
    60146    private static void TestOperators() {
    61147      IRandom random = new MersenneTwister();
     
    64150      manip.IntValueManipulatorParameter.ActualValue = new UniformIntValueManipulator();
    65151      manip.DoubleValueManipulatorParameter.ActualValue = new NormalDoubleValueManipulator();
    66      
     152
    67153      var doubleRange = new DoubleValueRange(new DoubleValue(0), new DoubleValue(100), new DoubleValue(0.1));
    68154      using (var sw = new StreamWriter("out-DoubleValue.txt")) {
     
    70156          var val = new DoubleValue(50);
    71157          NormalDoubleValueManipulator.ApplyStatic(random, val, doubleRange);
    72          
     158
    73159          sw.WriteLine(val);
    74160        }
     
    98184    private static void TestTypeDiscovery() {
    99185      PluginLoader.pluginAssemblies.Any();
    100      
     186
    101187      var items = ApplicationManager.Manager.GetInstances(typeof(DoubleArray)).ToArray();
    102188
     
    107193
    108194    private static void TestMemoryLeak(GeneticAlgorithm metaLevelAlgorithm) {
    109       IValueConfiguration algorithmVc = ((MetaOptimizationProblem)metaLevelAlgorithm.Problem).AlgorithmParameterConfiguration;
     195      IValueConfiguration algorithmVc = ((MetaOptimizationProblem)metaLevelAlgorithm.Problem).ParameterConfigurationTree;
    110196
    111197      Console.WriteLine("Starting Memory Test...");
     
    160246
    161247      metaOptimizationProblem.Algorithm = baseLevelAlgorithm;
    162       IValueConfiguration algorithmVc = metaOptimizationProblem.AlgorithmParameterConfiguration;
     248      IValueConfiguration algorithmVc = metaOptimizationProblem.ParameterConfigurationTree;
    163249
    164250      metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
     
    171257      });
    172258
    173       ConfigurePopulationSize(algorithmVc);
    174       ConfigureMutationRate(algorithmVc);
     259      ConfigurePopulationSize(algorithmVc, 20, 100, 1);
     260      ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.01);
    175261      ConfigureMutationOperator(algorithmVc);
    176262      ConfigureElites(algorithmVc);
    177       ConfigureSelectionOperator(algorithmVc);
     263      ConfigureSelectionOperator(algorithmVc, true);
    178264      return algorithmVc;
    179265    }
     
    203289        GeneticAlgorithm newAlg = (GeneticAlgorithm)baseLevelAlgorithm.Clone();
    204290        //clonedVc.Mutate(rand);
    205        
     291
    206292        //.Apply(rand, clonedVc); todo
    207293        clonedVc.Parameterize(newAlg);
     
    259345    }
    260346
    261     private static void ConfigureSelectionOperator(IValueConfiguration algorithmVc) {
     347    private static void ConfigureSelectionOperator(IValueConfiguration algorithmVc, bool configureTournamenSize) {
    262348      var selectionOperatorPc = algorithmVc.ParameterConfigurations.Where(x => x.Name == "Selector").SingleOrDefault();
    263349      selectionOperatorPc.Optimize = true;
     
    266352        if (vc.ActualValue.ValueDataType == typeof(TournamentSelector)) {
    267353          selectionOperatorPc.ValueConfigurations.SetItemCheckedState(vc, true);
    268           vc.Optimize = true;
    269           ConfigureTournamentGroupSize(vc);
     354          if (configureTournamenSize) {
     355            vc.Optimize = true;
     356            ConfigureTournamentGroupSize(vc);
     357          }
    270358        } else if (vc.ActualValue.ValueDataType == typeof(RandomSelector)) {
    271359          selectionOperatorPc.ValueConfigurations.SetItemCheckedState(vc, true);
     
    286374    }
    287375
    288     private static void ConfigurePopulationSize(IValueConfiguration algorithmVc) {
     376    private static void ConfigurePopulationSize(IValueConfiguration algorithmVc, int lower, int upper, int stepsize) {
    289377      var populationSizePc = algorithmVc.ParameterConfigurations.Where(x => x.Name == "PopulationSize").SingleOrDefault();
    290378      populationSizePc.Optimize = true;
    291379      var populationSizeVc = populationSizePc.ValueConfigurations.First();
    292380      populationSizeVc.Optimize = true;
    293       populationSizeVc.RangeConstraint.LowerBound = new IntValue(20);
    294       populationSizeVc.RangeConstraint.UpperBound = new IntValue(100);
    295       populationSizeVc.RangeConstraint.StepSize = new IntValue(1);
    296     }
    297 
    298     private static void ConfigureMutationRate(IValueConfiguration algorithmVc) {
     381      populationSizeVc.RangeConstraint.LowerBound = new IntValue(lower);
     382      populationSizeVc.RangeConstraint.UpperBound = new IntValue(upper);
     383      populationSizeVc.RangeConstraint.StepSize = new IntValue(stepsize);
     384    }
     385
     386    private static void ConfigureMutationRate(IValueConfiguration algorithmVc, double lower, double upper, double stepsize) {
    299387      var mutationRatePc = algorithmVc.ParameterConfigurations.Where(x => x.Name == "MutationProbability").SingleOrDefault();
    300388      mutationRatePc.Optimize = true;
    301389      var mutationRateVc = mutationRatePc.ValueConfigurations.First();
    302390      mutationRateVc.Optimize = true;
    303       mutationRateVc.RangeConstraint.LowerBound = new PercentValue(0.0);
    304       mutationRateVc.RangeConstraint.UpperBound = new PercentValue(1.0);
    305       mutationRateVc.RangeConstraint.StepSize = new PercentValue(0.01);
     391      mutationRateVc.RangeConstraint.LowerBound = new PercentValue(lower);
     392      mutationRateVc.RangeConstraint.UpperBound = new PercentValue(upper);
     393      mutationRateVc.RangeConstraint.StepSize = new PercentValue(stepsize);
    306394    }
    307395
     
    446534    }
    447535  }
     536
     537  public class Node {
     538    public string Name { get; set; }
     539    public int ActualValue { get; set; }
     540    public int[] PossibleValues { get; set; }
     541    public List<Node> ChildNodes { get; set; }
     542
     543    public Node(string name) {
     544      this.Name = name;
     545      PossibleValues = new int[] { 1, 2, 3 };
     546      ChildNodes = new List<Node>();
     547    }
     548
     549    public void Init() {
     550      this.ActualValue = PossibleValues.First();
     551      foreach (var child in ChildNodes) {
     552        child.Init();
     553      }
     554    }
     555
     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
     589    public override string ToString() {
     590      StringBuilder sb = new StringBuilder();
     591      sb.Append(string.Format("{0}:{1}", this.Name, this.ActualValue));
     592      if (this.ChildNodes.Count() > 0) {
     593        sb.Append(" (");
     594        var lst = new List<string>();
     595        foreach (Node child in ChildNodes) {
     596          lst.Add(child.ToString());
     597        }
     598        sb.Append(string.Join(", ", lst.ToArray()));
     599        sb.Append(")");
     600      }
     601
     602      return sb.ToString();
     603    }
     604  }
     605
     606  public class NodeEnumerator : IEnumerator<Node> {
     607    private Node node;
     608    private List<IEnumerator> enumerators;
     609
     610    public NodeEnumerator(Node node) {
     611      this.node = node;
     612      this.enumerators = new List<IEnumerator>();
     613    }
     614
     615    public Node Current {
     616      get { return node; }
     617    }
     618    object IEnumerator.Current {
     619      get { return Current; }
     620    }
     621
     622    public void Dispose() { }
     623
     624    public bool MoveNext() {
     625      int i = 0;
     626      bool ok = false;
     627      while(!ok && i < enumerators.Count) {
     628        if(enumerators[i].MoveNext()) {
     629          ok = true;
     630        } else {
     631          i++;
     632        }
     633      }
     634
     635      if (ok) {
     636        for (int k = i-1; k >= 0; k--) {
     637          enumerators[k].Reset();
     638          enumerators[k].MoveNext();
     639        }
     640      } else {
     641        return false;
     642      }
     643
     644      node.ActualValue = (int)enumerators[0].Current;
     645      return true;
     646    }
     647
     648    public void Reset() {
     649      enumerators.Clear();
     650      enumerators.Add(node.PossibleValues.GetEnumerator());
     651      enumerators[0].Reset();
     652
     653      foreach (var child in node.ChildNodes) {
     654        var enumerator = new NodeEnumerator(child);
     655        enumerator.Reset();
     656        enumerator.MoveNext();
     657        enumerators.Add(enumerator);
     658      }
     659    }
     660  }
    448661}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/app.config

    r4997 r5144  
    1313    </assemblyBinding>
    1414  </runtime>
    15 </configuration>
     15<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/HeuristicLab.Problems.MetaOptimization.Views-3.3.csproj

    r5111 r5144  
    9999      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.MainForm.WindowsForms-3.3.dll</HintPath>
    100100    </Reference>
     101    <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     102      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Optimization-3.3.dll</HintPath>
     103    </Reference>
     104    <Reference Include="HeuristicLab.Optimization.Views-3.3">
     105      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Optimization.Views-3.3.dll</HintPath>
     106    </Reference>
    101107    <Reference Include="HeuristicLab.Parameters-3.3">
    102108      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Parameters-3.3.dll</HintPath>
     
    126132      <DependentUpon>ConstrainedItemListView.cs</DependentUpon>
    127133    </Compile>
     134    <Compile Include="MetaOptimizationProblemView.cs">
     135      <SubType>UserControl</SubType>
     136    </Compile>
     137    <Compile Include="MetaOptimizationProblemView.Designer.cs">
     138      <DependentUpon>MetaOptimizationProblemView.cs</DependentUpon>
     139    </Compile>
    128140    <Compile Include="OptimizableView.cs">
    129141      <SubType>UserControl</SubType>
     
    133145    </Compile>
    134146    <None Include="Properties\AssemblyInfo.cs.frame" />
    135     <Compile Include="RootValueConfigurationView.cs">
    136       <SubType>UserControl</SubType>
    137     </Compile>
    138     <Compile Include="RootValueConfigurationView.Designer.cs">
    139       <DependentUpon>RootValueConfigurationView.cs</DependentUpon>
     147    <Compile Include="ParameterConfigurationTreeView.cs">
     148      <SubType>UserControl</SubType>
     149    </Compile>
     150    <Compile Include="ParameterConfigurationTreeView.Designer.cs">
     151      <DependentUpon>ParameterConfigurationTreeView.cs</DependentUpon>
    140152    </Compile>
    141153    <Compile Include="ValueConfigurationViews\ValueConfigurationCheckedItemList.cs">
     
    171183  </ItemGroup>
    172184  <ItemGroup>
     185    <EmbeddedResource Include="MetaOptimizationProblemView.resx">
     186      <DependentUpon>MetaOptimizationProblemView.cs</DependentUpon>
     187    </EmbeddedResource>
    173188    <EmbeddedResource Include="OptimizableView.resx">
    174189      <DependentUpon>OptimizableView.cs</DependentUpon>
    175190    </EmbeddedResource>
    176     <EmbeddedResource Include="RootValueConfigurationView.resx">
    177       <DependentUpon>RootValueConfigurationView.cs</DependentUpon>
     191    <EmbeddedResource Include="ParameterConfigurationTreeView.resx">
     192      <DependentUpon>ParameterConfigurationTreeView.cs</DependentUpon>
    178193    </EmbeddedResource>
    179194    <EmbeddedResource Include="ValueConfigurationViews\RangeView.resx">
     
    187202    </EmbeddedResource>
    188203  </ItemGroup>
    189   <ItemGroup>
    190     <Folder Include="ParameterConfigurationViews\" />
    191   </ItemGroup>
     204  <ItemGroup />
    192205  <ItemGroup>
    193206    <ProjectReference Include="..\..\HeuristicLab.Problems.MetaOptimization\3.3\HeuristicLab.Problems.MetaOptimization-3.3.csproj">
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurationTree.cs

    r5112 r5144  
    88using HeuristicLab.Optimization;
    99using HeuristicLab.Data;
     10using System.Collections;
    1011
    1112namespace HeuristicLab.Problems.MetaOptimization {
    1213  // todo: storable, name, descr, ...
    1314  [StorableClass]
    14   public class ParameterConfigurationTree : ValueConfiguration {
     15  public class ParameterConfigurationTree : ValueConfiguration, IEnumerable {
    1516    //[Storable]
    1617    //public EngineAlgorithm Algorithm {
     
    180181      ((IAlgorithm)item).CollectParameterValues(this.Parameters);
    181182    }
     183
     184    public Experiment GenerateExperiment(IAlgorithm algorithm) {
     185      Experiment experiment = new Experiment();
     186      foreach (IValueConfiguration combination in this) {
     187        IAlgorithm clonedAlg = (IAlgorithm)algorithm.Clone();
     188        clonedAlg.Name = combination.ToParameterInfoString();
     189        combination.Parameterize(clonedAlg);
     190        experiment.Optimizers.Add(clonedAlg);
     191      }
     192      return experiment;
     193    }
     194
     195    public IEnumerator GetEnumerator() {
     196      IEnumerator enumerator = new ParameterCombinationsEnumerator(this);
     197      enumerator.Reset();
     198      return enumerator;
     199    }
     200
     201    public long GetCombinationCount() {
     202      long cnt = 0;
     203      foreach (var c in this) {
     204        cnt++;
     205      }
     206      return cnt;
     207    }
    182208  }
    183209}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs

    r5112 r5144  
    99using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    1010using HeuristicLab.PluginInfrastructure;
     11using System.Text;
    1112
    1213namespace HeuristicLab.Problems.MetaOptimization {
     
    299300    }
    300301
     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();
     315    }
     316
    301317    public static IParameterConfiguration Create(IParameterizedNamedItem parent, IParameter parameter) {
    302318      if (parameter is IValueParameter) {
     
    348364      }
    349365    }
     366
     367    public void UpdateActualValueIndexToItem(IValueConfiguration vc) {
     368      for (int i = 0; i < this.ValueConfigurations.CheckedItems.Count(); i++) {
     369        if (this.ValueConfigurations.CheckedItems.ElementAt(i) == vc) {
     370          this.actualValueConfigurationIndex = i;
     371          return;
     372        }
     373      }
     374    }
     375
    350376  }
    351377}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/DoubleValueRange.cs

    r5112 r5144  
    3737      if (value.Value < this.LowerBound.Value) value.Value = this.LowerBound.Value;
    3838    }
     39
     40    public override IEnumerable<DoubleValue> GetCombinations() {
     41      var solutions = new List<DoubleValue>();
     42      double value = ((int)Math.Round(LowerBound.Value / StepSize.Value, 0)) * StepSize.Value;
     43      if (value < LowerBound.Value) value += StepSize.Value;
     44
     45      while (value <= UpperBound.Value) {
     46        //yield return new DoubleValue(value);
     47        solutions.Add(new DoubleValue(value));
     48        value += StepSize.Value;
     49      }
     50      return solutions;
     51    }
    3952  }
    4053}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/IntValueRange.cs

    r5112 r5144  
    3737      if (value.Value < this.LowerBound.Value) value.Value = this.LowerBound.Value;
    3838    }
     39
     40    public override IEnumerable<IntValue> GetCombinations() {
     41      var solutions = new List<IntValue>();
     42      int value = (this.LowerBound.Value / StepSize.Value) * StepSize.Value;
     43      if (value < this.LowerBound.Value) value += StepSize.Value;
     44
     45      while (value <= this.UpperBound.Value) {
     46        //yield return new IntValue(value);
     47        solutions.Add(new IntValue(value));
     48        value += this.StepSize.Value;
     49      }
     50      return solutions;
     51    }
    3952  }
    4053}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/PercentValueRange.cs

    r5112 r5144  
    3232      return new DoubleValueRange(LowerBound, UpperBound, StepSize);
    3333    }
     34
     35    public override IEnumerable<PercentValue> GetCombinations() {
     36      var solutions = new List<PercentValue>();
     37      double value = ((int)Math.Round(LowerBound.Value / StepSize.Value, 0)) * StepSize.Value;
     38      if (value < LowerBound.Value) value += StepSize.Value;
     39
     40      while (value <= UpperBound.Value) {
     41        //yield return new PercentValue(value);
     42        solutions.Add(new PercentValue(value));
     43        value += StepSize.Value;
     44      }
     45      return solutions;
     46    }
    3447  }
    3548}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/Range.cs

    r5112 r5144  
    11using System;
     2using System.Collections.Generic;
     3using System.Linq;
    24using HeuristicLab.Common;
    35using HeuristicLab.Core;
     
    206208
    207209    protected abstract T GetRandomSample(IRandom random);
    208 
    209210    IItem IRange.GetRandomValue(IRandom random) {
    210211      return GetRandomValue(random);
    211212    }
     213
     214    public abstract IEnumerable<T> GetCombinations();
     215    IEnumerable<IItem> IRange.GetCombinations() {
     216      return GetCombinations().Cast<IItem>().ToArray();
     217    }
    212218  }
    213219}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/ValueConfiguration.cs

    r5112 r5144  
    99using HeuristicLab.Encodings.IntegerVectorEncoding;
    1010using HeuristicLab.PluginInfrastructure;
     11using System.Collections.Generic;
     12using System.Text;
    1113
    1214namespace HeuristicLab.Problems.MetaOptimization {
     
    8991      this.IsOptimizable = true;
    9092      if (actualValue.ValueDataType == typeof(IntValue)) {
    91         rangeConstraint = new IntValueRange(new IntValue(0), (IntValue)value, new IntValue(1));
     93        RangeConstraint = new IntValueRange(new IntValue(0), (IntValue)value, new IntValue(1));
    9294      } else if (actualValue.ValueDataType == typeof(DoubleValue)) {
    93         rangeConstraint = new DoubleValueRange(new DoubleValue(0), (DoubleValue)value, new DoubleValue(0.01));
     95        RangeConstraint = new DoubleValueRange(new DoubleValue(0), (DoubleValue)value, new DoubleValue(0.01));
    9496      } else if (actualValue.ValueDataType == typeof(PercentValue)) {
    95         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.001));
    9698      } else if (actualValue.ValueDataType == typeof(BoolValue)) {
    9799        this.IsOptimizable = false; // there is nothing to configure for bools
    98100      } else {
    99         rangeConstraint = null;
    100       }
    101       RegisterRangeConstraintEvents();
     101        RangeConstraint = null;
     102      }
    102103    }
    103104
     
    155156    }
    156157    #endregion
    157    
     158
    158159    #region IItem Members
    159160    public override string ItemDescription {
     
    169170    }
    170171    #endregion
    171    
     172
    172173    #region Event Handlers
    173174    public virtual event EventHandler ValueChanged;
     
    208209        return base.ToString();
    209210      }
     211    }
     212
     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();
    210225    }
    211226
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj

    r5111 r5144  
    134134    <Compile Include="ConstrainedItemList.cs" />
    135135    <Compile Include="Encoding\NullValue.cs" />
     136    <Compile Include="Encoding\ParameterCombinationsEnumerator.cs" />
    136137    <Compile Include="Encoding\RangeConstraints\PercentValueRange.cs">
    137138      <SubType>Code</SubType>
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IOptimizable.cs

    r5111 r5144  
    1818    void Mutate(IRandom random, MutateDelegate mutate, ParameterConfigurationManipulator pcmanip);
    1919    void Cross(IRandom random, IOptimizable other, CrossDelegate cross, ParameterConfigurationCrossover pccross);
    20    
     20    string ToParameterInfoString();
     21
    2122    event EventHandler IsOptimizableChanged;
    2223    event EventHandler OptimizeChanged;
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterConfiguration.cs

    r5111 r5144  
    1414
    1515    void Parameterize(IValueParameter parameter);
     16    void UpdateActualValueIndexToItem(IValueConfiguration vc);
    1617  }
    1718}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IRange.cs

    r5009 r5144  
    33using HeuristicLab.Core;
    44using HeuristicLab.Data;
     5using System.Collections.Generic;
    56
    67namespace HeuristicLab.Problems.MetaOptimization {
     
    1516
    1617    IItem GetRandomValue(IRandom random);
     18
     19    IEnumerable<IItem> GetCombinations();
    1720  }
    1821
     
    2225    new T StepSize { get; set; }
    2326    new T GetRandomValue(IRandom random);
     27    new IEnumerable<T> GetCombinations();
    2428  }
    2529}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IValueConfiguration.cs

    r5009 r5144  
    22using HeuristicLab.Core;
    33using HeuristicLab.Data;
     4using System.Collections.Generic;
    45
    56namespace HeuristicLab.Problems.MetaOptimization {
     
    89    IRange RangeConstraint { get; }
    910    event EventHandler ValueChanged;
    10 
     11   
    1112    void Parameterize(IParameterizedItem item);
    1213  }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs

    r5111 r5144  
    4040    public const string ProblemTypeParameterName = "ProblemType";
    4141    public const string ProblemsParameterName = "Problems";
    42     public const string ParameterConfigurationParameterName = "InitialParameterConfigurationTree";
     42    public const string ParameterConfigurationTreeParameterName = "ParameterConfigurationTree";
    4343    public const string RepetitionsParameterName = "Repetitions";
    4444
     
    5858      get { return (ValueParameter<ConstrainedItemList<ISingleObjectiveProblem>>)Parameters[ProblemsParameterName]; }
    5959    }
    60     public IValueParameter<ParameterConfigurationTree> ParameterConfigurationParameter {
    61       get { return (ValueParameter<ParameterConfigurationTree>)Parameters[ParameterConfigurationParameterName]; }
     60    public IValueParameter<ParameterConfigurationTree> ParameterConfigurationTreeParameter {
     61      get { return (ValueParameter<ParameterConfigurationTree>)Parameters[ParameterConfigurationTreeParameterName]; }
    6262    }
    6363    public IValueParameter<IntValue> RepetitionsParameter {
     
    8787      set { ProblemsParameter.Value = value; }
    8888    }
    89     public ParameterConfigurationTree AlgorithmParameterConfiguration {
    90       get { return ParameterConfigurationParameter.Value; }
    91       set { ParameterConfigurationParameter.Value = value; }
     89    public ParameterConfigurationTree ParameterConfigurationTree {
     90      get { return ParameterConfigurationTreeParameter.Value; }
     91      set { ParameterConfigurationTreeParameter.Value = value; }
    9292    }
    9393    public IntValue Repetitions {
     
    101101      Parameters.Add(new ValueParameter<ISingleObjectiveProblem>(ProblemTypeParameterName, "The problem type.", new SingleObjectiveTestFunctionProblem()));
    102102      Parameters.Add(new ValueParameter<ConstrainedItemList<ISingleObjectiveProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ConstrainedItemList<ISingleObjectiveProblem>()));
    103       Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfigurationParameterName, "List of algorithm parameters that should be optimized."));
     103      Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfigurationTreeParameterName, "List of algorithm parameters that should be optimized."));
    104104      Parameters.Add(new ValueParameter<IntValue>(RepetitionsParameterName, "The number of evaluations for each problem.", new IntValue(3)));
    105105
     
    122122      Problems.Type = Problem.GetType();
    123123      Algorithm.Problem = Problem;
    124       ParameterConfigurationParameter.ActualValue = new ParameterConfigurationTree(Algorithm);
     124      ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm);
    125125    }
    126126
     
    185185    void AlgorithmTypeParameter_ValueChanged(object sender, EventArgs e) {
    186186      Algorithm.Problem = Problem;
    187       ParameterConfigurationParameter.ActualValue = new ParameterConfigurationTree(Algorithm);
     187      ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm);
    188188    }
    189189    void ProblemTypeParameter_ValueChanged(object sender, EventArgs e) {
    190190      Problems.Type = Problem.GetType();
    191191      Algorithm.Problem = Problem;
    192       ParameterConfigurationParameter.ActualValue = new ParameterConfigurationTree(Algorithm);
     192      ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm);
    193193    }
    194194    #endregion
Note: See TracChangeset for help on using the changeset viewer.