Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1693


Ignore:
Timestamp:
04/28/09 15:41:11 (15 years ago)
Author:
dtraxing
Message:

Improved algorithm abortion support. Added support for composite operations in FixedSGAMain. (ticket #580)

Location:
trunk/sources/HeuristicLab.FixedOperators/3.2
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.FixedOperators/3.2/FixedSGAMain.cs

    r1661 r1693  
    3535
    3636namespace HeuristicLab.FixedOperators {
    37   class FixedSGAMain : CombinedOperator {
     37  class FixedSGAMain : FixedBase {
    3838    public override string Description {
    3939      get { return @"Implements the functionality of SGAMain with fixed control structures. Operators like selection, crossover, mutation and evaluation are delegated."; }
     
    6161
    6262
    63     long[] timesExecuteCreateChildren;
     63    //long[] timesExecuteCreateChildren;
    6464
    6565    public FixedSGAMain()
     
    6868      AddVariableInfo(new VariableInfo("MaximumGenerations", "Maximum number of generations to create", typeof(IntData), VariableKind.In));
    6969      AddVariableInfo(new VariableInfo("Generations", "Number of processed generations", typeof(IntData), VariableKind.In | VariableKind.Out));
     70      AddVariableInfo(new VariableInfo("ExecutionPointer", "Execution pointer for algorithm abortion", typeof(IntData), VariableKind.New));
     71
    7072      Name = "FixedSGAMain";
    7173
     
    140142      IntData nrOfGenerations = GetVariableValue<IntData>("Generations", scope, true);
    141143
     144
     145      // executionpointer saves the reentry point after engine abort occurs.
     146      IntData executionPointer;
     147      try
     148      {
     149        executionPointer = GetVariableValue<IntData>("ExecutionPointer", scope, true);
     150      }
     151      catch (Exception)
     152      {
     153        scope.AddVariable(new Variable("ExecutionPointer", new IntData(-1)));
     154        executionPointer = GetVariableValue<IntData>("ExecutionPointer", scope, true);
     155      }
     156     
     157      // fetch variables from scope for create children
    142158      InitializeExecuteCreateChildren(scope);
    143       Stopwatch watch = new Stopwatch();
    144       long[] times = new long[10];
    145       timesExecuteCreateChildren = new long[10];
    146159      for (int i = nrOfGenerations.Data; i < maxGenerations.Data && !Canceled; i++) {
    147         watch.Start();
    148         selector.Execute(scope);
    149         watch.Stop();
    150         times[0] += watch.ElapsedTicks;
    151         watch.Reset();
    152         watch.Start();
    153         ExecuteCreateChildrenWithFixedControlStructures(scope.SubScopes[1]);
    154         watch.Stop();
    155         times[1] += watch.ElapsedTicks;
    156         watch.Reset();
    157         watch.Start();
    158         ExecuteCreateReplacementWithFixedConstrolStructures(scope);
    159         watch.Stop();
    160         times[2] += watch.ElapsedTicks;
    161         watch.Reset();
    162         watch.Start();
    163         ql.Execute(scope);
    164         watch.Stop();
    165         times[3] += watch.ElapsedTicks;
    166         watch.Reset();
    167         watch.Start();
    168         bawqc.Execute(scope);
    169         watch.Stop();
    170         times[4] += watch.ElapsedTicks;
    171         watch.Reset();
    172         watch.Start();
    173         dc.Execute(scope);
    174         watch.Stop();
    175         times[5] += watch.ElapsedTicks;
    176         watch.Reset();
    177         watch.Start();
    178         lci.Execute(scope);
    179         watch.Stop();
    180         times[6] += watch.ElapsedTicks;
    181         watch.Reset();
    182         watch.Start();
    183         nrOfGenerations.Data++;
    184       }
     160        if (Canceled) {
     161          executionPointer.Data = -1;
     162          continue;
     163        }
     164        if (executionPointer.Data < 0)
     165          Execute(selector, scope);
     166
     167        if (Canceled) {
     168          executionPointer.Data = 0;
     169          continue;
     170        }
     171        if (executionPointer.Data < 1)
     172          ExecuteCreateChildrenWithFixedControlStructures(scope.SubScopes[1]);
     173
     174        if (Canceled) {
     175          executionPointer.Data = 1;
     176          continue;
     177        }
     178        if (executionPointer.Data < 2)
     179          ExecuteCreateReplacementWithFixedConstrolStructures(scope);
     180
     181        if (Canceled) {
     182          executionPointer.Data = 2;
     183          continue;
     184        }
     185        if (executionPointer.Data < 3) {
     186          ql.Execute(scope);
     187          bawqc.Execute(scope);
     188          dc.Execute(scope);
     189          lci.Execute(scope);
     190          nrOfGenerations.Data++;
     191        }
     192        executionPointer.Data = -1;
     193      } // for i
     194
     195      //Stopwatch watch = new Stopwatch();
     196      //long[] times = new long[10];
     197      //timesExecuteCreateChildren = new long[10];
     198      //for (int i = nrOfGenerations.Data; i < maxGenerations.Data && !Canceled; i++) {
     199      //  watch.Start();
     200      //  selector.Execute(scope);
     201      //  watch.Stop();
     202      //  times[0] += watch.ElapsedTicks;
     203      //  watch.Reset();
     204      //  watch.Start();
     205      //  ExecuteCreateChildrenWithFixedControlStructures(scope.SubScopes[1]);
     206      //  watch.Stop();
     207      //  times[1] += watch.ElapsedTicks;
     208      //  watch.Reset();
     209      //  watch.Start();
     210      //  ExecuteCreateReplacementWithFixedConstrolStructures(scope);
     211      //  watch.Stop();
     212      //  times[2] += watch.ElapsedTicks;
     213      //  watch.Reset();
     214      //  watch.Start();
     215      //  ql.Execute(scope);
     216      //  watch.Stop();
     217      //  times[3] += watch.ElapsedTicks;
     218      //  watch.Reset();
     219      //  watch.Start();
     220      //  bawqc.Execute(scope);
     221      //  watch.Stop();
     222      //  times[4] += watch.ElapsedTicks;
     223      //  watch.Reset();
     224      //  watch.Start();
     225      //  dc.Execute(scope);
     226      //  watch.Stop();
     227      //  times[5] += watch.ElapsedTicks;
     228      //  watch.Reset();
     229      //  watch.Start();
     230      //  lci.Execute(scope);
     231      //  watch.Stop();
     232      //  times[6] += watch.ElapsedTicks;
     233      //  watch.Reset();
     234      //  watch.Start();
     235      //  nrOfGenerations.Data++;
     236      //}
    185237
    186238      swApply.Stop();
     
    215267      // UniformSequentialSubScopesProcessor
    216268      foreach (IScope s in scope.SubScopes) {
    217         crossover.Execute(s);
     269        Execute(crossover, s);
    218270        // Stochastic Branch
    219271        if (random.NextDouble() < probability.Data)
    220           mutator.Execute(s);
    221         evaluator.Execute(s);
     272          Execute(mutator, s);
     273        Execute(evaluator, s);
    222274        sr.Execute(s);
    223275        counter.Execute(s);
  • trunk/sources/HeuristicLab.FixedOperators/3.2/HeuristicLab.FixedOperators-3.2.csproj

    r1661 r1693  
    7171    <Compile Include="CreateReplacement.cs" />
    7272    <Compile Include="CreateChildrenHardWired.cs" />
     73    <Compile Include="FixedBase.cs" />
    7374    <Compile Include="FixedSGAMain.cs" />
    7475    <Compile Include="HeuristicLabFixedOperatorsPlugin.cs" />
Note: See TracChangeset for help on using the changeset viewer.