Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/27/10 17:38:55 (14 years ago)
Author:
cneumuel
Message:

implemented basic crossover operator for ParameterSets. MetaOptimization is now functional on a basic level (Configuration and Crossing only works for IntValue Parameters) (#1215)

Location:
branches/HeuristicLab.MetaOptimization
Files:
3 added
11 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ParameterConfigurationView.cs

    r4516 r4525  
    3535      base.OnContentChanged();
    3636      if (Content != null) {
    37         optimizeCheckBox.Checked = Content.Optimize;
    3837        viewHost.Content = Content.Parameter;
    3938      } else {
    40         optimizeCheckBox.Checked = false;
    4139        viewHost.Content = null;
    4240      }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Creators/RandomParameterSetCreator.cs

    r4516 r4525  
    77using HeuristicLab.Operators;
    88using HeuristicLab.Parameters;
     9using HeuristicLab.Common;
    910
    1011namespace HeuristicLab.Problems.MetaOptimization {
     
    2627    }
    2728
     29    [Storable]
    2830    private ParameterConfigurationList parametersToOptimize;
    2931    public ParameterConfigurationList ParametersToOptimize {
     
    4244      return base.Apply();
    4345    }
     46
     47    #region Cloning
     48    public override IDeepCloneable Clone(Cloner cloner) {
     49      RandomParameterSetCreator clone = (RandomParameterSetCreator) base.Clone(cloner);
     50      clone.parametersToOptimize = (ParameterConfigurationList)this.parametersToOptimize.Clone();
     51      return clone;
     52    }
     53    #endregion
    4454  }
    4555}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/NumericParameterConfiguration.cs

    r4516 r4525  
    66using HeuristicLab.Core;
    77using HeuristicLab.Collections;
     8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    89
    910namespace HeuristicLab.Problems.MetaOptimization {
     11  [StorableClass]
    1012  public class NumericParameterConfiguration : ParameterConfiguration {
     13    [Storable]
    1114    private NumericRangeList ranges;
    1215    public NumericRangeList Ranges {
     
    1518
    1619    protected NumericParameterConfiguration() { }
     20   
     21    [StorableConstructor]
     22    protected NumericParameterConfiguration(bool deserializing) : base(deserializing) { }
     23
    1724    public NumericParameterConfiguration(IParameter parameter, string category)
    1825      : base(parameter, category) {
     
    2229      this.ranges.CollectionReset += new CollectionItemsChangedEventHandler<INumericRange>(ranges_CollectionReset);
    2330    }
     31
     32
    2433
    2534    void ranges_CollectionReset(object sender, CollectionItemsChangedEventArgs<INumericRange> e) {
     
    5564    }
    5665
     66    #region Cloning
    5767    public override Common.IDeepCloneable Clone(Common.Cloner cloner) {
    5868      NumericParameterConfiguration clone = (NumericParameterConfiguration)base.Clone(cloner);
     
    6373      return clone;
    6474    }
     75    #endregion
    6576
    6677    void range_ToStringChanged(object sender, EventArgs e) {
     
    7283    }
    7384
    74     public override IParameter GetParameterWithRandomValue(IRandom random) {
     85    public override void SetParameterWithRandomValue(IRandom random) {
    7586      int rangeIndex = random.Next(ranges.Count);
    7687      int value = random.Next(ranges.ElementAt(rangeIndex).LowerBound.Value, ranges.ElementAt(rangeIndex).UpperBound.Value); // TODO: respect StepSize parameter
    77       IParameter clone = (IParameter)this.Parameter.Clone();
    78       clone.ActualValue = new IntValue(value);
    79       return clone;
     88      this.Parameter.ActualValue = new IntValue(value);
    8089    }
    8190  }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ParameterConfiguration.cs

    r4516 r4525  
    55using HeuristicLab.Core;
    66using HeuristicLab.Common;
     7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    78
    89namespace HeuristicLab.Problems.MetaOptimization {
     10  [StorableClass]
    911  public abstract class ParameterConfiguration : IParameterConfiguration {
    10     public bool Optimize { get; set; }
     12    [Storable]
    1113    public IParameter Parameter { get; set; }
     14
     15    [Storable]
    1216    public string Category { get; set; }
    1317
    1418    public ParameterConfiguration() { }
     19   
     20    [StorableConstructor]
     21    protected ParameterConfiguration(bool deserializing) { }
     22
    1523    public ParameterConfiguration(IParameter parameter, string category) {
    1624      this.Parameter = parameter;
     
    7482      cloner.RegisterClonedObject(this, clone);
    7583      clone.Parameter = (IParameter)cloner.Clone(this.Parameter);
    76       clone.Optimize = this.Optimize;
     84      clone.Category = this.Category;
    7785      return clone;
    7886    }
     
    8795    }
    8896   
    89     public abstract IParameter GetParameterWithRandomValue(IRandom random);
     97    public abstract void SetParameterWithRandomValue(IRandom random);
    9098
    9199  }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ParameterSet.cs

    r4516 r4525  
    44using System.Text;
    55using HeuristicLab.Core;
     6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    67
    78namespace HeuristicLab.Problems.MetaOptimization {
     9  [StorableClass]
    810  public class ParameterSet : Item, IParameterSet {
    9     private List<KeyValuePair<string, IParameter>> parameters;
    10     public IEnumerable<KeyValuePair<string, IParameter>> Parameters {
     11    [Storable]
     12    private List<IParameterConfiguration> parameters;
     13    public IEnumerable<IParameterConfiguration> Parameters {
    1114      get { return parameters; }
    1215    }
    1316
    1417    public ParameterSet() {
    15       this.parameters = new List<KeyValuePair<string, IParameter>>();
     18      this.parameters = new List<IParameterConfiguration>();
    1619    }
     20
     21    [StorableConstructor]
     22    protected ParameterSet(bool deserializing) : base(deserializing) { }
     23
    1724    public ParameterSet(ParameterConfigurationList parametersToOptimize, IRandom random)
    1825      : this() {
    1926      foreach (IParameterConfiguration config in parametersToOptimize.CheckedItems) {
    20         parameters.Add(new KeyValuePair<string, IParameter>(config.Category, config.GetParameterWithRandomValue(random)));
     27        IParameterConfiguration clone = (IParameterConfiguration)config.Clone();
     28        clone.SetParameterWithRandomValue(random);
     29        parameters.Add(clone);
    2130      }
    2231    }
    2332
    24 
     33    #region Cloning
     34    public override Common.IDeepCloneable Clone(Common.Cloner cloner) {
     35      ParameterSet clone = (ParameterSet)base.Clone(cloner);
     36      clone.parameters = new List<IParameterConfiguration>();
     37      foreach (var param in this.parameters) {
     38        clone.parameters.Add((IParameterConfiguration)param.Clone(cloner));
     39      }
     40      return clone;
     41    }
     42    #endregion
    2543  }
    2644}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/MetaOptimizationEvaluator.cs

    r4516 r4525  
    5757
    5858    private void ParametrizeAlgorithm() {
    59       foreach (KeyValuePair<string, IParameter> parameter in ParameterSetParameter.ActualValue.Parameters) {
    60         if (parameter.Key == "Algorithm") {
    61           this.AlgorithmParameter.ActualValue.Parameters[parameter.Value.Name].ActualValue = parameter.Value.ActualValue;
    62         } else if (parameter.Key == "Problem") {
    63           this.AlgorithmParameter.ActualValue.Problem.Parameters[parameter.Value.Name].ActualValue = parameter.Value.ActualValue;
     59      foreach (IParameterConfiguration parameter in ParameterSetParameter.ActualValue.Parameters) {
     60        if (parameter.Category == "Algorithm") {
     61          this.AlgorithmParameter.ActualValue.Parameters[parameter.Parameter.Name].ActualValue = parameter.Parameter.ActualValue;
     62        } else if (parameter.Category == "Problem") {
     63          this.AlgorithmParameter.ActualValue.Problem.Parameters[parameter.Parameter.Name].ActualValue = parameter.Parameter.ActualValue;
    6464        }
    6565      }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj

    r4516 r4525  
    5454      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Data-3.3.dll</HintPath>
    5555    </Reference>
     56    <Reference Include="HeuristicLab.Encodings.BinaryVectorEncoding-3.3">
     57      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Encodings.BinaryVectorEncoding-3.3.dll</HintPath>
     58    </Reference>
     59    <Reference Include="HeuristicLab.Encodings.IntegerVectorEncoding-3.3">
     60      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Encodings.IntegerVectorEncoding-3.3.dll</HintPath>
     61    </Reference>
     62    <Reference Include="HeuristicLab.Encodings.RealVectorEncoding-3.3">
     63      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Encodings.RealVectorEncoding-3.3.dll</HintPath>
     64    </Reference>
    5665    <Reference Include="HeuristicLab.Operators-3.3">
    5766      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Operators-3.3.dll</HintPath>
     
    8190    <Compile Include="Creators\RandomParameterSetCreator.cs" />
    8291    <Compile Include="Encodings\BooleanParameterConfiguration.cs" />
     92    <Compile Include="Encodings\Crossovers\ParameterSetCrossover.cs" />
     93    <Compile Include="Interfaces\IParameterSetOperator.cs" />
    8394    <Compile Include="NumericRangeList.cs" />
    8495    <Compile Include="Encodings\EnumerableParameterConfiguration.cs" />
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterConfiguration.cs

    r4516 r4525  
    77namespace HeuristicLab.Problems.MetaOptimization {
    88  public interface IParameterConfiguration : INamedItem {
    9     bool Optimize { get; set; }
    109    IParameter Parameter { get; set; }
    1110    string Category { get; set; }
    1211
    13     IParameter GetParameterWithRandomValue(IRandom random);
     12    void SetParameterWithRandomValue(IRandom random);
    1413  }
    1514}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterSet.cs

    r4516 r4525  
    77namespace HeuristicLab.Problems.MetaOptimization {
    88  public interface IParameterSet : IItem {
    9     IEnumerable<KeyValuePair<string, IParameter>> Parameters { get; }
     9    IEnumerable<IParameterConfiguration> Parameters { get; }
    1010  }
    1111}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs

    r4516 r4525  
    172172    }
    173173
     174    #region Cloning
    174175    public override IDeepCloneable Clone(Cloner cloner) {
    175176      MetaOptimizationProblem clone = (MetaOptimizationProblem)base.Clone(cloner);
     
    179180      return clone;
    180181    }
     182    #endregion
    181183
    182184    #region Helpers
     
    195197      operators.Add(new BestQualityAnalyzer());
    196198      ParameterizeAnalyzer();
     199      operators.AddRange(ApplicationManager.Manager.GetInstances<IParameterSetOperator>().Cast<IOperator>());
    197200      ParameterizeOperators();
     201
     202      //UpdateMoveEvaluators();
     203      //InitializeMoveGenerators();
    198204    }
    199205    private void ParameterizeSolutionCreator() {
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/NumericRange.cs

    r4516 r4525  
    55using HeuristicLab.Core;
    66using HeuristicLab.Data;
     7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    78
    89namespace HeuristicLab.Problems.MetaOptimization {
     10  [StorableClass]
    911  public class NumericRange : Item, INumericRange {
     12    [Storable]
    1013    private IntValue lowerBound;
    1114    public IntValue LowerBound {
     
    2528    }
    2629
     30    [Storable]
    2731    private IntValue upperBound;
    2832    public IntValue UpperBound {
     
    4246    }
    4347
     48    [Storable]
    4449    private IntValue stepSize;
    4550    public IntValue StepSize {
     
    6368      UpperBound = new IntValue(0);
    6469      StepSize = new IntValue(1);
     70    }
     71
     72    [StorableConstructor]
     73    protected NumericRange(bool deserializing) : base(deserializing) { }
     74
     75    [StorableHook(HookType.AfterDeserialization)]
     76    private void AfterDeserialization() {
     77      if (lowerBound != null) {
     78        lowerBound.ValueChanged += new EventHandler(lowerBound_ValueChanged);
     79      }
     80      if (upperBound != null) {
     81        upperBound.ValueChanged += new EventHandler(upperBound_ValueChanged);
     82      }
     83      if (stepSize != null) {
     84        stepSize.ValueChanged += new EventHandler(stepSize_ValueChanged);
     85      }
    6586    }
    6687
     
    95116      return string.Format("[{0},{1}:{2}]", LowerBound.ToString(), UpperBound.ToString(), StepSize.ToString());
    96117    }
     118
     119    #region Cloning
     120    public override Common.IDeepCloneable Clone(Common.Cloner cloner) {
     121      NumericRange clone = (NumericRange)base.Clone(cloner);
     122      clone.LowerBound = (IntValue)this.LowerBound.Clone();
     123      clone.UpperBound = (IntValue)this.UpperBound.Clone();
     124      clone.StepSize = (IntValue)this.StepSize.Clone();
     125      return base.Clone(cloner);
     126    }
     127    #endregion
    97128  }
    98129}
Note: See TracChangeset for help on using the changeset viewer.