Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/17/11 19:17:51 (13 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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.