Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/20/11 01:30:44 (13 years ago)
Author:
cneumuel
Message:

#1215

  • made all IAlgorithm types compatible to be loaded into MetaOptimization.
  • valid problem types are now automatically set
File:
1 edited

Legend:

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

    r5328 r5337  
    4949
    5050    #region Parameter Properties
    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]; }
    56     }
    57     public IValueParameter<ConstrainedItemList<ISingleObjectiveProblem>> ProblemsParameter {
    58       get { return (ValueParameter<ConstrainedItemList<ISingleObjectiveProblem>>)Parameters[ProblemsParameterName]; }
     51    public IValueParameter<ConstrainedTypeValue<IAlgorithm>> AlgorithmTypeParameter {
     52      get { return (ValueParameter<ConstrainedTypeValue<IAlgorithm>>)Parameters[AlgorithmTypeParameterName]; }
     53    }
     54    public IValueParameter<ConstrainedTypeValue<IProblem>> ProblemTypeParameter {
     55      get { return (ValueParameter<ConstrainedTypeValue<IProblem>>)Parameters[ProblemTypeParameterName]; }
     56    }
     57    public IValueParameter<ConstrainedItemList<IProblem>> ProblemsParameter {
     58      get { return (ValueParameter<ConstrainedItemList<IProblem>>)Parameters[ProblemsParameterName]; }
    5959    }
    6060    public IValueParameter<ParameterConfigurationTree> ParameterConfigurationTreeParameter {
     
    7575
    7676    #region Properties
    77     public EngineAlgorithm Algorithm {
     77    public IAlgorithm Algorithm {
    7878      get { return CreateAlgorithm(AlgorithmType.Value, ProblemType.Value); }
    7979    }
    80     public ConstrainedTypeValue<EngineAlgorithm> AlgorithmType {
     80    public ConstrainedTypeValue<IAlgorithm> AlgorithmType {
    8181      get { return AlgorithmTypeParameter.Value; }
    8282      set { AlgorithmTypeParameter.Value = value; }
    8383    }
    84     public ConstrainedTypeValue<ISingleObjectiveProblem> ProblemType {
     84    public ConstrainedTypeValue<IProblem> ProblemType {
    8585      get { return ProblemTypeParameter.Value; }
    8686      set { ProblemTypeParameter.Value = value; }
    8787    }
    88     public ConstrainedItemList<ISingleObjectiveProblem> Problems {
     88    public ConstrainedItemList<IProblem> Problems {
    8989      get { return ProblemsParameter.Value; }
    9090      set { ProblemsParameter.Value = value; }
     
    111111    public MetaOptimizationProblem()
    112112      : base() {
    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))));
    115       Parameters.Add(new ValueParameter<ConstrainedItemList<ISingleObjectiveProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ConstrainedItemList<ISingleObjectiveProblem>()));
     113      Parameters.Add(new ValueParameter<ConstrainedTypeValue<IAlgorithm>>(AlgorithmTypeParameterName, "The algorithm which's parameters should be optimized.", new ConstrainedTypeValue<IAlgorithm>(typeof(GeneticAlgorithm))));
     114      Parameters.Add(new ValueParameter<ConstrainedTypeValue<IProblem>>(ProblemTypeParameterName, "The problem type.", new ConstrainedTypeValue<IProblem>()));
     115      Parameters.Add(new ValueParameter<ConstrainedItemList<IProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ConstrainedItemList<IProblem>()));
    116116      Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfigurationTreeParameterName, "Tree of algorithm parameters that should be optimized."));
    117117      Parameters.Add(new ValueParameter<IntValue>(RepetitionsParameterName, "The number of evaluations for each problem.", new IntValue(3)));
     
    137137      ParameterizeOperators();
    138138
    139       ProblemTypeParameter_ValueChanged(this, EventArgs.Empty);
     139      AlgorithmTypeParameter_ValueChanged(this, EventArgs.Empty);
    140140    }
    141141
     
    222222
    223223    private void AlgorithmType_ValueChanged(object sender, EventArgs e) {
     224      IAlgorithm instance = (IAlgorithm)Activator.CreateInstance(AlgorithmType.Value);
     225      this.ProblemType.ValidTypes = ApplicationManager.Manager.GetTypes(instance.ProblemType, true).ToList();
     226      this.ProblemType.Value = this.ProblemType.ValidTypes.First();
    224227      ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(CreateAlgorithm(AlgorithmType.Value, ProblemType.Value));
    225228    }
     
    236239    #endregion
    237240
    238     private EngineAlgorithm CreateAlgorithm(Type algorithmType, Type problemType) {
    239       EngineAlgorithm algorithm = (EngineAlgorithm)Activator.CreateInstance(algorithmType);
     241    private IAlgorithm CreateAlgorithm(Type algorithmType, Type problemType) {
     242      IAlgorithm algorithm = (IAlgorithm)Activator.CreateInstance(algorithmType);
    240243      algorithm.Problem = (IProblem)Activator.CreateInstance(problemType);
    241244      return algorithm;
    242245    }
    243246
    244     public void ImportAlgorithm(EngineAlgorithm algorithm) {
     247    public void ImportAlgorithm(IAlgorithm algorithm) {
    245248      AlgorithmType.Value = algorithm.GetType();
    246       if(algorithm.Problem != null) ProblemType.Value = algorithm.Problem.GetType();
     249      if (algorithm.Problem != null) ProblemType.Value = algorithm.Problem.GetType();
    247250      ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(algorithm);
    248       if(algorithm.Problem != null) Problems.Add((ISingleObjectiveProblem)algorithm.Problem);
     251      if (algorithm.Problem != null) Problems.Add((IProblem)algorithm.Problem);
    249252    }
    250253  }
Note: See TracChangeset for help on using the changeset viewer.