Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/24/09 10:16:58 (15 years ago)
Author:
dtraxing
Message:

Renamed HeuristicLab.SGAHardWired Plugin to HeuristicLab.FixedOperators. (ticket #580)

Location:
trunk/sources/HeuristicLab.FixedOperators
Files:
1 copied
1 moved

Legend:

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

    r1645 r1646  
    3333using System.Diagnostics;
    3434
    35 namespace HeuristicLab.SGA.Hardwired {
    36   class SGAMainWithHWControllStructures : CombinedOperator {
     35namespace HeuristicLab.FixedOperators {
     36  class FixedSGAMain : CombinedOperator {
    3737    public override string Description {
    3838      get { return @"Implements the SGAMain with hardwired control structures. Operators are delegated."; }
     
    4949    DoubleData probability;
    5050
    51     public SGAMainWithHWControllStructures()
     51    long[] timesExecuteCreateChildren;
     52
     53    public FixedSGAMain()
    5254      : base() {
    5355      AddVariableInfo(new VariableInfo("Selector", "Selection strategy for SGA", typeof(OperatorBase), VariableKind.In));
    5456      AddVariableInfo(new VariableInfo("MaximumGenerations", "Maximum number of generations to create", typeof(IntData), VariableKind.In));
    5557      AddVariableInfo(new VariableInfo("Generations", "Number of processed generations", typeof(IntData), VariableKind.In | VariableKind.Out));
    56       Name = "SGAMainWithHWControllStructures";
    57 
     58      Name = "FixedSGAMain";
    5859      //InitCreateChildrenHWCS();
    5960      InitCreateChildrenHW();
     
    9697
    9798    public override IOperation Apply(IScope scope) {
    98 
     99      Stopwatch swApply = new Stopwatch();
     100      swApply.Start();
    99101      //base.Apply(scope); // noch nachfragen ob das auch in ordnung wäre
    100102      for (int i = 0; i < SubOperators.Count; i++) {
     
    134136      IntData evaluatedSolutions = GetVariableValue<IntData>("EvaluatedSolutions", scope, true);
    135137      Stopwatch watch = new Stopwatch();
     138      long[] times = new long[10];
     139      timesExecuteCreateChildren = new long[10];
    136140      for (int i = 0; i < maxGenerations.Data; i++) {
     141          watch.Start();
    137142        selector.Execute(scope);
     143        watch.Stop();
     144        times[0] += watch.ElapsedTicks;
     145        watch.Reset();
     146        watch.Start();
     147        // if uncomment, adapt constructor
    138148        //createChildren.Execute(scope.SubScopes[1]);
    139149        //ExecuteCreateChildrenHWCS(scope.SubScopes[1]);
    140150        ExecuteCreateChildrenHW(scope.SubScopes[1], evaluatedSolutions);
     151        watch.Stop();
     152        times[1] += watch.ElapsedTicks;
     153        watch.Reset();
     154        watch.Start();
    141155        createReplacement.Execute(scope);
     156        watch.Stop();
     157        times[2] += watch.ElapsedTicks;
     158        watch.Reset();
     159        watch.Start();
    142160        ql.Execute(scope);
     161        watch.Stop();
     162        times[3] += watch.ElapsedTicks;
     163        watch.Reset();
     164        watch.Start();
    143165        bawqc.Execute(scope);
     166        watch.Stop();
     167        times[4] += watch.ElapsedTicks;
     168        watch.Reset();
     169        watch.Start();
    144170        dc.Execute(scope);
     171        watch.Stop();
     172        times[5] += watch.ElapsedTicks;
     173        watch.Reset();
     174        watch.Start();
    145175        lci.Execute(scope);
     176        watch.Stop();
     177        times[6] += watch.ElapsedTicks;
     178        watch.Reset();
     179        watch.Start();
    146180        nrOfGenerations.Data++;
    147181      }
    148182
    149      
     183      swApply.Stop();
     184      Console.WriteLine("SGAMain.Apply(): {0}", swApply.Elapsed);
    150185      return null;
    151186    } // Apply
    152187
     188    /// <summary>
     189    /// Initializes some variables needed before the execution of create children
     190    /// </summary>
     191    /// <param name="scope"></param>
    153192    private void InitializeExecuteCreateChildren(IScope scope) {
    154193      crossover = (OperatorBase)GetVariableValue("Crossover", scope, true);
     
    180219
    181220    private void ExecuteCreateChildrenHW(IScope scope, IntData evaluatedSolutions){
     221      //Stopwatch watch = new Stopwatch();
     222      //long[] times = new long[10];
    182223      // ChildrenInitializer
     224      //watch.Start();
    183225      ci.Apply(scope);
     226      //watch.Stop();
     227      //timesExecuteCreateChildren[0] += watch.ElapsedTicks;
     228      //watch.Reset();
    184229      // UniformSequentialSubScopesProcessor
    185230      foreach (IScope s in scope.SubScopes) {
     231        //watch.Start();
    186232        if (crossover.Execute(s) != null)
    187233          throw new InvalidOperationException("ERROR: no support for combined operators!");
     234        //watch.Stop();
     235        //timesExecuteCreateChildren[1] += watch.ElapsedTicks;
     236        //watch.Reset();
     237
    188238
    189239        // Stochastic Branch
    190240        if (random.NextDouble() < probability.Data) {
     241          //watch.Start();
    191242          if (mutator.Execute(s) != null)
    192243            throw new InvalidOperationException("ERROR: no support for combined operators!");
     244          //watch.Stop();
     245          //timesExecuteCreateChildren[2] += watch.ElapsedTicks;
     246          //watch.Reset();
     247
    193248        }
    194249
     250        //watch.Start();
    195251        if (evaluator.Execute(s) != null)
    196252          throw new InvalidOperationException("ERROR: no support for combined operators!");
     253        //watch.Stop();
     254        //timesExecuteCreateChildren[3] += watch.ElapsedTicks;
     255        //watch.Reset();
    197256
    198257        // subscopes remover
     258        //watch.Start();
    199259        while (s.SubScopes.Count > 0)
    200260          s.RemoveSubScope(s.SubScopes[0]);
     261        //watch.Stop();
     262        //timesExecuteCreateChildren[4] += watch.ElapsedTicks;
     263        //watch.Reset();
    201264
    202265        evaluatedSolutions.Data++;
     
    204267
    205268      // sort scopes
    206       //bool descending = GetVariableValue<BoolData>("Maximization", scope, true).Data;
    207       //double[] keys = new double[scope.SubScopes.Count];
    208       //int[] sequence = new int[keys.Length];
    209 
    210       //for (int i = 0; i < keys.Length; i++) {
    211       //  keys[i] = scope.SubScopes[i].GetVariableValue<DoubleData>("Quality", false).Data;
    212       //  sequence[i] = i;
    213       //}
    214 
    215       //Array.Sort<double, int>(keys, sequence);
    216 
    217       //if (descending) {
    218       //  int temp;
    219       //  for (int i = 0; i < sequence.Length / 2; i++) {
    220       //    temp = sequence[i];
    221       //    sequence[i] = sequence[sequence.Length - 1 - i];
    222       //    sequence[sequence.Length - 1 - i] = temp;
    223       //  }
    224       //}
    225       //scope.ReorderSubScopes(sequence);
     269      bool descending = GetVariableValue<BoolData>("Maximization", scope, true).Data;
     270
     271      double[] keys = new double[scope.SubScopes.Count];
     272      int[] sequence = new int[keys.Length];
     273
     274      for (int i = 0; i < keys.Length; i++) {
     275        keys[i] = scope.SubScopes[i].GetVariableValue<DoubleData>("Quality", false).Data;
     276        sequence[i] = i;
     277      }
     278
     279      Array.Sort<double, int>(keys, sequence);
     280
     281      if (descending) {
     282        int temp;
     283        for (int i = 0; i < sequence.Length / 2; i++) {
     284          temp = sequence[i];
     285          sequence[i] = sequence[sequence.Length - 1 - i];
     286          sequence[sequence.Length - 1 - i] = temp;
     287        }
     288      }
     289      scope.ReorderSubScopes(sequence);
     290      //watch.Stop();
     291      //timesExecuteCreateChildren[5] += watch.ElapsedTicks;
     292      //watch.Reset();
    226293
    227294      return;
    228     }
    229 
    230   } // class SGAMainWithHWControllStructures
    231 } // namespace HeuristicLab.SGA.Hardwired
     295    } // ExecuteCreateChildrenHW
     296
     297  } // class FixedSGAMain
     298} // namespace HeuristicLab.FixedOperators
Note: See TracChangeset for help on using the changeset viewer.