Index: /trunk/sources/HeuristicLab.SGA.Hardwired/3.2/SGAMainWithHWControllStructures.cs
===================================================================
--- /trunk/sources/HeuristicLab.SGA.Hardwired/3.2/SGAMainWithHWControllStructures.cs	(revision 1609)
+++ /trunk/sources/HeuristicLab.SGA.Hardwired/3.2/SGAMainWithHWControllStructures.cs	(revision 1610)
@@ -31,4 +31,5 @@
 using HeuristicLab.Routing.TSP;
 using HeuristicLab.Logging;
+using System.Diagnostics;
 
 namespace HeuristicLab.SGA.Hardwired {
@@ -38,10 +39,58 @@
     }
 
+    ChildrenInitializer ci;
+    OperatorBase crossover;
+    OperatorBase mutator;
+    OperatorBase evaluator;
+    SubScopesRemover sr;
+    Counter counter;
+    Sorter sorter;
+    IRandom random;
+    DoubleData probability;
+
     public SGAMainWithHWControllStructures()
       : base() {
       AddVariableInfo(new VariableInfo("Selector", "Selection strategy for SGA", typeof(OperatorBase), VariableKind.In));
       AddVariableInfo(new VariableInfo("MaximumGenerations", "Maximum number of generations to create", typeof(IntData), VariableKind.In));
-
+      AddVariableInfo(new VariableInfo("Generations", "Number of processed generations", typeof(IntData), VariableKind.In | VariableKind.Out));
       Name = "SGAMainWithHWControllStructures";
+
+      //InitCreateChildrenHWCS();
+      InitCreateChildrenHW();
+
+    }
+
+    private void InitCreateChildrenHW() {
+      // variables infos
+      AddVariableInfo(new VariableInfo("Random", "Pseudo random number generator", typeof(IRandom), VariableKind.In));
+      AddVariableInfo(new VariableInfo("MutationRate", "Probability to choose first branch", typeof(DoubleData), VariableKind.In));
+      AddVariableInfo(new VariableInfo("Crossover", "Crossover strategy for SGA", typeof(OperatorBase), VariableKind.In));
+      AddVariableInfo(new VariableInfo("Mutator", "Mutation strategy for SGA", typeof(OperatorBase), VariableKind.In));
+      AddVariableInfo(new VariableInfo("Evaluator", "Evaluation strategy for SGA", typeof(OperatorBase), VariableKind.In));
+      AddVariableInfo(new VariableInfo("EvaluatedSolutions", "Number of evaluated solutions", typeof(IntData), VariableKind.In | VariableKind.Out));
+      AddVariableInfo(new VariableInfo("Maximization", "Sort in descending order", typeof(BoolData), VariableKind.In));
+      AddVariableInfo(new VariableInfo("Quality", "Sorting value", typeof(DoubleData), VariableKind.In));
+    }
+
+    private void InitCreateChildrenHWCS() {
+      // variables for create children
+      ci = new ChildrenInitializer();
+
+      // variables infos
+      AddVariableInfo(new VariableInfo("Random", "Pseudo random number generator", typeof(IRandom), VariableKind.In));
+      AddVariableInfo(new VariableInfo("MutationRate", "Probability to choose first branch", typeof(DoubleData), VariableKind.In));
+      AddVariableInfo(new VariableInfo("Crossover", "Crossover strategy for SGA", typeof(OperatorBase), VariableKind.In));
+      AddVariableInfo(new VariableInfo("Mutator", "Mutation strategy for SGA", typeof(OperatorBase), VariableKind.In));
+      AddVariableInfo(new VariableInfo("Evaluator", "Evaluation strategy for SGA", typeof(OperatorBase), VariableKind.In));
+
+      sr = new SubScopesRemover();
+      sr.GetVariableInfo("SubScopeIndex").Local = true;
+
+      counter = new Counter();
+      counter.GetVariableInfo("Value").ActualName = "EvaluatedSolutions";
+
+      sorter = new Sorter();
+      sorter.GetVariableInfo("Descending").ActualName = "Maximization";
+      sorter.GetVariableInfo("Value").ActualName = "Quality";
     }
 
@@ -80,9 +129,14 @@
 
       IntData maxGenerations = GetVariableValue<IntData>("MaximumGenerations", scope, true);
