Changeset 9467 for branches/LearningClassifierSystems/HeuristicLab.Algorithms.LearningClassifierSystems
- Timestamp:
- 05/08/13 14:12:00 (12 years ago)
- Location:
- branches/LearningClassifierSystems
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LearningClassifierSystems
-
Property
svn:mergeinfo
set to
/trunk/sources/HeuristicLab.Core merged eligible
-
Property
svn:mergeinfo
set to
-
branches/LearningClassifierSystems/HeuristicLab.Algorithms.LearningClassifierSystems/3.3/LearningClassifierSystem.cs
r9242 r9467 118 118 get { return (ValueParameter<IntValue>)Parameters["MaxIterations"]; } 119 119 } 120 public IConstrainedValueParameter<ISelector> SelectorParameter { 121 get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; } 122 } 120 123 public IConstrainedValueParameter<ICrossover> CrossoverParameter { 121 124 get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; } … … 213 216 get { return FinalAnalyzerParameter.Value; } 214 217 set { FinalAnalyzerParameter.Value = value; } 218 } 219 public ISelector Selector { 220 get { return SelectorParameter.Value; } 221 set { SelectorParameter.Value = value; } 215 222 } 216 223 public ICrossover Crossover { … … 254 261 Parameters.Add(new ValueParameter<MultiAnalyzer>("FinalAnalyzer", "The operator used to analyze the last generation.", new MultiAnalyzer())); 255 262 Parameters.Add(new ValueParameter<IntValue>("MaxIterations", "The maximum number of iterations.", new IntValue(1000))); 263 Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions.")); 256 264 Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.")); 257 265 Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.")); … … 276 284 mainLoop.FinalAnalyzerParameter.ActualName = FinalAnalyzerParameter.Name; 277 285 mainLoop.MaxIterationsParameter.ActualName = MaxIterationsParameter.Name; 286 mainLoop.SelectorParameter.ActualName = SelectorParameter.Name; 278 287 mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name; 279 288 mainLoop.MutatorParameter.ActualName = MutatorParameter.Name; … … 303 312 ParameterizeEvaluator(Problem.Evaluator); 304 313 MainLoop.SetCurrentProblem(Problem); 314 UpdateSelectors(); 305 315 UpdateCrossovers(); 306 316 UpdateMutators(); 307 317 UpdateAnalyzers(); 318 ParameterizeSelectors(); 308 319 ParameterizeManipulator(); 309 320 } … … 311 322 } 312 323 313 private void ParameterizeManipulator() {314 foreach (var op in Problem.Operators.OfType<IProbabilityMutatorOperator>()) {315 op.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name;316 }317 }318 324 protected override void Problem_EvaluatorChanged(object sender, EventArgs e) { 319 325 ParameterizeEvaluator(Problem.Evaluator); … … 326 332 } 327 333 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { 334 UpdateSelectors(); 328 335 UpdateCrossovers(); 329 336 UpdateMutators(); 330 337 UpdateAnalyzers(); 338 ParameterizeSelectors(); 331 339 ParameterizeManipulator(); 332 340 base.Problem_OperatorsChanged(sender, e); 333 341 } 334 342 343 private void ParameterizeSelectors() { 344 foreach (ISelector selector in SelectorParameter.ValidValues) { 345 selector.CopySelected = new BoolValue(true); 346 selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(4); 347 selector.NumberOfSelectedSubScopesParameter.Hidden = true; 348 ParameterizeStochasticOperator(selector); 349 } 350 if (Problem != null) { 351 foreach (IXCSSelector selector in SelectorParameter.ValidValues.OfType<IXCSSelector>()) { 352 selector.NumerosityParameter.ActualName = Problem.Evaluator.NumerosityParameter.ActualName; 353 selector.NumerosityParameter.Hidden = true; 354 } 355 foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) { 356 selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 357 selector.MaximizationParameter.Hidden = true; 358 selector.QualityParameter.ActualName = Problem.Evaluator.FitnessParameter.ActualName; 359 selector.QualityParameter.Hidden = true; 360 } 361 } 362 } 363 private void ParameterizeManipulator() { 364 foreach (var op in Problem.Operators.OfType<IProbabilityMutatorOperator>()) { 365 op.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name; 366 } 367 } 335 368 private void ParameterizeEvaluator(IXCSEvaluator evaluator) { 336 369 evaluator.ActualTimeParameter.ActualName = "Iteration"; … … 339 372 evaluator.PowerParameter.ActualName = PowerParameter.Name; 340 373 evaluator.ErrorZeroParameter.ActualName = ErrorZeroParameter.Name; 374 } 375 private void ParameterizeStochasticOperator(IOperator op) { 376 IStochasticOperator stochasticOp = op as IStochasticOperator; 377 if (stochasticOp != null) { 378 stochasticOp.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; 379 stochasticOp.RandomParameter.Hidden = true; 380 } 381 } 382 383 private void UpdateSelectors() { 384 ISelector oldSelector = SelectorParameter.Value; 385 SelectorParameter.ValidValues.Clear(); 386 ISelector defaultSelector = Problem.Operators.OfType<IXCSSelector>().FirstOrDefault(); 387 if (defaultSelector == null) { 388 defaultSelector = Problem.Operators.OfType<ISelector>().FirstOrDefault(); 389 } 390 391 foreach (ISelector selector in Problem.Operators.OfType<ISelector>().OrderBy(x => x.Name)) 392 SelectorParameter.ValidValues.Add(selector); 393 394 if (oldSelector != null) { 395 ISelector selector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType()); 396 if (selector != null) SelectorParameter.Value = selector; 397 else oldSelector = null; 398 } 399 if (oldSelector == null && defaultSelector != null) 400 SelectorParameter.Value = defaultSelector; 341 401 } 342 402 -
branches/LearningClassifierSystems/HeuristicLab.Algorithms.LearningClassifierSystems/3.3/LearningClassifierSystemMainLoop.cs
r9242 r9467 25 25 using HeuristicLab.Encodings.ConditionActionEncoding; 26 26 using HeuristicLab.Operators; 27 using HeuristicLab.Optimization;28 27 using HeuristicLab.Optimization.Operators; 29 28 using HeuristicLab.Parameters; … … 42 41 43 42 #region Parameter Properties 44 public IConstrainedValueParameter<ISelector> SelectorParameter {45 get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; }43 public ValueLookupParameter<IOperator> SelectorParameter { 44 get { return adaptedGeneticAlgorithmMainLoop.SelectorParameter; } 46 45 } 47 46 public ValueLookupParameter<PercentValue> CrossoverProbabilityParameter { … … 108 107 private void Initialize() { 109 108 #region Create parameters 110 Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.", new ItemSet<ISelector>() { new ProportionalSelector() }, new ProportionalSelector()));111 109 Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization.")); 112 110 XCSAfterCopyingParentOperator afterCopyingParents = new XCSAfterCopyingParentOperator(); … … 273 271 subsumptionSelector.CopySelected = new BoolValue(false); 274 272 275 SelectorParameter.Value.CopySelected = new BoolValue(true);276 SelectorParameter.Value.NumberOfSelectedSubScopesParameter.Value = new IntValue(4);277 278 273 evaluator.Name = "Evaluator"; 279 274 … … 320 315 afterCrossover.ParentAverageActionSetSizeParameter.ActualName = "AverageActionSetSize"; 321 316 322 adaptedGeneticAlgorithmMainLoop.SelectorParameter.ActualName = SelectorParameter.Name;323 317 adaptedGeneticAlgorithmMainLoop.RandomParameter.ActualName = "Random"; 324 318 adaptedGeneticAlgorithmMainLoop.MaximumGenerationsParameter.ActualName = "ZeroIntValue"; … … 428 422 } 429 423 430 private void ParameterizeStochasticOperator(IOperator op) {431 IStochasticOperator stochasticOp = op as IStochasticOperator;432 if (stochasticOp != null) {433 stochasticOp.RandomParameter.ActualName = "Random";434 stochasticOp.RandomParameter.Hidden = true;435 }436 }437 438 424 internal void SetCurrentProblem(IConditionActionProblem problem) { 439 425 initialSolutionsCreator.SolutionCreatorParameter.ActualName = problem.SolutionCreatorParameter.Name; … … 485 471 adaptedGeneticAlgorithmMainLoop.SetChildName(problem.ChildName); 486 472 } 487 //private void ParameterizeSelectors() {488 // foreach (ISelector selector in SelectorParameter.ValidValues) {489 // selector.CopySelected = new BoolValue(true);490 // //set value by parameter!491 // selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(5);492 // selector.NumberOfSelectedSubScopesParameter.Hidden = true;493 // ParameterizeStochasticOperator(selector);494 // }495 // if (Problem != null) {496 // foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {497 // selector.MaximizationParameter.Value = new BoolValue(true);498 // selector.MaximizationParameter.Hidden = true;499 // selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;500 // selector.QualityParameter.Hidden = true;501 // }502 // }503 //}504 473 } 505 474 }
Note: See TracChangeset
for help on using the changeset viewer.