[2120] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | #region Using directives
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Evolutionary;
|
---|
| 26 | using HeuristicLab.Logging;
|
---|
| 27 | using HeuristicLab.Operators;
|
---|
| 28 | using HeuristicLab.Selection;
|
---|
| 29 | using System;
|
---|
| 30 | using System.Collections.Generic;
|
---|
| 31 | using System.Linq;
|
---|
| 32 | using System.Text;
|
---|
| 33 | using HeuristicLab.Selection.OffspringSelection;
|
---|
| 34 | #endregion
|
---|
| 35 |
|
---|
| 36 | namespace HeuristicLab.FixedOperators {
|
---|
| 37 | class FixedOSGAMain : FixedGAMainBase {
|
---|
| 38 | WeightedOffspringFitnessComparer wofc;
|
---|
[2150] | 39 | protected IOperator os;
|
---|
[2120] | 40 |
|
---|
| 41 | public FixedOSGAMain()
|
---|
| 42 | : base() {
|
---|
[2150] | 43 | Name = "FixedOSGAMain";
|
---|
[2120] | 44 | wofc = new WeightedOffspringFitnessComparer();
|
---|
| 45 | os = new OffspringSelector();
|
---|
| 46 | os.AddSubOperator(new EmptyOperator());
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | /// <summary>
|
---|
| 50 | /// Apply
|
---|
| 51 | /// </summary>
|
---|
| 52 | public override IOperation Apply(IScope scope) {
|
---|
| 53 | base.Apply(scope);
|
---|
| 54 |
|
---|
| 55 | #region Initialization
|
---|
| 56 | DataCollector selectionPressureDC = new DataCollector();
|
---|
| 57 | selectionPressureDC.GetVariableInfo("Values").ActualName = "SelPressValues";
|
---|
| 58 | ItemList<StringData> names = selectionPressureDC.GetVariable("VariableNames").GetValue<ItemList<StringData>>();
|
---|
| 59 | names.Add(new StringData("SelectionPressure"));
|
---|
| 60 |
|
---|
| 61 | LinechartInjector selectionPressureLCI = new LinechartInjector();
|
---|
| 62 | selectionPressureLCI.GetVariableInfo("Linechart").ActualName = "SelectionPressureLinechart";
|
---|
| 63 | selectionPressureLCI.GetVariable("NumberOfLines").GetValue<IntData>().Data = 1;
|
---|
| 64 | selectionPressureLCI.GetVariableInfo("Values").ActualName = "SelPressValues";
|
---|
| 65 |
|
---|
| 66 | IScope s;
|
---|
| 67 | IScope s2;
|
---|
[2129] | 68 | bool loopSkipped = true;
|
---|
| 69 | bool running = false;
|
---|
[2120] | 70 |
|
---|
| 71 | DoubleData selectionPressure = null;
|
---|
| 72 | DoubleData selectionPressureLimit = new DoubleData();
|
---|
| 73 | try {
|
---|
| 74 | selectionPressureLimit = scope.GetVariableValue<DoubleData>("SelectionPressureLimit", false);
|
---|
| 75 | }
|
---|
| 76 | catch (Exception) {
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | #endregion
|
---|
| 80 |
|
---|
| 81 | tempExePointer = new int[10];
|
---|
| 82 | tempPersExePointer = new int[10];
|
---|
| 83 | try {
|
---|
| 84 | for (; nrOfGenerations.Data < maxGenerations.Data; nrOfGenerations.Data++) {
|
---|
| 85 | SaveExecutionPointer(0);
|
---|
| 86 | do {
|
---|
| 87 | SetExecutionPointerToLastSaved(0);
|
---|
| 88 | Execute(selector, scope);
|
---|
| 89 |
|
---|
| 90 | ////// Create Children //////
|
---|
| 91 | // ChildrenInitializer
|
---|
| 92 | s = scope.SubScopes[1];
|
---|
| 93 |
|
---|
| 94 | Execute(ci, s);
|
---|
| 95 |
|
---|
| 96 | SaveExecutionPointer(1);
|
---|
| 97 | // UniformSequentialSubScopesProcessor
|
---|
| 98 | for (; subscopeNr.Data < s.SubScopes.Count; subscopeNr.Data++) {
|
---|
| 99 | SetExecutionPointerToLastSaved(1);
|
---|
| 100 |
|
---|
| 101 | s2 = s.SubScopes[subscopeNr.Data];
|
---|
| 102 | Execute(crossover, s2);
|
---|
| 103 | // Stochastic Branch
|
---|
| 104 | Execute(sb, s2);
|
---|
| 105 | Execute(evaluator, s2);
|
---|
| 106 | Execute(counter, s2);
|
---|
| 107 | Execute(wofc, s2);
|
---|
| 108 | Execute(sr, s2);
|
---|
[2129] | 109 | loopSkipped = false;
|
---|
[2120] | 110 | } // foreach
|
---|
| 111 |
|
---|
[2129] | 112 | // if for loop skipped, we had to add skiped operations
|
---|
| 113 | // to execution pointer.
|
---|
| 114 | if (loopSkipped)
|
---|
| 115 | executionPointer += 5;
|
---|
| 116 |
|
---|
[2120] | 117 | Execute(sorter, s);
|
---|
| 118 | ////// END Create Children //////
|
---|
[2129] | 119 |
|
---|
| 120 | running = ExecuteFirstOperator(os, scope);
|
---|
| 121 | if (running) subscopeNr.Data = 0;
|
---|
| 122 | } while (running);
|
---|
[2120] | 123 |
|
---|
| 124 | DoReplacement(scope);
|
---|
| 125 | Execute(ql, scope);
|
---|
| 126 | Execute(bawqc, scope);
|
---|
| 127 | Execute(dc, scope);
|
---|
| 128 | Execute(lci, scope);
|
---|
| 129 | Execute(selectionPressureDC, scope);
|
---|
| 130 | Execute(selectionPressureLCI, scope);
|
---|
| 131 | Console.WriteLine(nrOfGenerations);
|
---|
| 132 |
|
---|
| 133 | if (selectionPressure == null)
|
---|
| 134 | selectionPressure = scope.GetVariableValue<DoubleData>("SelectionPressure", false);
|
---|
| 135 | if (selectionPressure.Data > selectionPressureLimit.Data)
|
---|
| 136 | break;
|
---|
| 137 |
|
---|
[2129] | 138 | subscopeNr.Data = 0;
|
---|
[2120] | 139 | ResetExecutionPointer();
|
---|
| 140 | } // for i generations
|
---|
| 141 | } // try
|
---|
| 142 | catch (CancelException) {
|
---|
| 143 | //Console.WriteLine("Micro engine aborted by cancel flag.");
|
---|
| 144 | return new AtomicOperation(this, scope);
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | return null;
|
---|
| 148 | } // Apply
|
---|
| 149 | } // FixedOSGAMain
|
---|
| 150 | } // namespace HeuristicLab.FixedOperators
|
---|