-      //IntData nrOfGenerations = GetVariableValue<IntData>("Generations", scope, true);
-
+      IntData nrOfGenerations = GetVariableValue<IntData>("Generations", scope, true);
+
+      InitializeExecuteCreateChildren(scope);
+      IntData evaluatedSolutions = GetVariableValue<IntData>("EvaluatedSolutions", scope, true);
+      Stopwatch watch = new Stopwatch();
       for (int i = 0; i < maxGenerations.Data; i++) {
         selector.Execute(scope);
-        createChildren.Execute(scope.SubScopes[1]);
+        //createChildren.Execute(scope.SubScopes[1]);
+        //ExecuteCreateChildrenHWCS(scope.SubScopes[1]);
+        ExecuteCreateChildrenHW(scope.SubScopes[1], evaluatedSolutions);
         createReplacement.Execute(scope);
         ql.Execute(scope);
@@ -90,7 +144,5 @@
         dc.Execute(scope);
         lci.Execute(scope);
-        //c.Execute(scope);
-        //ltc.Execute(scope);
-        //nrOfGenerations.Data = i;
+        nrOfGenerations.Data++;
       }
 
@@ -98,4 +150,82 @@
       return null;
     } // Apply
+
+    private void InitializeExecuteCreateChildren(IScope scope) {
+      crossover = (OperatorBase)GetVariableValue("Crossover", scope, true);
+      mutator = (OperatorBase)GetVariableValue("Mutator", scope, true);
+      evaluator = GetVariableValue<OperatorBase>("Evaluator", scope, true);
+
+      random = GetVariableValue<IRandom>("Random", scope, true);
+      probability = GetVariableValue<DoubleData>("MutationRate", scope, true);
+
+      ci = new ChildrenInitializer();
+    }
+
+    private void ExecuteCreateChildrenHWCS(IScope scope) {
+      // ChildrenInitializer
+      ci.Apply(scope);
+      // UniformSequentialSubScopesProcessor
+      foreach (IScope s in scope.SubScopes) {
+        crossover.Execute(s);
+        // Stochastic Branch
+        if (random.NextDouble() < probability.Data)
+          mutator.Execute(s);
+        evaluator.Execute(s);
+        sr.Execute(s);
+        counter.Execute(s);
+      } // foreach
+
+      sorter.Execute(scope);
+    } // ExecuteCreateChildrenHWCS
+
+    private void ExecuteCreateChildrenHW(IScope scope, IntData evaluatedSolutions){
+      // ChildrenInitializer
+      ci.Apply(scope);
+      // UniformSequentialSubScopesProcessor
+      foreach (IScope s in scope.SubScopes) {
+        if (crossover.Execute(s) != null)
+          throw new InvalidOperationException("ERROR: no support for combined operators!");
+
+        // Stochastic Branch
+        if (random.NextDouble() < probability.Data) {
+          if (mutator.Execute(s) != null)
+            throw new InvalidOperationException("ERROR: no support for combined operators!");
+        }
+
+        if (evaluator.Execute(s) != null)
+          throw new InvalidOperationException("ERROR: no support for combined operators!");
+
+        // subscopes remover
+        while (s.SubScopes.Count > 0)
+          s.RemoveSubScope(s.SubScopes[0]);
+
+        evaluatedSolutions.Data++;
+      } // foreach
+
+      // sort scopes
+      //bool descending = GetVariableValue<BoolData>("Maximization", scope, true).Data;
+      //double[] keys = new double[scope.SubScopes.Count];
+      //int[] sequence = new int[keys.Length];
+
+      //for (int i = 0; i < keys.Length; i++) {
+      //  keys[i] = scope.SubScopes[i].GetVariableValue<DoubleData>("Quality", false).Data;
+      //  sequence[i] = i;
+      //}
+
+      //Array.Sort<double, int>(keys, sequence);
+
+      //if (descending) {
+      //  int temp;
+      //  for (int i = 0; i < sequence.Length / 2; i++) {
+      //    temp = sequence[i];
+      //    sequence[i] = sequence[sequence.Length - 1 - i];
+      //    sequence[sequence.Length - 1 - i] = temp;
+      //  }
+      //}
+      //scope.ReorderSubScopes(sequence);
+
+      return;
+    }
+
   } // class SGAMainWithHWControllStructures
 } // namespace HeuristicLab.SGA.Hardwired
