Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.FixedOperators/3.2/FixedSteadyStateOSGAMain.cs @ 2150

Last change on this file since 2150 was 2150, checked in by dtraxing, 15 years ago

added fixed operator for SteadyStateOSGA
FixedOSGAMain: fixed a type in the name; removed catch block to in Apply method
FixedGAMainBase: add virtual and protected modifier to InitReplacement and DoReplacement
(ticket #580)

File size: 3.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Operators.Programmable;
6using HeuristicLab.Operators;
7using HeuristicLab.Core;
8using HeuristicLab.Data;
9using HeuristicLab.Permutation;
10using HeuristicLab.Evolutionary;
11using HeuristicLab.Routing.TSP;
12using HeuristicLab.Logging;
13using System.Diagnostics;
14using HeuristicLab.Selection;
15using System.Threading;
16using System.IO;
17using HeuristicLab.Random;
18
19
20namespace HeuristicLab.FixedOperators {
21  class FixedSteadyStateOSGAMain : FixedOSGAMain {
22
23    public FixedSteadyStateOSGAMain() {
24      Name = "FixedSteadyStateOSGAMain";
25      os = new ProgrammableOperator();
26      os.AddSubOperator(new EmptyOperator());
27      ((ProgrammableOperator)os).Code = @"IScope parents = scope.SubScopes[0], children = scope.SubScopes[1];
28                                          HeuristicLab.Data.DoubleData selectionPressure = scope.GetVariableValue<HeuristicLab.Data.DoubleData>(""SelectionPressure"", true);
29                                          int badCount = 0;
30                                          for (int i = 0 ; i < children.SubScopes.Count ; i++) {
31                                            IScope child = children.SubScopes[i];
32                                            bool successful = child.GetVariableValue<HeuristicLab.Data.BoolData>(""SuccessfulChild"", false).Data;
33                                            if (!successful) {
34                                              badCount++;
35                                              children.RemoveSubScope(child);
36                                              i--;
37                                            }
38                                          }
39                                          selectionPressure.Data += badCount / ((double)parents.SubScopes.Count);
40                                          if (children.SubScopes.Count == 0) {
41                                            scope.RemoveSubScope(children);
42                                            scope.RemoveSubScope(parents);
43                                            for (int i = 0; i < parents.SubScopes.Count; i++)
44                                              scope.AddSubScope(parents.SubScopes[i]);
45                                            return new AtomicOperation(op.SubOperators[0], scope);
46                                          }
47                                          return null;";
48
49
50
51    } // FixedSteadyStateOSGAMain
52
53    protected override void InitReplacement() {
54      base.InitReplacement();
55      ls.GetVariableInfo("Selected").ActualName = "PopulationSize";
56    }
57
58    protected override void DoReplacement(IScope scope) {
59      //// SequentialSubScopesProcessor
60      Execute(mr, scope);
61      Execute(sorter, scope);
62      Execute(ls, scope);
63      Execute(rr, scope);
64    } // DoReplacement
65  } // class FixedSteadyStateOSGAMain
66} // namespace HeuristicLab.FixedOperators
Note: See TracBrowser for help on using the repository browser.