- Timestamp:
- 07/27/12 16:17:01 (12 years ago)
- Location:
- branches/RAPGA/HeuristicLab.Algorithms.RAPGA/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RAPGA/HeuristicLab.Algorithms.RAPGA/3.3/HeuristicLab.Algorithms.RAPGA-3.3.csproj
r8313 r8349 97 97 </ItemGroup> 98 98 <ItemGroup> 99 <Compile Include="DuplicateSelector.cs" /> 99 100 <Compile Include="RAPGA.cs" /> 100 101 <Compile Include="RAPGAMainLoop.cs" /> -
branches/RAPGA/HeuristicLab.Algorithms.RAPGA/3.3/RAPGA.cs
r8330 r8349 66 66 private IValueParameter<IntValue> MinimumPopulationSizeParameter { 67 67 get { return (IValueParameter<IntValue>)Parameters["MinimumPopulationSize"]; } 68 } 68 } 69 69 private IValueParameter<IntValue> MaximumPopulationSizeParameter { 70 get { return (IValueParameter<IntValue>) 70 get { return (IValueParameter<IntValue>)Parameters["MaximumPopulationSize"]; } 71 71 } 72 72 private IValueParameter<DoubleValue> ComparisonFactorParameter { … … 96 96 private ValueParameter<IntValue> MaximumGenerationsParameter { 97 97 get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; } 98 } 99 public IConstrainedValueParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter { 100 get { return (IConstrainedValueParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; } 98 101 } 99 102 #endregion … … 155 158 get { return MaximumGenerationsParameter.Value; } 156 159 set { MaximumGenerationsParameter.Value = value; } 160 } 161 public ISolutionSimilarityCalculator SimilarityCalculator { 162 get { return SimilarityCalculatorParameter.Value; } 163 set { SimilarityCalculatorParameter.Value = value; } 157 164 } 158 165 private RandomCreator RandomCreator { … … 194 201 Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer())); 195 202 Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000))); 203 Parameters.Add(new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions.")); 196 204 197 205 RandomCreator randomCreator = new RandomCreator(); … … 249 257 250 258 public override void Prepare() { 251 if (Problem != null ) base.Prepare();259 if (Problem != null && SimilarityCalculator != null) base.Prepare(); 252 260 } 253 261 … … 258 266 foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op); 259 267 ParameterizeSolutionsCreator(); 260 ParameterizeGeneticAlgorithmMainLoop();261 268 ParameterizeSelectors(); 262 269 ParameterizeAnalyzers(); … … 265 272 UpdateMutators(); 266 273 UpdateAnalyzers(); 274 UpdateSimilarityCalculators(); 275 ParameterizeRAPGAMainLoop(); 267 276 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 268 277 base.OnProblemChanged(); … … 277 286 ParameterizeStochasticOperator(Problem.Evaluator); 278 287 ParameterizeSolutionsCreator(); 279 Parameterize GeneticAlgorithmMainLoop();288 ParameterizeRAPGAMainLoop(); 280 289 ParameterizeSelectors(); 281 290 ParameterizeAnalyzers(); … … 284 293 } 285 294 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { 286 foreach (IOperator op in Problem.Operators ) ParameterizeStochasticOperator(op);295 foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op); 287 296 ParameterizeIterationBasedOperators(); 288 297 UpdateCrossovers(); 289 298 UpdateMutators(); 290 299 UpdateAnalyzers(); 300 UpdateSimilarityCalculators(); 301 ParameterizeRAPGAMainLoop(); 291 302 base.Problem_OperatorsChanged(sender, e); 292 303 } … … 307 318 } 308 319 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { 309 Parameterize GeneticAlgorithmMainLoop();320 ParameterizeRAPGAMainLoop(); 310 321 ParameterizeSelectors(); 311 322 ParameterizeAnalyzers(); … … 328 339 SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name; 329 340 } 330 private void Parameterize GeneticAlgorithmMainLoop() {341 private void ParameterizeRAPGAMainLoop() { 331 342 RAPGAMainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 332 343 RAPGAMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 333 344 RAPGAMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 345 foreach (ISimilarityBasedOperator op in RAPGAMainLoop.OperatorGraph.Operators.OfType<ISimilarityBasedOperator>()) 346 op.SimilarityCalculator = SimilarityCalculator; 334 347 } 335 348 private void ParameterizeStochasticOperator(IOperator op) { … … 416 429 Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault); 417 430 } 431 private void UpdateSimilarityCalculators() { 432 ISolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value; 433 SimilarityCalculatorParameter.ValidValues.Clear(); 434 ISolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISolutionSimilarityCalculator>().FirstOrDefault(); 435 436 foreach (ISolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISolutionSimilarityCalculator>()) 437 SimilarityCalculatorParameter.ValidValues.Add(similarityCalculator); 438 439 if (oldSimilarityCalculator != null) { 440 ISolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType()); 441 if (similarityCalculator != null) SimilarityCalculatorParameter.Value = similarityCalculator; 442 else oldSimilarityCalculator = null; 443 } 444 if (oldSimilarityCalculator == null && defaultSimilarityCalculator != null) 445 SimilarityCalculatorParameter.Value = defaultSimilarityCalculator; 446 } 418 447 private RAPGAMainLoop FindMainLoop(IOperator start) { 419 448 IOperator mainLoop = start; -
branches/RAPGA/HeuristicLab.Algorithms.RAPGA/3.3/RAPGAMainLoop.cs
r8330 r8349 151 151 ConditionalSelector conditionalSelector = new ConditionalSelector(); 152 152 RightReducer rightReducer1 = new RightReducer(); 153 UniformSubScopesProcessor uniformSubScopesProcessor3 = new UniformSubScopesProcessor(); 154 SubScopesRemover subScopesRemover = new SubScopesRemover(); 155 DuplicateSelector duplicateSelector = new DuplicateSelector(); 156 LeftReducer leftReducer = new LeftReducer(); 153 157 SubScopesCounter subScopesCounter1 = new SubScopesCounter(); 154 158 IntCounter intCounter1 = new IntCounter(); 155 UniformSubScopesProcessor uniformSubScopesProcessor3 = new UniformSubScopesProcessor();156 SubScopesRemover subScopesRemover = new SubScopesRemover();157 159 Comparator comparator2 = new Comparator(); 158 160 ConditionalBranch conditionalBranch1 = new ConditionalBranch(); … … 217 219 conditionalSelector.CopySelected.Value = false; 218 220 221 duplicateSelector.CopySelected.Value = false; 222 223 uniformSubScopesProcessor3.Parallel.Value = true; 224 225 subScopesRemover.RemoveAllSubScopes = true; 226 219 227 subScopesCounter1.Name = "Count Successful Offspring"; 220 228 subScopesCounter1.ValueParameter.ActualName = "NumberOfSuccessfulOffspring"; … … 223 231 intCounter1.IncrementParameter.Value = null; 224 232 intCounter1.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; 225 226 uniformSubScopesProcessor3.Parallel.Value = true;227 228 subScopesRemover.RemoveAllSubScopes = true;229 233 230 234 comparator2.Comparison = new Comparison(ComparisonType.GreaterOrEqual); … … 267 271 assigner2.RightSideParameter.Value = new IntValue(0); 268 272 269 subScopesCounter2.Name = " Increment EvaluatedSolutions";273 subScopesCounter2.Name = "Set CurrentPopulationSize"; 270 274 subScopesCounter2.ValueParameter.ActualName = "CurrentPopulationSize"; 271 275 … … 304 308 evaluator.Successor = comparator1; 305 309 conditionalSelector.Successor = rightReducer1; 306 rightReducer1.Successor = subScopesCounter1; 310 rightReducer1.Successor = uniformSubScopesProcessor3; 311 uniformSubScopesProcessor3.Operator = subScopesRemover; 312 uniformSubScopesProcessor3.Successor = duplicateSelector; 313 duplicateSelector.Successor = leftReducer; 314 leftReducer.Successor = subScopesCounter1; 307 315 subScopesCounter1.Successor = intCounter1; 308 intCounter1.Successor = uniformSubScopesProcessor3; 309 uniformSubScopesProcessor3.Operator = subScopesRemover; 310 uniformSubScopesProcessor3.Successor = comparator2; 316 intCounter1.Successor = comparator2; 311 317 comparator2.Successor = conditionalBranch1; 312 318 conditionalBranch1.TrueBranch = bestSelector1;
Note: See TracChangeset
for help on using the changeset viewer.