Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.FixedOperators/3.2/FixedESMain.cs @ 3580

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

FixedGAMainBase: fixed type in operator name; added virtual modifier to GetOperatorsFromScope Method
FixedOperatorBase: removed general exception catching
added fixed operator for evolution strategies
(ticket #580)

File size: 4.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.ES;
7using HeuristicLab.Operators;
8using HeuristicLab.Data;
9
10
11namespace HeuristicLab.FixedOperators {
12  class FixedESMain : FixedGAMainBase {
13    protected ESRandomSelector childSelector;
14    protected OperatorBase recombinator;
15
16    public FixedESMain() {
17      Name = this.GetType().Name;
18      Init();
19     
20    } // FixedESMain
21
22    private void Init() {
23      childSelector = new ESRandomSelector();
24      childSelector.GetVariableInfo("Lambda").ActualName = "ESlambda";
25      childSelector.GetVariableInfo("Rho").ActualName = "ESrho";
26
27      ls.GetVariableInfo("Selected").ActualName = "ESmu";
28      //ci.GetVariableInfo("ParentsPerChild").ActualName = "ESrho";
29     
30   
31    } // Init
32
33    protected override void GetOperatorsFromScope(IScope scope) {
34      mutator = new OperatorExtractor();
35      mutator.GetVariableInfo("Operator").ActualName = "Mutator";
36
37      evaluator = new OperatorExtractor();
38      evaluator.GetVariableInfo("Operator").ActualName = "Evaluation (Rosenbrock)";
39
40      recombinator = new OperatorExtractor();
41      recombinator.GetVariableInfo("Operator").ActualName = "Recombinator";
42     
43      //mutator = (OperatorBase)GetVariableValue("Mutator", scope, true);
44      //evaluator = GetVariableValue<OperatorBase>("Evaluator", scope, true);
45      //recombinator = GetVariableValue<OperatorBase>("Recombinator", scope, true);
46    }
47
48    public override IOperation Apply(IScope scope) {
49      base.Apply(scope);
50      IScope s;
51      IScope s2;
52      bool loopSkipped = true;
53
54      tempExePointer = new int[10];
55      tempPersExePointer = new int[10];
56      IntData esRho; 
57
58      try {
59        for (; nrOfGenerations.Data < maxGenerations.Data; nrOfGenerations.Data++) {
60
61          Execute(childSelector, scope);
62          ////// Create Children //////
63          s = scope.SubScopes[1];
64          esRho = s.GetVariableValue<IntData>("ESrho", true);
65
66          if (esRho.Data > 1) { // Use recombination?
67            Execute(ci, s);
68            SaveExecutionPointer(0);
69            for (; subscopeNr.Data < s.SubScopes.Count; subscopeNr.Data++) {
70              SetExecutionPointerToLastSaved(0);
71              s2 = s.SubScopes[subscopeNr.Data];
72              Execute(recombinator, s2);
73              Execute(mutator, s2);
74              Execute(evaluator, s2);
75              Execute(counter, s2);
76              Execute(sr, s2);
77              loopSkipped = false;
78            } // foreach
79
80            if (loopSkipped)
81              executionPointer += 5;
82          } // if (esRho.Data > 1)
83          else {
84            SaveExecutionPointer(0);
85            for (; subscopeNr.Data < s.SubScopes.Count; subscopeNr.Data++) {
86              SetExecutionPointerToLastSaved(0);
87              s2 = s.SubScopes[subscopeNr.Data];
88              Execute(mutator, s2);
89              Execute(evaluator, s2);
90              Execute(counter, s2);
91              loopSkipped = false;
92            } // foreach
93
94            if (loopSkipped)
95              executionPointer += 3;
96          } // else
97
98          Execute(sorter, s);
99
100
101          // if for loop skipped, we had to add skiped operations
102          // to execution pointer.
103          if (loopSkipped)
104            executionPointer += 5;
105
106          ////// END Create Children //////
107
108
109          // Plus or Comma Replacement
110          BoolData plusNotation = scope.GetVariableValue<BoolData>("PlusNotation", true);
111          if (plusNotation.Data)
112            Execute(mr, scope);
113          else
114            Execute(rr, scope);
115
116          // TODO: Parents Selection
117          Execute(sorter, scope);
118          Execute(ls, scope);
119          Execute(rr, scope);
120
121          Execute(ql, scope);
122          Execute(bawqc, scope);
123          Execute(dc, scope);
124          Execute(lci, scope);
125          subscopeNr.Data = 0;
126          ResetExecutionPointer();
127        } // for Generations
128      } // try
129      catch (CancelException) {
130        return new AtomicOperation(this, scope);
131      }
132
133      return null;
134    } // Apply
135  } // class FixedESMain
136} // namespace HeuristicLab.FixedOperators
Note: See TracBrowser for help on using the repository browser.