Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5313 for branches


Ignore:
Timestamp:
01/17/11 19:17:51 (14 years ago)
Author:
cneumuel
Message:

#1215

  • changed AlgorithType and ProblemType to actually be types not objects. this eliminates redundant views for MetaOptimizationProblem
  • import algorithm for MetaOptimizationProblem
  • nicer dialog for combination creation
  • fixed iconimage for ParameterConfigurations
  • fixed ValidValues
Location:
branches/HeuristicLab.MetaOptimization
Files:
8 added
11 edited

Legend:

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

    r5303 r5313  
    3333    private static int metaAlgorithmPopulationSize = 10;
    3434    private static int metaAlgorithmMaxGenerations = 10;
    35     private static int metaProblemRepetitions = 3;
     35    private static int metaProblemRepetitions = 10;
    3636    private static int baseAlgorithmMaxGenerations = 20;
    37     private static double mutationProbability = 0.00;
     37    private static double mutationProbability = 0.10;
    3838
    3939    static void Main(string[] args) {
     
    5959      //TestItemDictionary();
    6060
    61       GeneticAlgorithm baseLevelAlgorithm = new GeneticAlgorithm();
     61     
    6262
    6363      MetaOptimizationProblem metaOptimizationProblem = new MetaOptimizationProblem();
    6464      metaOptimizationProblem.Repetitions = new IntValue(metaProblemRepetitions);
    65       GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem);
    66       //GeneticAlgorithm metaLevelAlgorithm = GetParallelMetaGA(metaOptimizationProblem);
     65      //GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem);
     66      GeneticAlgorithm metaLevelAlgorithm = GetParallelMetaGA(metaOptimizationProblem);
    6767      //GeneticAlgorithm metaLevelAlgorithm = GetHiveParallelMetaGA(metaOptimizationProblem);
    6868
    6969      //EvolutionStrategy metaLevelAlgorithm = GetMetaES(metaOptimizationProblem);
    7070
    71       IValueConfiguration algorithmVc = SetupGAAlgorithm(baseLevelAlgorithm, metaOptimizationProblem);
     71      IValueConfiguration algorithmVc = SetupGAAlgorithm(typeof(GeneticAlgorithm), metaOptimizationProblem);
    7272
    7373      //TestToString(algorithmVc);
     
    127127      ga.MaximumGenerations.Value = 1;
    128128      ga.Engine = new SequentialEngine.SequentialEngine();
     129      throw new NotImplementedException("TODO: set ga properties correctly");
    129130
    130131      MetaOptimizationProblem metaOptimizationProblem = new MetaOptimizationProblem();
    131132      metaOptimizationProblem.Repetitions = new IntValue(metaProblemRepetitions);
    132133      GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem);
    133       ParameterConfigurationTree algorithmVc = SetupGAAlgorithm(ga, metaOptimizationProblem);
     134      ParameterConfigurationTree algorithmVc = SetupGAAlgorithm(typeof(GeneticAlgorithm), metaOptimizationProblem);
    134135      Stopwatch sw = new Stopwatch();
    135136
     
    292293      ga.MaximumGenerations.Value = 1;
    293294      ga.Engine = new SequentialEngine.SequentialEngine();
     295      throw new NotImplementedException("TODO: Set ga parameters correctly");
    294296
    295297      MetaOptimizationProblem metaOptimizationProblem = new MetaOptimizationProblem();
    296298      metaOptimizationProblem.Repetitions = new IntValue(metaProblemRepetitions);
    297299      GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem);
    298       ParameterConfigurationTree algorithmVc = SetupGAAlgorithm(ga, metaOptimizationProblem);
     300      ParameterConfigurationTree algorithmVc = SetupGAAlgorithm(typeof(GeneticAlgorithm), metaOptimizationProblem);
    299301      Stopwatch sw = new Stopwatch();
    300302
     
    507509
    508510      metaLevelAlgorithm.MutationProbability.Value = mutationProbability;
     511      //metaLevelAlgorithm.Selector = ((OptionalConstrainedValueParameter<ISelector>)((IAlgorithm)metaLevelAlgorithm).Parameters["Selector"]).ValidValues.Where(x => x.GetType() == typeof(LinearRankSelector)).Single();
     512      //metaLevelAlgorithm.Selector = ((OptionalConstrainedValueParameter<ISelector>)((IAlgorithm)metaLevelAlgorithm).Parameters["Selector"]).ValidValues.Where(x => x.GetType() == typeof(TournamentSelector)).Single();
     513      //metaLevelAlgorithm.Selector = ((OptionalConstrainedValueParameter<ISelector>)((IAlgorithm)metaLevelAlgorithm).Parameters["Selector"]).ValidValues.Where(x => x.GetType() == typeof(GenderSpecificSelector)).Single();
     514      //metaLevelAlgorithm.Selector = ((OptionalConstrainedValueParameter<ISelector>)((IAlgorithm)metaLevelAlgorithm).Parameters["Selector"]).ValidValues.Where(x => x.GetType() == typeof(BestSelector)).Single();
     515      metaLevelAlgorithm.Selector = ((OptionalConstrainedValueParameter<ISelector>)((IAlgorithm)metaLevelAlgorithm).Parameters["Selector"]).ValidValues.Where(x => x.GetType() == typeof(ProportionalSelector)).Single();
    509516
    510517      return metaLevelAlgorithm;
     
    540547    }
    541548
    542     private static ParameterConfigurationTree SetupGAAlgorithm(GeneticAlgorithm baseLevelAlgorithm, MetaOptimizationProblem metaOptimizationProblem) {
    543       baseLevelAlgorithm.Problem = new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem();
    544       baseLevelAlgorithm.MaximumGenerations.Value = baseAlgorithmMaxGenerations;
    545 
    546       metaOptimizationProblem.Algorithm = baseLevelAlgorithm;
     549    private static ParameterConfigurationTree SetupGAAlgorithm(Type baseLevelAlgorithmType, MetaOptimizationProblem metaOptimizationProblem) {
     550      metaOptimizationProblem.AlgorithmType.Value = baseLevelAlgorithmType;
     551      metaOptimizationProblem.ProblemType.Value = typeof(SingleObjectiveTestFunctionProblem);
    547552      ParameterConfigurationTree algorithmVc = metaOptimizationProblem.ParameterConfigurationTree;
     553      ((IntValue)algorithmVc.ParameterConfigurations.Single(x => x.Name == "MaximumGenerations").ActualValue.Value).Value = baseAlgorithmMaxGenerations;
    548554
    549555      metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/HeuristicLab.Problems.MetaOptimization.Views-3.3.csproj

    r5303 r5313  
    132132      <DependentUpon>ConstrainedItemListView.cs</DependentUpon>
    133133    </Compile>
     134    <Compile Include="ConstrainedTypeValueView.cs">
     135      <SubType>UserControl</SubType>
     136    </Compile>
     137    <Compile Include="ConstrainedTypeValueView.Designer.cs">
     138      <DependentUpon>ConstrainedTypeValueView.cs</DependentUpon>
     139    </Compile>
     140    <Compile Include="CreateExperimentDialog.cs">
     141      <SubType>Form</SubType>
     142    </Compile>
     143    <Compile Include="CreateExperimentDialog.Designer.cs">
     144      <DependentUpon>CreateExperimentDialog.cs</DependentUpon>
     145    </Compile>
    134146    <Compile Include="ItemDictionaryView.cs">
    135147      <SubType>UserControl</SubType>
     
    201213  </ItemGroup>
    202214  <ItemGroup>
     215    <EmbeddedResource Include="ConstrainedTypeValueView.resx">
     216      <DependentUpon>ConstrainedTypeValueView.cs</DependentUpon>
     217    </EmbeddedResource>
     218    <EmbeddedResource Include="CreateExperimentDialog.resx">
     219      <DependentUpon>CreateExperimentDialog.cs</DependentUpon>
     220    </EmbeddedResource>
    203221    <EmbeddedResource Include="ItemDictionaryView.resx">
    204222      <DependentUpon>ItemDictionaryView.cs</DependentUpon>
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/MetaOptimizationProblemView.Designer.cs

    r5144 r5313  
    3030      // parameterCollectionView
    3131      //
     32      this.parameterCollectionView.AllowDrop = true;
    3233      this.parameterCollectionView.Size = new System.Drawing.Size(604, 353);
     34      this.parameterCollectionView.DragDrop += new System.Windows.Forms.DragEventHandler(this.parameterCollectionView_DragDrop);
     35      this.parameterCollectionView.DragEnter += new System.Windows.Forms.DragEventHandler(this.parameterCollectionView_DragEnterOver);
     36      this.parameterCollectionView.DragOver += new System.Windows.Forms.DragEventHandler(this.parameterCollectionView_DragEnterOver);
    3337      //
    3438      // nameTextBox
     
    4650      this.createExperimentButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
    4751                  | System.Windows.Forms.AnchorStyles.Right)));
    48       this.createExperimentButton.Location = new System.Drawing.Point(0, 405);
     52      this.createExperimentButton.Location = new System.Drawing.Point(0, 411);
    4953      this.createExperimentButton.Name = "createExperimentButton";
    50       this.createExperimentButton.Size = new System.Drawing.Size(604, 31);
     54      this.createExperimentButton.Size = new System.Drawing.Size(604, 24);
    5155      this.createExperimentButton.TabIndex = 5;
    52       this.createExperimentButton.Text = "Create Experiment";
     56      this.createExperimentButton.Text = "Create Combinations";
    5357      this.createExperimentButton.UseVisualStyleBackColor = true;
    5458      this.createExperimentButton.Click += new System.EventHandler(this.createExperimentButton_Click);
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/MetaOptimizationProblemView.cs

    r5184 r5313  
    99using HeuristicLab.Optimization.Views;
    1010using HeuristicLab.Optimization;
     11using System.Windows.Forms;
    1112
    1213namespace HeuristicLab.Problems.MetaOptimization.Views {
     
    6263        }
    6364        if (result == System.Windows.Forms.DialogResult.OK) {
    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);
     65          CreateExperimentDialog dlg = new CreateExperimentDialog();
     66          DialogResult dlgResult = dlg.ShowDialog();
     67
     68          if (dlgResult == DialogResult.OK) {
     69            EngineAlgorithm algorithm = Content.Algorithm;
     70            if(Content.Problems.Count > 0) algorithm.Problem = Content.Problems.First();
     71            Experiment experiment;
     72
     73            if (dlg.CreateBatchRuns) {
     74              experiment = Content.ParameterConfigurationTree.GenerateExperiment(algorithm, true, dlg.Repetitions);
     75            } else {
     76              experiment = Content.ParameterConfigurationTree.GenerateExperiment(algorithm);
     77            }
     78            MainFormManager.MainForm.ShowContent(experiment);
    6979          }
    70           MainFormManager.MainForm.ShowContent(experiment);
    7180        }
    7281      }
     
    7483
    7584    #endregion
     85
     86    protected void parameterCollectionView_DragEnterOver(object sender, System.Windows.Forms.DragEventArgs e) {
     87      e.Effect = DragDropEffects.None;
     88      Type type = e.Data.GetData("Type") as Type;
     89      if ((type != null) && (Content.AlgorithmType.ValidTypes.Contains(type))) {
     90        EngineAlgorithm algorithm = e.Data.GetData("Value") as EngineAlgorithm;
     91        if (algorithm.Problem == null || Content.ProblemType.ValidTypes.Contains(algorithm.Problem.GetType())) {
     92          e.Effect = DragDropEffects.Copy;
     93        }
     94      }
     95    }
     96    protected void parameterCollectionView_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) {
     97      if (e.Effect != DragDropEffects.None) {
     98        EngineAlgorithm algorithm = e.Data.GetData("Value") as EngineAlgorithm;
     99        Content.ImportAlgorithm(algorithm);
     100      }
     101    }
    76102  }
    77103}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/MetaOptimizationProblemView.resx

    r5144 r5313  
    113113  </resheader>
    114114  <resheader name="reader">
    115     <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
     115    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    116116  </resheader>
    117117  <resheader name="writer">
    118     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
     118    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    119119  </resheader>
    120   <metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     120  <metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
    121121    <value>107, 17</value>
    122122  </metadata>
    123   <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     123  <metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     124    <value>107, 17</value>
     125  </metadata>
     126  <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
    124127    <value>17, 17</value>
    125128  </metadata>
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurationTree.cs

    r5303 r5313  
    105105    }
    106106
     107    [Storable]
     108    protected string name;
     109    public string Name {
     110      get { return name; }
     111      set { name = value; }
     112    }
     113
    107114    #region constructors and cloning
    108115    public ParameterConfigurationTree(EngineAlgorithm algorithm)
     
    110117      this.Optimize = true; // root must always be optimized
    111118      this.parameters = new Dictionary<string, IItem>();
    112 
     119      this.Name = algorithm.ItemName;
    113120      PopulateParameterConfigurations(algorithm);
    114121    }
     
    119126    protected ParameterConfigurationTree(ParameterConfigurationTree original, Cloner cloner)
    120127      : base(original, cloner) {
     128      this.name = original.name;
    121129      this.bestQualities = cloner.Clone(original.BestQualities);
    122130      this.averageQualities = cloner.Clone(original.averageQualities);
     
    186194        if (createBatchRuns) {
    187195          BatchRun batchRun = new BatchRun(string.Format("BatchRun: {0}", combination.ParameterInfoString));
    188           batchRun.Algorithm = clonedAlg;
     196          batchRun.Optimizer = clonedAlg;
    189197          batchRun.Repetitions = repetitions;
    190198          experiment.Optimizers.Add(batchRun);
     
    218226      return allOptimizables[random.Next(allOptimizables.Count)];
    219227    }
     228
     229    public override string ToString() {
     230      return this.Name;
     231    }
    220232  }
    221233}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs

    r5303 r5313  
    1313using HeuristicLab.Optimization;
    1414using HeuristicLab.Collections;
     15using System.Drawing;
    1516
    1617namespace HeuristicLab.Problems.MetaOptimization {
     
    4344
    4445    [Storable]
     46    private Image itemImage;
     47    public virtual Image ItemImage {
     48      get { return itemImage ?? base.ItemImage; }
     49    }
     50
     51    [Storable]
    4552    protected string parameterName;
    4653    public string ParameterName {
     
    133140      this.validTypes = GetValidTypes(valueParameter).ToArray();
    134141      this.IsNullable = valueParameter.ItemName.StartsWith("Optional");
     142      this.itemImage = valueParameter.ItemImage;
    135143      if (IsNullable) {
    136144        validTypes = new List<Type>(validTypes) { typeof(NullValue) }.ToArray();
    137145      }
    138       this.ValueConfigurations = new CheckedValueConfigurationList();
     146      this.ValueConfigurations = new CheckedValueConfigurationList(this.validValues ?? CreateValidValues());
    139147      this.ActualValue = new ConstrainedValue(
    140148        valueParameter.Value != null ? (IItem)valueParameter.Value.Clone() : null,
     
    162170      this.actualValueConfigurationIndex = original.actualValueConfigurationIndex;
    163171      this.isNullable = original.isNullable;
     172      this.itemImage = original.itemImage;
    164173      if (this.valueConfigurations != null) RegisterValueConfigurationEvents();
    165174    }
     
    246255    }
    247256
    248     private ItemSet<IItem> CreateValidValues() {
     257    private IItemSet<IItem> CreateValidValues() {
    249258      var validValues = new ItemSet<IItem>();
    250259      foreach (Type t in this.validTypes) {
     
    295304    }
    296305    public override string ItemDescription {
    297       //get { return parameter != null ? parameter.Description : base.ItemDescription; }
    298306      get { return base.ItemDescription; }
    299307    }
    300     public override System.Drawing.Image ItemImage {
    301       //get { return parameter != null ? parameter.ItemImage : base.ItemImage; }
    302       get { return base.ItemImage; }
    303     }
    304308    public override string ItemName {
    305       //get { return parameter != null ?parameter.ItemName : base.ItemName; }
    306309      get { return base.ItemName; }
    307310    }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/CheckedValueConfigurationCollection.cs

    r5277 r5313  
    2525    }
    2626
    27     public CheckedValueConfigurationList(ItemSet<IItem> validValues) {
     27    public CheckedValueConfigurationList(IItemSet<IItem> validValues) {
    2828      this.validValues = validValues;
    2929      RegisterEvents();
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/ParameterConfigurationEvaluator.cs

    r5303 r5313  
    2727      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
    2828    }
    29     public ILookupParameter<EngineAlgorithm> AlgorithmParameter {
    30       get { return (ILookupParameter<EngineAlgorithm>)Parameters[MetaOptimizationProblem.AlgorithmTypeParameterName]; }
     29    public ILookupParameter<TypeValue> AlgorithmTypeParameter {
     30      get { return (ILookupParameter<TypeValue>)Parameters[MetaOptimizationProblem.AlgorithmTypeParameterName]; }
    3131    }
    3232    public ILookupParameter<IItemList<ISingleObjectiveProblem>> ProblemsParameter {
     
    5757      : base() {
    5858      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The evaluated quality of the ParameterVector."));
    59       Parameters.Add(new LookupParameter<EngineAlgorithm>(MetaOptimizationProblem.AlgorithmTypeParameterName, "Missing description."));
     59      Parameters.Add(new LookupParameter<TypeValue>(MetaOptimizationProblem.AlgorithmTypeParameterName, "Missing description."));
    6060      Parameters.Add(new LookupParameter<IItemList<ISingleObjectiveProblem>>(MetaOptimizationProblem.ProblemsParameterName, "Missing description."));
    6161      Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "Missing description."));
     
    7777    public override IOperation Apply() {
    7878      ParameterConfigurationTree parameterConfiguration = ParameterConfigurationParameter.ActualValue;
    79       EngineAlgorithm algorithm = (EngineAlgorithm)AlgorithmParameter.ActualValue;
     79      EngineAlgorithm algorithm = (EngineAlgorithm)Activator.CreateInstance(AlgorithmTypeParameter.ActualValue.Value);
    8080      IItemList<ISingleObjectiveProblem> problems = ProblemsParameter.ActualValue;
    8181      ItemDictionary<StringValue, RunCollection> runsCache = ResultsParameter.ActualValue.ContainsKey("Runs") ? (ItemDictionary<StringValue, RunCollection>)ResultsParameter.ActualValue["Runs"].Value : null;
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj

    r5303 r5313  
    133133  <ItemGroup>
    134134    <Compile Include="Analyzers\BestParameterConfigurationAnalyzer.cs" />
     135    <Compile Include="ConstrainedTypeValue.cs" />
     136    <Compile Include="TypeValue.cs" />
    135137    <None Include="Properties\AssemblyInfo.cs.frame" />
    136138    <None Include="HeuristicLabProblemsMetaOptimizationPlugin.cs.frame" />
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs

    r5303 r5313  
    4040    public const string ProblemTypeParameterName = "ProblemType";
    4141    public const string ProblemsParameterName = "Problems";
    42     public const string ParameterConfigurationTreeParameterName = "InitialParameterConfigurationTree";
     42    public const string ParameterConfigurationTreeParameterName = "ParameterConfigurationTree";
    4343    public const string RepetitionsParameterName = "Repetitions";
    4444
     
    4949
    5050    #region Parameter Properties
    51     public IValueParameter<EngineAlgorithm> AlgorithmTypeParameter {
    52       get { return (ValueParameter<EngineAlgorithm>)Parameters[AlgorithmTypeParameterName]; }
    53     }
    54     public IValueParameter<ISingleObjectiveProblem> ProblemTypeParameter {
    55       get { return (ValueParameter<ISingleObjectiveProblem>)Parameters[ProblemTypeParameterName]; }
     51    public IValueParameter<ConstrainedTypeValue<EngineAlgorithm>> AlgorithmTypeParameter {
     52      get { return (ValueParameter<ConstrainedTypeValue<EngineAlgorithm>>)Parameters[AlgorithmTypeParameterName]; }
     53    }
     54    public IValueParameter<ConstrainedTypeValue<ISingleObjectiveProblem>> ProblemTypeParameter {
     55      get { return (ValueParameter<ConstrainedTypeValue<ISingleObjectiveProblem>>)Parameters[ProblemTypeParameterName]; }
    5656    }
    5757    public IValueParameter<ConstrainedItemList<ISingleObjectiveProblem>> ProblemsParameter {
     
    7676    #region Properties
    7777    public EngineAlgorithm Algorithm {
     78      get { return CreateAlgorithm(AlgorithmType.Value, ProblemType.Value); }
     79    }
     80    public ConstrainedTypeValue<EngineAlgorithm> AlgorithmType {
    7881      get { return AlgorithmTypeParameter.Value; }
    7982      set { AlgorithmTypeParameter.Value = value; }
    8083    }
    81     public ISingleObjectiveProblem Problem {
     84    public ConstrainedTypeValue<ISingleObjectiveProblem> ProblemType {
    8285      get { return ProblemTypeParameter.Value; }
    8386      set { ProblemTypeParameter.Value = value; }
     
    108111    public MetaOptimizationProblem()
    109112      : base() {
    110       Parameters.Add(new ValueParameter<EngineAlgorithm>(AlgorithmTypeParameterName, "The algorithm which's parameters should be optimized.", new GeneticAlgorithm()));
    111       Parameters.Add(new ValueParameter<ISingleObjectiveProblem>(ProblemTypeParameterName, "The problem type.", new SingleObjectiveTestFunctionProblem()));
     113      Parameters.Add(new ValueParameter<ConstrainedTypeValue<EngineAlgorithm>>(AlgorithmTypeParameterName, "The algorithm which's parameters should be optimized.", new ConstrainedTypeValue<EngineAlgorithm>(typeof(GeneticAlgorithm))));
     114      Parameters.Add(new ValueParameter<ConstrainedTypeValue<ISingleObjectiveProblem>>(ProblemTypeParameterName, "The problem type.", new ConstrainedTypeValue<ISingleObjectiveProblem>(typeof(SingleObjectiveTestFunctionProblem))));
    112115      Parameters.Add(new ValueParameter<ConstrainedItemList<ISingleObjectiveProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ConstrainedItemList<ISingleObjectiveProblem>()));
    113116      Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfigurationTreeParameterName, "Tree of algorithm parameters that should be optimized."));
     
    134137      ParameterizeOperators();
    135138
    136       Problems.Type = Problem.GetType();
    137       Algorithm.Problem = Problem;
    138       ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm);
     139      ProblemTypeParameter_ValueChanged(this, EventArgs.Empty);
    139140    }
    140141
     
    143144    private MetaOptimizationProblem(MetaOptimizationProblem original, Cloner cloner)
    144145      : base(original, cloner) {
    145       // todo
    146146      this.RegisterParameterEvents();
    147147    }
     
    160160      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    161161      AlgorithmTypeParameter.ValueChanged += new EventHandler(AlgorithmTypeParameter_ValueChanged);
     162      AlgorithmType.ValueChanged += new EventHandler(AlgorithmType_ValueChanged);
    162163      ProblemTypeParameter.ValueChanged += new EventHandler(ProblemTypeParameter_ValueChanged);
     164      ProblemType.ValueChanged += new EventHandler(ProblemType_ValueChanged);
    163165    }
    164166
     
    215217      ParameterizeAnalyzer();
    216218    }
    217     void AlgorithmTypeParameter_ValueChanged(object sender, EventArgs e) {
    218       Algorithm.Problem = Problem;
    219       ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm);
    220     }
    221     void ProblemTypeParameter_ValueChanged(object sender, EventArgs e) {
    222       Problems.Type = Problem.GetType();
    223       Algorithm.Problem = Problem;
    224       ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm);
    225     }
    226     #endregion
     219    private void AlgorithmTypeParameter_ValueChanged(object sender, EventArgs e) {
     220      AlgorithmType_ValueChanged(sender, e);
     221    }
     222
     223    private void AlgorithmType_ValueChanged(object sender, EventArgs e) {
     224      ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(CreateAlgorithm(AlgorithmType.Value, ProblemType.Value));
     225    }
     226
     227    private void ProblemTypeParameter_ValueChanged(object sender, EventArgs e) {
     228      ProblemType_ValueChanged(sender, e);
     229    }
     230
     231    private void ProblemType_ValueChanged(object sender, EventArgs e) {
     232      Problems.Clear();
     233      Problems.Type = ProblemType.Value;
     234      ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(CreateAlgorithm(AlgorithmType.Value, ProblemType.Value));
     235    }
     236    #endregion
     237
     238    private EngineAlgorithm CreateAlgorithm(Type algorithmType, Type problemType) {
     239      EngineAlgorithm algorithm = (EngineAlgorithm)Activator.CreateInstance(algorithmType);
     240      algorithm.Problem = (IProblem)Activator.CreateInstance(problemType);
     241      return algorithm;
     242    }
     243
     244    public void ImportAlgorithm(EngineAlgorithm algorithm) {
     245      AlgorithmType.Value = algorithm.GetType();
     246      if(algorithm.Problem != null) ProblemType.Value = algorithm.Problem.GetType();
     247      ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(algorithm);
     248      if(algorithm.Problem != null) Problems.Add((ISingleObjectiveProblem)algorithm.Problem);
     249    }
    227250  }
    228251}
Note: See TracChangeset for help on using the changeset viewer.