Changeset 9204 for branches/LearningClassifierSystems/HeuristicLab.Algorithms.LearningClassifierSystems
- Timestamp:
- 02/04/13 16:16:38 (12 years ago)
- Location:
- branches/LearningClassifierSystems/HeuristicLab.Algorithms.LearningClassifierSystems/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LearningClassifierSystems/HeuristicLab.Algorithms.LearningClassifierSystems/3.3/LearningClassifierSystem.cs
r9175 r9204 118 118 get { return (ValueParameter<IntValue>)Parameters["MaxIterations"]; } 119 119 } 120 public IConstrainedValueParameter<ICrossover> CrossoverParameter { 121 get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; } 122 } 123 public IConstrainedValueParameter<IManipulator> MutatorParameter { 124 get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; } 125 } 120 126 #endregion 121 127 … … 204 210 get { return FinalAnalyzerParameter.Value; } 205 211 set { FinalAnalyzerParameter.Value = value; } 212 } 213 public ICrossover Crossover { 214 get { return CrossoverParameter.Value; } 215 set { CrossoverParameter.Value = value; } 216 } 217 public IManipulator Mutator { 218 get { return MutatorParameter.Value; } 219 set { MutatorParameter.Value = value; } 206 220 } 207 221 private RandomCreator RandomCreator { … … 237 251 Parameters.Add(new ValueParameter<MultiAnalyzer>("FinalAnalyzer", "The operator used to analyze the last generation.", new MultiAnalyzer())); 238 252 Parameters.Add(new ValueParameter<IntValue>("MaxIterations", "The maximum number of iterations.", new IntValue(1000))); 253 Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.")); 254 Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.")); 239 255 #endregion 240 256 … … 256 272 mainLoop.FinalAnalyzerParameter.ActualName = FinalAnalyzerParameter.Name; 257 273 mainLoop.MaxIterationsParameter.ActualName = MaxIterationsParameter.Name; 274 mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name; 275 mainLoop.MutatorParameter.ActualName = MutatorParameter.Name; 276 mainLoop.CrossoverProbabilityParameter.ActualName = CrossoverProbabilityParameter.Name; 258 277 #endregion 259 278 … … 279 298 ParameterizeEvaluator(Problem.Evaluator); 280 299 MainLoop.SetCurrentProblem(Problem); 300 UpdateCrossovers(); 301 UpdateMutators(); 281 302 UpdateAnalyzers(); 303 ParameterizeManipulator(); 282 304 } 283 305 base.OnProblemChanged(); 306 } 307 308 private void ParameterizeManipulator() { 309 foreach (var op in Problem.Operators.OfType<IProbabilityMutatorOperator>()) { 310 op.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name; 311 } 284 312 } 285 313 protected override void Problem_EvaluatorChanged(object sender, EventArgs e) { … … 293 321 } 294 322 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { 323 UpdateCrossovers(); 324 UpdateMutators(); 295 325 UpdateAnalyzers(); 326 ParameterizeManipulator(); 296 327 base.Problem_OperatorsChanged(sender, e); 297 328 } … … 305 336 } 306 337 338 private void UpdateCrossovers() { 339 ICrossover oldCrossover = CrossoverParameter.Value; 340 CrossoverParameter.ValidValues.Clear(); 341 ICrossover defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault(); 342 343 foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name)) 344 CrossoverParameter.ValidValues.Add(crossover); 345 346 if (oldCrossover != null) { 347 ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType()); 348 if (crossover != null) CrossoverParameter.Value = crossover; 349 else oldCrossover = null; 350 } 351 if (oldCrossover == null && defaultCrossover != null) 352 CrossoverParameter.Value = defaultCrossover; 353 } 354 private void UpdateMutators() { 355 IManipulator oldMutator = MutatorParameter.Value; 356 MutatorParameter.ValidValues.Clear(); 357 IManipulator defaultMutator = Problem.Operators.OfType<IManipulator>().FirstOrDefault(); 358 359 foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name)) 360 MutatorParameter.ValidValues.Add(mutator); 361 if (oldMutator != null) { 362 IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType()); 363 if (mutator != null) MutatorParameter.Value = mutator; 364 else oldMutator = null; 365 } 366 if (oldMutator == null && defaultMutator != null) 367 MutatorParameter.Value = defaultMutator; 368 } 307 369 private void UpdateAnalyzers() { 308 370 Analyzer.Operators.Clear(); -
branches/LearningClassifierSystems/HeuristicLab.Algorithms.LearningClassifierSystems/3.3/LearningClassifierSystemMainLoop.cs
r9194 r9204 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Data; 25 using HeuristicLab.Encodings.CombinedIntegerVectorEncoding;26 25 using HeuristicLab.Encodings.ConditionActionEncoding; 27 26 using HeuristicLab.Operators; … … 46 45 get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; } 47 46 } 48 public IConstrainedValueParameter<ICrossover> CrossoverParameter { 49 get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; } 50 } 51 public IConstrainedValueParameter<IManipulator> MutatorParameter { 52 get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; } 47 public ValueLookupParameter<PercentValue> CrossoverProbabilityParameter { 48 get { return adaptedGeneticAlgorithmMainLoop.CrossoverProbabilityParameter; } 49 } 50 public ValueLookupParameter<IOperator> CrossoverParameter { 51 get { return adaptedGeneticAlgorithmMainLoop.CrossoverParameter; } 52 } 53 public ValueLookupParameter<IOperator> MutatorParameter { 54 get { return adaptedGeneticAlgorithmMainLoop.MutatorParameter; } 53 55 } 54 56 public IConstrainedValueParameter<IOperator> AfterCopyingParentsParameter { … … 78 80 private CountNumberOfUniqueActions countNumberOfUniqueActions; 79 81 80 private UniformSomePositionManipulator test;82 private LCSAdaptedGeneticAlgorithm adaptedGeneticAlgorithmMainLoop; 81 83 82 84 private Placeholder evaluator; … … 102 104 #region Create parameters 103 105 Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.", new ItemSet<ISelector>() { new ProportionalSelector() }, new ProportionalSelector())); 104 Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.", new ItemSet<ICrossover>() { new HeuristicLab.Encodings.CombinedIntegerVectorEncoding.SinglePointCrossover() }, new HeuristicLab.Encodings.CombinedIntegerVectorEncoding.SinglePointCrossover()));105 106 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.")); 106 test = new UniformSomePositionManipulator();107 test.ProbabilityParameter.ActualName = "MutationProbability";108 test.ChildParameter.ActualName = "CombinedIntegerVector";109 Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.", new ItemSet<IManipulator>() { new UniformSomePositionManipulator() }, test));110 107 XCSAfterCopyingParentOperator afterCopyingParents = new XCSAfterCopyingParentOperator(); 111 108 Parameters.Add(new ConstrainedValueParameter<IOperator>("AfterCopyingParents", "", new ItemSet<IOperator>() { new XCSAfterCopyingParentOperator() }, afterCopyingParents)); … … 162 159 UniformSubScopesProcessor timestampAssignerSubscopeProcessor = new UniformSubScopesProcessor(); 163 160 Assigner timestampAssigner = new Assigner(); 164 LCSAdaptedGeneticAlgorithmadaptedGeneticAlgorithmMainLoop = new LCSAdaptedGeneticAlgorithm();161 adaptedGeneticAlgorithmMainLoop = new LCSAdaptedGeneticAlgorithm(); 165 162 IntCounter currentPopulationSizeCounter = new IntCounter(); 166 163 CalculateNumberOfDeletionsOperator calculateNumberOfDeletions = new CalculateNumberOfDeletionsOperator(); … … 313 310 314 311 adaptedGeneticAlgorithmMainLoop.SelectorParameter.ActualName = SelectorParameter.Name; 315 adaptedGeneticAlgorithmMainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;316 adaptedGeneticAlgorithmMainLoop.MutatorParameter.ActualName = MutatorParameter.Name;317 312 adaptedGeneticAlgorithmMainLoop.RandomParameter.ActualName = "Random"; 318 313 adaptedGeneticAlgorithmMainLoop.MaximumGenerationsParameter.ActualName = "ZeroIntValue"; … … 440 435 classifierFetcher.OperatorParameter.ActualName = problem.ClassifierFetcherParameter.Name; 441 436 442 test.FetchedConditionParameter.ActualName = problem.ClassifierFetcher.CurrentInputToMatchParameter.ActualName;443 test.PossibleActionsParameter.ActualName = problem.PossibleActionsConcreteClassParameter.Name;444 445 437 actionExecuter.OperatorParameter.ActualName = problem.ActionExecuterParameter.Name; 446 438
Note: See TracChangeset
for help on using the changeset viewer.