[2150] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Operators.Programmable;
|
---|
| 6 | using HeuristicLab.Operators;
|
---|
| 7 | using HeuristicLab.Core;
|
---|
| 8 | using HeuristicLab.Data;
|
---|
| 9 | using HeuristicLab.Permutation;
|
---|
| 10 | using HeuristicLab.Evolutionary;
|
---|
| 11 | using HeuristicLab.Routing.TSP;
|
---|
| 12 | using HeuristicLab.Logging;
|
---|
| 13 | using System.Diagnostics;
|
---|
| 14 | using HeuristicLab.Selection;
|
---|
| 15 | using System.Threading;
|
---|
| 16 | using System.IO;
|
---|
| 17 | using HeuristicLab.Random;
|
---|
| 18 |
|
---|
| 19 |
|
---|
| 20 | namespace 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
|
---|