Index: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
===================================================================
--- branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs	(revision 4525)
+++ branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs	(revision 4830)
@@ -36,156 +36,78 @@
   [Creatable("Problems")]
   [StorableClass]
-  public sealed class MetaOptimizationProblem : ParameterizedNamedItem, ISingleObjectiveProblem, IStorableContent {
-    public string Filename { get; set; }
-
-    public override Image ItemImage {
-      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; }
-    }
+  public sealed class MetaOptimizationProblem : SingleObjectiveProblem<IMetaOptimizationEvaluator, IParameterConfigurationCreator> {
+    private const string AlgorithmParameterName = "Algorithm";
+    private const string ProblemsParameterName = "Problems";
+    private const string AlgorithmParameterConfigurationParameterName = "AlgorithmParameterConfiguration";
+    private const string ProblemParametersConfigurationParameterName = "ProblemParametersConfiguration";
 
     #region Parameter Properties
-
-    public ValueParameter<IntValue> RepetitionsParameter {
-      get { return (ValueParameter<IntValue>)Parameters["Repetitions"]; }
+    public ValueParameter<IAlgorithm> AlgorithmParameter {
+      get { return (ValueParameter<IAlgorithm>)Parameters[AlgorithmParameterName]; }
     }
-
-    public ValueParameter<IParameterSetCreator> SolutionCreatorParameter {
-      get { return (ValueParameter<IParameterSetCreator>)Parameters["SolutionCreator"]; }
+    public ValueParameter<IItemList<ISingleObjectiveProblem>> ProblemsParameter {
+      get { return (ValueParameter<IItemList<ISingleObjectiveProblem>>)Parameters[ProblemsParameterName]; }
     }
-    IParameter IProblem.SolutionCreatorParameter {
-      get { return SolutionCreatorParameter; }
+    public ValueParameter<IParameterConfiguration> AlgorithmParameterConfigurationParameter {
+      get { return (ValueParameter<IParameterConfiguration>)Parameters[AlgorithmParameterConfigurationParameterName]; }
     }
-
-    public ValueParameter<IMetaOptimizationEvaluator> EvaluatorParameter {
-      get { return (ValueParameter<IMetaOptimizationEvaluator>)Parameters["Evaluator"]; }
-    }
-    IParameter IProblem.EvaluatorParameter {
-      get { return EvaluatorParameter; }
-    }
-
-    public OptionalValueParameter<ParameterSet> BestKnownSolutionParameter {
-      get { return (OptionalValueParameter<ParameterSet>)Parameters["BestKnownSolution"]; }
-    }
-
-    public ValueParameter<BoolValue> MaximizationParameter {
-      get { return (ValueParameter<BoolValue>)Parameters["Maximization"]; }
-    }
-    IParameter ISingleObjectiveProblem.MaximizationParameter {
-      get { return MaximizationParameter; }
-    }
-
-    public OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
-      get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
-    }
-    IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
-      get { return BestKnownQualityParameter; }
-    }
-
-    public ValueParameter<IAlgorithm> AlgorithmParameter {
-      get { return (ValueParameter<IAlgorithm>)Parameters["Algorithm"]; }
-    }
-    public ValueParameter<ParameterConfigurationList> ParametersToOptimizeParameter {
-      get { return (ValueParameter<ParameterConfigurationList>)Parameters["ParametersToOptimize"]; }
-    }
+    //public ValueParameter<IItemList<IParameterConfiguration>> ProblemParametersConfigurationParameter {
+    //  get { return (ValueParameter<IItemList<IParameterConfiguration>>)Parameters[ProblemParametersConfigurationParameterName]; }
+    //}
     #endregion
 
     #region Properties
-
-    public IntValue Repetitions {
-      get { return RepetitionsParameter.Value; }
-      set { RepetitionsParameter.Value = value; }
-    }
-
-    public IEnumerable<IOperator> Operators {
-      get { return operators; }
-    }
-
-    IEvaluator IProblem.Evaluator {
-      get { return EvaluatorParameter.Value; }
-    }
-    public IMetaOptimizationEvaluator Evaluator {
-      get { return EvaluatorParameter.Value; }
-      set { EvaluatorParameter.Value = value; }
-    }
-
-    ISolutionCreator IProblem.SolutionCreator {
-      get { return SolutionCreatorParameter.Value; }
-    }
-    public IParameterSetCreator SolutionCreator {
-      get { return SolutionCreatorParameter.Value; }
-    }
-
-    ISingleObjectiveEvaluator ISingleObjectiveProblem.Evaluator {
-      get { return this.Evaluator; }
-    }
-
-    public DoubleValue BestKnownQuality {
-      get { return BestKnownQualityParameter.Value; }
-      set { BestKnownQualityParameter.Value = value; }
-    }
-    public ParameterSet BestKnownSolution {
-      get { return BestKnownSolutionParameter.Value; }
-      set { BestKnownSolutionParameter.Value = value; }
-    }
-
     public IAlgorithm Algorithm {
       get { return AlgorithmParameter.Value; }
       set { AlgorithmParameter.Value = value; }
     }
-
-    public ParameterConfigurationList ParametersToOptimize {
-      get { return ParametersToOptimizeParameter.Value; }
-      set { ParametersToOptimizeParameter.Value = value; }
+    public IItemList<ISingleObjectiveProblem> Problems {
+      get { return ProblemsParameter.Value; }
+      set { ProblemsParameter.Value = value; }
     }
-
-    private BestQualityAnalyzer BestQualityAnalyzer {
-      get { return operators.OfType<BestQualityAnalyzer>().FirstOrDefault(); }
+    public IParameterConfiguration AlgorithmParameterConfiguration {
+      get { return AlgorithmParameterConfigurationParameter.Value; }
+      set { AlgorithmParameterConfigurationParameter.Value = value; }
     }
+    //public IItemList<IParameterConfiguration> ProblemParametersConfiguration {
+    //  get { return ProblemParametersConfigurationParameter.Value; }
+    //  set { ProblemParametersConfigurationParameter.Value = value; }
+    //}
     #endregion
 
-    [Storable]
-    private List<IOperator> operators;
+    public MetaOptimizationProblem()
+      : base() {
+      Parameters.Add(new ValueParameter<IAlgorithm>(AlgorithmParameterName, "The algorithm which's parameters should be optimized."));
+      Parameters.Add(new ValueParameter<IItemList<IProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ItemList<IProblem>()));
+      Parameters.Add(new ValueParameter<IParameterConfiguration>(AlgorithmParameterConfigurationParameterName, "List of algorithm parameters that should be optimized."));
+      //Parameters.Add(new ValueParameter<IItemList<IParameterConfiguration>>(ProblemParametersConfigurationParameterName, "List of problem parameters that should be optimized.", new ItemList<IParameterConfiguration>()));
+      
+      Maximization = new BoolValue(false);
+      SolutionCreator = new RandomParameterConfigurationCreator();
+      Evaluator = new MetaOptimizationEvaluator();
+
+      InitializeOperators();
+      RegisterParameterEvents();
+      ParameterizeSolutionCreator();
+      ParameterizeEvaluator();
+      ParameterizeOperators();
+    }
 
     [StorableConstructor]
     private MetaOptimizationProblem(bool deserializing) : base(deserializing) { }
-    public MetaOptimizationProblem()
-      : base() {
-
-      IParameterSetCreator creator = new RandomParameterSetCreator();
-      MetaOptimizationEvaluator evaluator = new MetaOptimizationEvaluator();
-      ParameterConfigurationList parametersToOptimize = new ParameterConfigurationList();
-
-      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the Traveling Salesman Problem is a minimization problem.", new BoolValue(false)));
-      Parameters.Add(new ValueParameter<IntValue>("Repetitions", "Number of evaluations for one individual.", new IntValue(3)));
-      Parameters.Add(new ValueParameter<IParameterSetCreator>("SolutionCreator", "The operator which should be used to create new TSP solutions.", creator));
-      Parameters.Add(new ValueParameter<IMetaOptimizationEvaluator>("Evaluator", "The operator which should be used to evaluate TSP solutions.", evaluator));
-      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this TSP instance."));
-      Parameters.Add(new OptionalValueParameter<ParameterSet>("BestKnownSolution", "The best known solution of this TSP instance."));
-
-      Parameters.Add(new ValueParameter<IAlgorithm>("Algorithm", "The algorithm and problem which's parameters should be optimized."));
-      Parameters.Add(new ValueParameter<ParameterConfigurationList>("ParametersToOptimize", "List of parameters that should be optimized.", parametersToOptimize));
-
-      ParameterizeSolutionCreator();
-      ParameterizeEvaluator();
-
-      InitializeOperators();
-      AttachEventHandlers();
+    private MetaOptimizationProblem(MetaOptimizationProblem original, Cloner cloner) : base(original, cloner) {
+      // todo
+      this.RegisterParameterEvents();
     }
-
-    #region Cloning
     public override IDeepCloneable Clone(Cloner cloner) {
-      MetaOptimizationProblem clone = (MetaOptimizationProblem)base.Clone(cloner);
-      clone.operators = operators.Select(x => (IOperator)cloner.Clone(x)).ToList();
-      // todo
-      clone.AttachEventHandlers();
-      return clone;
+      return new MetaOptimizationProblem(this, cloner);
     }
-    #endregion
 
     #region Helpers
     [StorableHook(HookType.AfterDeserialization)]
     private void AfterDeserializationHook() {
-      AttachEventHandlers();
+      RegisterParameterEvents();
     }
-    private void AttachEventHandlers() {
+    private void RegisterParameterEvents() {
       SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
       EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
@@ -194,80 +116,23 @@
     }
     private void InitializeOperators() {
-      operators = new List<IOperator>();
-      operators.Add(new BestQualityAnalyzer());
-      ParameterizeAnalyzer();
-      operators.AddRange(ApplicationManager.Manager.GetInstances<IParameterSetOperator>().Cast<IOperator>());
-      ParameterizeOperators();
-
-      //UpdateMoveEvaluators();
-      //InitializeMoveGenerators();
+      Operators.AddRange(ApplicationManager.Manager.GetInstances<IParameterConfigurationOperator>().Cast<IOperator>());
+      Operators.Add(new BestParameterConfigurationAnalyzer());
     }
     private void ParameterizeSolutionCreator() {
-      SolutionCreator.ParametersToOptimize = this.ParametersToOptimize;
+      //SolutionCreator.ParametersToOptimize = this.ParametersToOptimize;
     }
     private void ParameterizeEvaluator() {
+      ((MetaOptimizationEvaluator)Evaluator).ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
     }
     private void ParameterizeAnalyzer() {
-      BestQualityAnalyzer.ResultsParameter.ActualName = "Results";
+      //BestQualityAnalyzer.ResultsParameter.ActualName = "Results";
     }
     private void ParameterizeOperators() {
+      
     }
 
-    private void AddAlgorithmParameters() {
-      foreach (IParameter parameter in Algorithm.Parameters) {
-        this.ParametersToOptimize.Add(new NumericParameterConfiguration(parameter, "Algorithm"), false);
-      }
-    }
-    private void RemoveAlgorithmParameters() {
-      foreach (IParameter parameter in Algorithm.Parameters) {
-        IParameterConfiguration parameterConfiguration = this.ParametersToOptimize.Single(p => p.Parameter == parameter);
-        if (parameterConfiguration != null) {
-          this.ParametersToOptimize.Remove(parameterConfiguration);
-        }
-      }
-    }
-    private void ClearAlgorithmParameters() {
-      //this.ParametersToOptimize.Clear();
-    }
-
-    private void AddProblemParameters() {
-      foreach (IParameter parameter in Algorithm.Problem.Parameters) {
-        this.ParametersToOptimize.Add(new NumericParameterConfiguration(parameter, "Problem"), false);
-      }
-    }
-    private void RemoveProblemParameters() {
-      foreach (IParameter parameter in Algorithm.Problem.Parameters) {
-        IParameterConfiguration parameterConfiguration = this.ParametersToOptimize.Single(p => p.Parameter == parameter);
-        if (parameterConfiguration != null) {
-          this.ParametersToOptimize.Remove(parameterConfiguration);
-        }
-      }
-    }
-    private void ClearProblemParameters() {
-      //this.ParametersToOptimize.Clear();
-    }
     #endregion
 
     #region Events
-    public event EventHandler SolutionCreatorChanged;
-    private void OnSolutionCreatorChanged() {
-      EventHandler handler = SolutionCreatorChanged;
-      if (handler != null) handler(this, EventArgs.Empty);
-    }
-    public event EventHandler EvaluatorChanged;
-    private void OnEvaluatorChanged() {
-      EventHandler handler = EvaluatorChanged;
-      if (handler != null) handler(this, EventArgs.Empty);
-    }
-    public event EventHandler OperatorsChanged;
-    private void OnOperatorsChanged() {
-      EventHandler handler = OperatorsChanged;
-      if (handler != null) handler(this, EventArgs.Empty);
-    }
-    public event EventHandler Reset;
-    private void OnReset() {
-      EventHandler handler = Reset;
-      if (handler != null) handler(this, EventArgs.Empty);
-    }
 
     private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
@@ -288,8 +153,7 @@
     }
     void BaseLevelAlgorithmParameter_ValueChanged(object sender, EventArgs e) {
-      ClearAlgorithmParameters();
       if (Algorithm != null) {
         Algorithm.ProblemChanged += new EventHandler(BaseLevelAlgorithm_ProblemChanged);
-        AddAlgorithmParameters(); // TODO: When to Detach?
+        AlgorithmParameterConfiguration = ParameterConfiguration.Create(Algorithm);
       }
       BaseLevelAlgorithm_ProblemChanged(sender, e);
@@ -297,8 +161,8 @@
 
     void BaseLevelAlgorithm_ProblemChanged(object sender, EventArgs e) {
-      ClearProblemParameters();
-      if (Algorithm.Problem != null) {
-        AddProblemParameters();
-      }
+      //ClearProblemParameters();
+      //if (Algorithm.Problem != null) {
+      //  AddProblemParameters();
+      //}
     }
     #endregion
