Changeset 5337 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
- Timestamp:
- 01/20/11 01:30:44 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
r5328 r5337 49 49 50 50 #region Parameter Properties 51 public IValueParameter<ConstrainedTypeValue< EngineAlgorithm>> AlgorithmTypeParameter {52 get { return (ValueParameter<ConstrainedTypeValue< EngineAlgorithm>>)Parameters[AlgorithmTypeParameterName]; }53 } 54 public IValueParameter<ConstrainedTypeValue<I SingleObjectiveProblem>> ProblemTypeParameter {55 get { return (ValueParameter<ConstrainedTypeValue<I SingleObjectiveProblem>>)Parameters[ProblemTypeParameterName]; }56 } 57 public IValueParameter<ConstrainedItemList<I SingleObjectiveProblem>> ProblemsParameter {58 get { return (ValueParameter<ConstrainedItemList<I SingleObjectiveProblem>>)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]; } 59 59 } 60 60 public IValueParameter<ParameterConfigurationTree> ParameterConfigurationTreeParameter { … … 75 75 76 76 #region Properties 77 public EngineAlgorithm Algorithm {77 public IAlgorithm Algorithm { 78 78 get { return CreateAlgorithm(AlgorithmType.Value, ProblemType.Value); } 79 79 } 80 public ConstrainedTypeValue< EngineAlgorithm> AlgorithmType {80 public ConstrainedTypeValue<IAlgorithm> AlgorithmType { 81 81 get { return AlgorithmTypeParameter.Value; } 82 82 set { AlgorithmTypeParameter.Value = value; } 83 83 } 84 public ConstrainedTypeValue<I SingleObjectiveProblem> ProblemType {84 public ConstrainedTypeValue<IProblem> ProblemType { 85 85 get { return ProblemTypeParameter.Value; } 86 86 set { ProblemTypeParameter.Value = value; } 87 87 } 88 public ConstrainedItemList<I SingleObjectiveProblem> Problems {88 public ConstrainedItemList<IProblem> Problems { 89 89 get { return ProblemsParameter.Value; } 90 90 set { ProblemsParameter.Value = value; } … … 111 111 public MetaOptimizationProblem() 112 112 : 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<I SingleObjectiveProblem>>(ProblemTypeParameterName, "The problem type.", new ConstrainedTypeValue<ISingleObjectiveProblem>(typeof(SingleObjectiveTestFunctionProblem))));115 Parameters.Add(new ValueParameter<ConstrainedItemList<I SingleObjectiveProblem>>(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>())); 116 116 Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfigurationTreeParameterName, "Tree of algorithm parameters that should be optimized.")); 117 117 Parameters.Add(new ValueParameter<IntValue>(RepetitionsParameterName, "The number of evaluations for each problem.", new IntValue(3))); … … 137 137 ParameterizeOperators(); 138 138 139 ProblemTypeParameter_ValueChanged(this, EventArgs.Empty);139 AlgorithmTypeParameter_ValueChanged(this, EventArgs.Empty); 140 140 } 141 141 … … 222 222 223 223 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(); 224 227 ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(CreateAlgorithm(AlgorithmType.Value, ProblemType.Value)); 225 228 } … … 236 239 #endregion 237 240 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); 240 243 algorithm.Problem = (IProblem)Activator.CreateInstance(problemType); 241 244 return algorithm; 242 245 } 243 246 244 public void ImportAlgorithm( EngineAlgorithm algorithm) {247 public void ImportAlgorithm(IAlgorithm algorithm) { 245 248 AlgorithmType.Value = algorithm.GetType(); 246 if (algorithm.Problem != null) ProblemType.Value = algorithm.Problem.GetType();249 if (algorithm.Problem != null) ProblemType.Value = algorithm.Problem.GetType(); 247 250 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); 249 252 } 250 253 }
Note: See TracChangeset
for help on using the changeset viewer.