Index: trunk/sources/HeuristicLab.Selection/3.3/HeuristicLab.Selection-3.2.csproj
===================================================================
--- trunk/sources/HeuristicLab.Selection/3.3/HeuristicLab.Selection-3.2.csproj	(revision 1692)
+++ trunk/sources/HeuristicLab.Selection/3.3/HeuristicLab.Selection-3.2.csproj	(revision 1692)
@@ -0,0 +1,133 @@
+﻿<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>9.0.30729</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{F7CF0571-25CB-43D5-8443-0843A1E2861A}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>HeuristicLab.Selection</RootNamespace>
+    <AssemblyName>HeuristicLab.Selection-3.2</AssemblyName>
+    <SignAssembly>true</SignAssembly>
+    <AssemblyOriginatorKeyFile>HeuristicLab.snk</AssemblyOriginatorKeyFile>
+    <FileUpgradeFlags>
+    </FileUpgradeFlags>
+    <OldToolsVersion>2.0</OldToolsVersion>
+    <UpgradeBackupLocation>
+    </UpgradeBackupLocation>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
+    <DocumentationFile>bin\Release\HeuristicLab.Selection-3.2.XML</DocumentationFile>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\x86\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x86</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <OutputPath>bin\x86\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <DocumentationFile>bin\Release\HeuristicLab.Selection-3.2.XML</DocumentationFile>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x86</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\x64\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
+    <OutputPath>bin\x64\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <DocumentationFile>bin\Release\HeuristicLab.Selection-3.2.XML</DocumentationFile>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="RightChildReducer.cs" />
+    <Compile Include="LeftReducer.cs" />
+    <Compile Include="MergingReducer.cs" />
+    <Compile Include="ProportionalSelector.cs" />
+    <Compile Include="LinearRankSelector.cs" />
+    <Compile Include="LeftSelector.cs" />
+    <Compile Include="RandomSelector.cs" />
+    <Compile Include="ReducerBase.cs" />
+    <Compile Include="RightReducer.cs" />
+    <Compile Include="RightSelector.cs" />
+    <Compile Include="SelectorBase.cs" />
+    <Compile Include="StochasticSelectorBase.cs" />
+    <Compile Include="TournamentSelector.cs" />
+    <Compile Include="HeuristicLabSelectionPlugin.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="HeuristicLab.snk" />
+    <None Include="Properties\AssemblyInfo.frame" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\HeuristicLab.Core\3.2\HeuristicLab.Core-3.2.csproj">
+      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
+      <Name>HeuristicLab.Core-3.2</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\..\HeuristicLab.Data\3.2\HeuristicLab.Data-3.2.csproj">
+      <Project>{F473D9AF-3F09-4296-9F28-3C65118DAFFA}</Project>
+      <Name>HeuristicLab.Data-3.2</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\..\HeuristicLab.Operators\3.2\HeuristicLab.Operators-3.2.csproj">
+      <Project>{A9983BA2-B3B2-475E-8E2C-62050B71D1C5}</Project>
+      <Name>HeuristicLab.Operators-3.2</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
+      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
+      <Name>HeuristicLab.PluginInfrastructure</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+  <PropertyGroup>
+    <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
+set ProjectDir=$(ProjectDir)
+set SolutionDir=$(SolutionDir)
+set Outdir=$(Outdir)
+
+call PreBuildEvent.cmd</PreBuildEvent>
+  </PropertyGroup>
+</Project>
Index: trunk/sources/HeuristicLab.Selection/3.3/HeuristicLabSelectionPlugin.cs
===================================================================
--- trunk/sources/HeuristicLab.Selection/3.3/HeuristicLabSelectionPlugin.cs	(revision 1692)
+++ trunk/sources/HeuristicLab.Selection/3.3/HeuristicLabSelectionPlugin.cs	(revision 1692)
@@ -0,0 +1,38 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using HeuristicLab.PluginInfrastructure;
+
+namespace HeuristicLab.Selection {
+  /// <summary>
+  /// Plugin class for HeuristicLab.Selection plugin.
+  /// </summary>
+  [ClassInfo(Name = "HeuristicLab.Selection-3.2")]
+  [PluginFile(Filename = "HeuristicLab.Selection-3.2.dll", Filetype = PluginFileType.Assembly)]
+  [Dependency(Dependency = "HeuristicLab.Core-3.2")]
+  [Dependency(Dependency = "HeuristicLab.Data-3.2")]
+  [Dependency(Dependency = "HeuristicLab.Operators-3.2")]
+  public class HeuristicLabSelectionPlugin : PluginBase {
+  }
+}
Index: trunk/sources/HeuristicLab.Selection/3.3/LeftReducer.cs
===================================================================
--- trunk/sources/HeuristicLab.Selection/3.3/LeftReducer.cs	(revision 1692)
+++ trunk/sources/HeuristicLab.Selection/3.3/LeftReducer.cs	(revision 1692)
@@ -0,0 +1,51 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using HeuristicLab.Core;
+using HeuristicLab.Operators;
+
+namespace HeuristicLab.Selection {
+  /// <summary>
+  /// Takes only sub scopes from the left child of the tree.
+  /// </summary>
+  public class LeftReducer : ReducerBase {
+    /// <inheritdoc select="summary"/>
+    public override string Description {
+      get { return @"TODO\r\nOperator description still missing ..."; }
+    }
+
+    /// <summary>
+    /// Takes only the sub scopes from the left sub scope of the tree.
+    /// </summary>
+    /// <param name="scope">The current scope.</param>
+    /// <returns>All sub scopes from the left part of the tree.</returns>
+    protected override ICollection<IScope> Reduce(IScope scope) {
+      List<IScope> subScopes = new List<IScope>();
+
+      if (scope.SubScopes.Count > 0)
+        subScopes.AddRange(scope.SubScopes[0].SubScopes);
+      return subScopes;
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.Selection/3.3/LeftSelector.cs
===================================================================
--- trunk/sources/HeuristicLab.Selection/3.3/LeftSelector.cs	(revision 1692)
+++ trunk/sources/HeuristicLab.Selection/3.3/LeftSelector.cs	(revision 1692)
@@ -0,0 +1,64 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using HeuristicLab.Core;
+
+namespace HeuristicLab.Selection {
+  /// <summary>
+  /// Copies or moves a defined number of sub scopes from a source scope to a target scope, starting at
+  /// the left side of the tree.
+  /// </summary>
+  public class LeftSelector : StochasticSelectorBase {
+    /// <inheritdoc select="summary"/>
+    public override string Description {
+      get { return @"TODO\r\nOperator description still missing ..."; }
+    }
+
+    /// <summary>
+    /// Copies or moves a number of sub scopes (<paramref name="selected"/>) from <paramref name="source"/>
+    /// starting at the left end to the <paramref name="target"/>.
+    /// </summary>
+    /// <param name="random">A random number generator.</param>
+    /// <param name="source">The source scope from which to copy/move the sub scopes.</param>
+    /// <param name="selected">The number of sub scopes to move. Can be also bigger than the total 
+    /// number of sub scopes in <paramref name="source"/>, then the copying process starts again from the 
+    /// beginning.</param>
+    /// <param name="target">The target where to copy/move the sub scopes.</param>
+    /// <param name="copySelected">Boolean flag whether the sub scopes shall be copied or moved.</param>
+    protected override void Select(IRandom random, IScope source, int selected, IScope target, bool copySelected) {
+      int index = 0;
+      for (int i = 0; i < selected; i++) {
+        if (copySelected) {
+          target.AddSubScope((IScope)source.SubScopes[index].Clone());
+          index++;
+          if (index >= source.SubScopes.Count) index = 0;
+        } else {
+          IScope s = source.SubScopes[0];
+          source.RemoveSubScope(s);
+          target.AddSubScope(s);
+        }
+      }
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.Selection/3.3/LinearRankSelector.cs
===================================================================
--- trunk/sources/HeuristicLab.Selection/3.3/LinearRankSelector.cs	(revision 1692)
+++ trunk/sources/HeuristicLab.Selection/3.3/LinearRankSelector.cs	(revision 1692)
@@ -0,0 +1,85 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+
+namespace HeuristicLab.Selection {
+  /// <summary>
+  /// Selects scopes based on their rank, which has been determined through their quality.
+  /// </summary>
+  public class LinearRankSelector : StochasticSelectorBase {
+    /// <inheritdoc select="summary"/>
+    public override string Description {
+      get { return @"TODO\r\nOperator description still missing ..."; }
+    }
+
+    /// <summary>
+    /// Initializes a new instance of <see cref="LinearRankSelector"/> with the <c>CopySelected</c> flag
+    /// set to <c>true</c>.
+    /// </summary>
+    public LinearRankSelector() {
+      GetVariable("CopySelected").GetValue<BoolData>().Data = true;
+    }
+
+    /// <summary>
+    /// Copies or moves sub scopes from the given <paramref name="source"/> to the specified
+    /// <paramref name="target"/> according to their rank which is determined through their quality.
+    /// </summary>
+    /// <exception cref="InvalidOperationException">Thrown when no source sub scopes are available.</exception>
+    /// <param name="random">The random number generator.</param>
+    /// <param name="source">The source scope from where to copy/move the sub scopes.</param>
+    /// <param name="selected">The number of sub scopes to copy/move.</param>
+    /// <param name="target">The target scope where to add the sub scopes.</param>
+    /// <param name="copySelected">Boolean flag whether the sub scopes shall be moved or copied.</param>
+    protected override void Select(IRandom random, IScope source, int selected, IScope target, bool copySelected) {
+      int subScopes = source.SubScopes.Count;
+      int lotSum = (subScopes * (subScopes + 1)) / 2;
+      int selectedLot;
+      int currentLot;
+      int index;
+
+      for (int i = 0; i < selected; i++) {
+        if (subScopes < 1) throw new InvalidOperationException("No source scopes available to select.");
+
+        selectedLot = random.Next(1, lotSum + 1);
+        currentLot = subScopes;  // first individual is the best one
+        index = 0;
+        while (currentLot < selectedLot) {
+          index++;
+          currentLot += subScopes - index;
+        }
+        IScope selectedScope = source.SubScopes[index];
+        if (copySelected)
+          target.AddSubScope((IScope)selectedScope.Clone());
+        else {
+          source.RemoveSubScope(selectedScope);
+          target.AddSubScope(selectedScope);
+          subScopes--;
+          lotSum = (subScopes * (subScopes + 1)) / 2;
+        }
+      }
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.Selection/3.3/MergingReducer.cs
===================================================================
--- trunk/sources/HeuristicLab.Selection/3.3/MergingReducer.cs	(revision 1692)
+++ trunk/sources/HeuristicLab.Selection/3.3/MergingReducer.cs	(revision 1692)
@@ -0,0 +1,53 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using HeuristicLab.Core;
+using HeuristicLab.Operators;
+
+namespace HeuristicLab.Selection {
+  /// <summary>
+  /// Merges all sub scopes of the children to one list.
+  /// </summary>
+  public class MergingReducer : ReducerBase {
+    /// <inheritdoc select="summary"/>
+    public override string Description {
+      get { return @"TODO\r\nOperator description still missing ..."; }
+    }
+
+    /// <summary>
+    /// Merges all sub scopes of the sub scopes of the current <paramref name="scope"/>.
+    /// </summary>
+    /// <param name="scope">The current scope whose sub scopes to merge.</param>
+    /// <returns>A list of all merged subscopes of the given <paramref name="scope"/>.</returns>
+    protected override ICollection<IScope> Reduce(IScope scope) {
+      List<IScope> subScopes = new List<IScope>();
+
+      for (int i = 0; i < scope.SubScopes.Count; i++) {
+        for (int j = 0; j < scope.SubScopes[i].SubScopes.Count; j++)
+          subScopes.Add(scope.SubScopes[i].SubScopes[j]);
+      }
+      return subScopes;
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.Selection/3.3/Properties/AssemblyInfo.frame
===================================================================
--- trunk/sources/HeuristicLab.Selection/3.3/Properties/AssemblyInfo.frame	(revision 1692)
+++ trunk/sources/HeuristicLab.Selection/3.3/Properties/AssemblyInfo.frame	(revision 1692)
@@ -0,0 +1,58 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using HeuristicLab.PluginInfrastructure;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("HeuristicLab.Selection")]
+[assembly: AssemblyDescription("HeuristicLab selection operators")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("HeuristicLab")]
+[assembly: AssemblyCopyright("(c) 2002-2008 HEAL")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("ed119c1e-a48f-41de-a797-43352ff4f1a3")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers 
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("3.2.0.$WCREV$")]
+[assembly: AssemblyFileVersion("3.2.0.$WCREV$")]
+[assembly: AssemblyBuildDate("$WCNOW$")]
Index: trunk/sources/HeuristicLab.Selection/3.3/ProportionalSelector.cs
===================================================================
--- trunk/sources/HeuristicLab.Selection/3.3/ProportionalSelector.cs	(revision 1692)
+++ trunk/sources/HeuristicLab.Selection/3.3/ProportionalSelector.cs	(revision 1692)
@@ -0,0 +1,155 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+
+namespace HeuristicLab.Selection {
+  /// <summary>
+  /// Copies or moves a number of sub scopes from a source scope to a target scope, their probability
+  /// to be selected depending on their quality.
+  /// </summary>
+  public class ProportionalSelector : StochasticSelectorBase {
+    /// <inheritdoc select="summary"/>
+    public override string Description {
+      get { return @"TODO\r\nOperator description still missing ..."; }
+    }
+
+    /// <summary>
+    /// Initializes a new instance of <see cref="ProportionalSelector"/> with three variable infos 
+    /// (<c>Maximization</c>, <c>Quality</c> and <c>Windowing</c>, being a local variable and initialized 
+    /// with <c>true</c>) and the <c>CopySelected</c> flag set to <c>true</c>.
+    /// </summary>
+    public ProportionalSelector() {
+      AddVariableInfo(new VariableInfo("Maximization", "Maximization problem", typeof(BoolData), VariableKind.In));
+      AddVariableInfo(new VariableInfo("Quality", "Quality value", typeof(DoubleData), VariableKind.In));
+      AddVariableInfo(new VariableInfo("Windowing", "Apply windowing strategy (selection probability is proportional to the quality differences and not to the total quality)", typeof(BoolData), VariableKind.In));
+      GetVariableInfo("Windowing").Local = true;
+      AddVariable(new Variable("Windowing", new BoolData(true)));
+      GetVariable("CopySelected").GetValue<BoolData>().Data = true;
+    }
+
+    /// <summary>
+    /// Copies or movies a number of sub scopes (<paramref name="selected"/>) in the given 
+    /// <paramref name="source"/> to the given <paramref name="target"/>, selection takes place with respect
+    /// to the quality of the scope.
+    /// </summary>
+    /// <param name="random">The random number generator.</param>
+    /// <param name="source">The source scope from where to copy/move the sub scopes.</param>
+    /// <param name="selected">The number of sub scopes to copy/move.</param>
+    /// <param name="target">The target scope where to add the sub scopes.</param>
+    /// <param name="copySelected">Boolean flag whether the sub scopes shall be moved or copied.</param>
+    protected override void Select(IRandom random, IScope source, int selected, IScope target, bool copySelected) {
+      bool maximization = GetVariableValue<BoolData>("Maximization", source, true).Data;
+      IVariableInfo qualityInfo = GetVariableInfo("Quality");
+      bool windowing = GetVariableValue<BoolData>("Windowing", source, true).Data;
+
+      double[] qualities;
+      double qualitySum;
+      double selectedQuality;
+      double sum;
+      int j;
+
+      GenerateQualitiesArray(source, maximization, qualityInfo, windowing, out qualities, out qualitySum);
+
+      // perform selection
+      for (int i = 0; i < selected; i++) {
+        selectedQuality = random.NextDouble() * qualitySum;
+        sum = 0;
+        j = 0;
+        while ((j < qualities.Length) && (sum <= selectedQuality)) {
+          sum += qualities[j];
+          j++;
+        }
+        IScope selectedScope = source.SubScopes[j - 1];
+        if (copySelected)
+          target.AddSubScope((IScope)selectedScope.Clone());
+        else {
+          source.RemoveSubScope(selectedScope);
+          target.AddSubScope(selectedScope);
+          GenerateQualitiesArray(source, maximization, qualityInfo, windowing, out qualities, out qualitySum);
+        }
+      }
+    }
+
+    /// <summary>
+    /// Calculates the qualities of the sub scopes of the given <paramref name="source"/>.
+    /// </summary>
+    /// <exception cref="InvalidOperationException">Thrown when the sub scopes are not sorted according
+    /// to their solution qualities or if the quality value is beyond zero and the <c>windowing</c>
+    /// flag is set to <c>false</c>.</exception>
+    /// <param name="source">The scource scope where to calculate the qualities.</param>
+    /// <param name="maximization">Boolean flag whether is a maximization problem.</param>
+    /// <param name="qualityInfo">The quality variable info.</param>
+    /// <param name="windowing">Boolean flag whether the windowing strategy shall be applied.</param>
+    /// <param name="qualities">Output parameter; contains all qualities of the sub scopes.</param>
+    /// <param name="qualitySum">Output parameter; the sum of all qualities.</param>
+    private void GenerateQualitiesArray(IScope source, bool maximization, IVariableInfo qualityInfo, bool windowing, out double[] qualities, out double qualitySum) {
+      int subScopes = source.SubScopes.Count;
+      qualities = new double[subScopes];
+      qualitySum = 0;
+
+      if (subScopes < 1) throw new InvalidOperationException("No source scopes to select available.");
+
+      double best = source.SubScopes[0].GetVariableValue<DoubleData>(qualityInfo.FormalName, false).Data;
+      double worst = source.SubScopes[subScopes - 1].GetVariableValue<DoubleData>(qualityInfo.FormalName, false).Data;
+      double limit = Math.Min(worst * 2, double.MaxValue);
+      double min = Math.Min(best, worst);
+      double max = Math.Max(best, worst);
+      double solutionQuality;
+
+      // preprocess fitness values, apply windowing if desired
+      for (int i = 0; i < qualities.Length; i++) {
+        solutionQuality = source.SubScopes[i].GetVariableValue<DoubleData>(qualityInfo.FormalName, false).Data;
+        if (solutionQuality < min || solutionQuality > max) {
+          // something has obviously gone wrong here
+          string errorMessage = "There is a problem with the ordering of the source sub-scopes in " + Name + ".\r\n" +
+            "The quality of solution number " + i.ToString() + " is ";
+          if (solutionQuality < min) errorMessage += "below";
+          else errorMessage += "greater than";
+          errorMessage += " the calculated qualities range:\r\n";
+          errorMessage += solutionQuality.ToString() + " is outside the interval [ " + min.ToString() + " ; " + max.ToString() + " ].";
+          throw new InvalidOperationException(errorMessage);
+        }
+        if (best != worst) {  // prevent division by zero
+          if (windowing) {
+            if (!maximization) {
+              qualities[i] = 1 - ((solutionQuality - best) / (worst - best));
+            } else {
+              qualities[i] = (solutionQuality - worst) / (best - worst);
+            }
+          } else {
+            if (solutionQuality < 0.0) throw new InvalidOperationException("ERROR in ProportionalSelector: Non-windowing is not working with quality values < 0. Use windowing.");
+            if (!maximization) qualities[i] = limit - solutionQuality;
+            else qualities[i] = solutionQuality;
+          }
+        } else {  // best == worst -> all fitness values are equal
+          qualities[i] = 1;
+        }
+        qualitySum += qualities[i];
+      }
+      if (double.IsInfinity(qualitySum)) qualitySum = double.MaxValue;
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.Selection/3.3/RandomSelector.cs
===================================================================
--- trunk/sources/HeuristicLab.Selection/3.3/RandomSelector.cs	(revision 1692)
+++ trunk/sources/HeuristicLab.Selection/3.3/RandomSelector.cs	(revision 1692)
@@ -0,0 +1,59 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using HeuristicLab.Core;
+
+namespace HeuristicLab.Selection {
+  /// <summary>
+  /// Copies or moves a defined number of sub scopes from a source scope to a target scope, being selected
+  /// randomly.
+  /// </summary>
+  public class RandomSelector : StochasticSelectorBase {
+    /// <inheritdoc select="summary"/>
+    public override string Description {
+      get { return @"TODO\r\nOperator description still missing ..."; }
+    }
+
+    /// <summary>
+    /// Copies or moves a number of sub scopes (<paramref name="selected"/>) from <paramref name="source"/>
+    /// to the <paramref name="target"/>, chosen randomly.
+    /// </summary>
+    /// <param name="random">The random number generator.</param>
+    /// <param name="source">The source scope from which to copy/move the sub scopes.</param>
+    /// <param name="selected">The number of sub scopes to move.</param>
+    /// <param name="target">The target where to copy/move the sub scopes.</param>
+    /// <param name="copySelected">Boolean flag whether the sub scopes shall be copied or moved.</param>
+    protected override void Select(IRandom random, IScope source, int selected, IScope target, bool copySelected) {
+      for (int i = 0; i < selected; i++) {
+        if (copySelected) {
+          target.AddSubScope((IScope)source.SubScopes[random.Next(source.SubScopes.Count)].Clone());
+        } else {
+          IScope s = source.SubScopes[random.Next(source.SubScopes.Count)];
+          source.RemoveSubScope(s);
+          target.AddSubScope(s);
+        }
+      }
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.Selection/3.3/ReducerBase.cs
===================================================================
--- trunk/sources/HeuristicLab.Selection/3.3/ReducerBase.cs	(revision 1692)
+++ trunk/sources/HeuristicLab.Selection/3.3/ReducerBase.cs	(revision 1692)
@@ -0,0 +1,59 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using HeuristicLab.Core;
+using HeuristicLab.Operators;
+
+namespace HeuristicLab.Selection {
+  /// <summary>
+  /// Base class for all reducers.
+  /// </summary>
+  public abstract class ReducerBase : OperatorBase {
+    /// <summary>
+    /// Reduces the given <paramref name="scope"/> so that it contains in the end only the reduced
+    /// elements.
+    /// </summary>
+    /// <remarks>Calls <see cref="Reduce"/>.</remarks>
+    /// <param name="scope">The scope to reduce.</param>
+    /// <returns><c>null</c>.</returns>
+    public override IOperation Apply(IScope scope) {
+      ICollection<IScope> subScopes = Reduce(scope);
+
+      while (scope.SubScopes.Count > 0)
+        scope.RemoveSubScope(scope.SubScopes[0]);
+
+      foreach (IScope s in subScopes)
+        scope.AddSubScope(s);
+
+      return null;
+    }
+
+    /// <summary>
+    /// Reduces the current <paramref name="scope"/>.
+    /// </summary>
+    /// <param name="scope">The scope to reduce.</param>
+    /// <returns>The reduced list of scopes, that should be kept.</returns>
+    protected abstract ICollection<IScope> Reduce(IScope scope);
+  }
+}
Index: trunk/sources/HeuristicLab.Selection/3.3/RightChildReducer.cs
===================================================================
--- trunk/sources/HeuristicLab.Selection/3.3/RightChildReducer.cs	(revision 1692)
+++ trunk/sources/HeuristicLab.Selection/3.3/RightChildReducer.cs	(revision 1692)
@@ -0,0 +1,71 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using HeuristicLab.Core;
+using HeuristicLab.Operators;
+
+namespace HeuristicLab.Selection {
+  /// <summary>
+  /// Reduces the sub scopes by one level, so that the right sub scope contains also the right child scopes
+  /// of the left sub scope and the left sub scope represents its left child scope.
+  /// <pre>                                                      
+  ///                   scope             scope  
+  ///                   / | \             /   \      
+  ///                  L ... R   =>      A     R                 
+  ///                / | \    \              / /\ \       
+  ///               A ... LR   C             C D E F      
+  ///                     /|\                              
+  ///                    D E F                             
+  /// </pre>
+  /// </summary>
+  public class RightChildReducer : ReducerBase {
+    /// <inheritdoc select="summary"/>
+    public override string Description {
+      get { return @"TODO\r\nOperator description still missing ..."; }
+    }
+
+    /// <summary>
+    /// Reduces the right child of the left sub scope and adds its sub scopes to the right sub scope.
+    /// The left sub scope is also narrowed, which means it represents then its left child.
+    /// </summary>
+    /// <param name="scope">The current scope to reduce.</param>
+    /// <returns>A list of the new reduced sub scopes.</returns>
+    protected override ICollection<IScope> Reduce(IScope scope) {
+      IScope rightChild = scope.SubScopes[scope.SubScopes.Count - 1];
+      IScope leftChild = scope.SubScopes[0];
+      IScope leftRightChild = leftChild.SubScopes[leftChild.SubScopes.Count - 1];
+
+      // merge right children
+      for (int i = 0; i < leftRightChild.SubScopes.Count; i++)
+        rightChild.AddSubScope(leftRightChild.SubScopes[i]);
+
+      leftChild = leftChild.SubScopes[0];
+
+      List<IScope> subScopes = new List<IScope>();
+      subScopes.Add(leftChild);
+      subScopes.Add(rightChild);
+      return subScopes;
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.Selection/3.3/RightReducer.cs
===================================================================
--- trunk/sources/HeuristicLab.Selection/3.3/RightReducer.cs	(revision 1692)
+++ trunk/sources/HeuristicLab.Selection/3.3/RightReducer.cs	(revision 1692)
@@ -0,0 +1,51 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using HeuristicLab.Core;
+using HeuristicLab.Operators;
+
+namespace HeuristicLab.Selection {
+  /// <summary>
+  /// Takes only sub scopes from the right child of the tree.
+  /// </summary>
+  public class RightReducer : ReducerBase {
+    /// <inheritdoc select="summary"/>
+    public override string Description {
+      get { return @"TODO\r\nOperator description still missing ..."; }
+    }
+
+    /// <summary>
+    /// Takes only the sub scopes from the right part of the tree.
+    /// </summary>
+    /// <param name="scope">The current scope.</param>
+    /// <returns>All sub scopes from the right sub scope of the tree.</returns>
+    protected override ICollection<IScope> Reduce(IScope scope) {
+      List<IScope> subScopes = new List<IScope>();
+
+      if (scope.SubScopes.Count > 0)
+        subScopes.AddRange(scope.SubScopes[scope.SubScopes.Count - 1].SubScopes);
+      return subScopes;
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.Selection/3.3/RightSelector.cs
===================================================================
--- trunk/sources/HeuristicLab.Selection/3.3/RightSelector.cs	(revision 1692)
+++ trunk/sources/HeuristicLab.Selection/3.3/RightSelector.cs	(revision 1692)
@@ -0,0 +1,64 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using HeuristicLab.Core;
+
+namespace HeuristicLab.Selection {
+  /// <summary>
+  /// Copies or moves a defined number of sub scopes from a source scope to a target scope, starting at
+  /// the right side of the tree.
+  /// </summary>
+  public class RightSelector : StochasticSelectorBase {
+    /// <inheritdoc select="summary"/>
+    public override string Description {
+      get { return @"TODO\r\nOperator description still missing ..."; }
+    }
+
+    /// <summary>
+    /// Copies or moves a number of sub scopes (<paramref name="selected"/>) from <paramref name="source"/>
+    /// starting at the right end to the <paramref name="target"/>.
+    /// </summary>
+    /// <param name="random">A random number generator.</param>
+    /// <param name="source">The source scope from which to copy/move the sub scopes.</param>
+    /// <param name="selected">The number of sub scopes to move. Can be also bigger than the total 
+    /// number of sub scopes in <paramref name="source"/>, then the copying process starts again from the 
+    /// beginning.</param>
+    /// <param name="target">The target where to copy/move the sub scopes.</param>
+    /// <param name="copySelected">Boolean flag whether the sub scopes shall be copied or moved.</param>
+    protected override void Select(IRandom random, IScope source, int selected, IScope target, bool copySelected) {
+      int index = source.SubScopes.Count - 1;
+      for (int i = 0; i < selected; i++) {
+        if (copySelected) {
+          target.AddSubScope((IScope)source.SubScopes[index].Clone());
+          index--;
+          if (index < 0) index = source.SubScopes.Count - 1;
+        } else {
+          IScope s = source.SubScopes[source.SubScopes.Count - 1];
+          source.RemoveSubScope(s);
+          target.AddSubScope(s);
+        }
+      }
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.Selection/3.3/SelectorBase.cs
===================================================================
--- trunk/sources/HeuristicLab.Selection/3.3/SelectorBase.cs	(revision 1692)
+++ trunk/sources/HeuristicLab.Selection/3.3/SelectorBase.cs	(revision 1692)
@@ -0,0 +1,79 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Operators;
+
+namespace HeuristicLab.Selection {
+  /// <summary>
+  /// Base class for all selectors.
+  /// </summary>
+  public abstract class SelectorBase : OperatorBase {
+    /// <summary>
+    /// Initializes a new instance of <see cref="SelectorBase"/> with one variable infos 
+    /// (<c>CopySelected</c>), which is a local one.
+    /// </summary>
+    public SelectorBase()
+      : base() {
+      AddVariableInfo(new VariableInfo("CopySelected", "Copy or move selected sub-scopes", typeof(BoolData), VariableKind.In));
+      GetVariableInfo("CopySelected").Local = true;
+      AddVariable(new Variable("CopySelected", new BoolData(false)));
+    }
+
+    /// <summary>
+    /// Inserts a new level of sub scopes in the given <paramref name="scope"/> with a scope containing the
+    /// remaining sub scopes and another with the selected ones.
+    /// </summary>
+    /// <remarks>Calls <see cref="Select"/>.</remarks>
+    /// <param name="scope">The scope where to select the sub scopes.</param>
+    /// <returns><c>null</c>.</returns>
+    public override IOperation Apply(IScope scope) {
+      BoolData copySelected = GetVariableValue<BoolData>("CopySelected", scope, true);
+
+      IScope source = new Scope("Remaining");
+      while (scope.SubScopes.Count > 0) {
+        IScope s = scope.SubScopes[0];
+        scope.RemoveSubScope(s);
+        source.AddSubScope(s);
+      }
+      scope.AddSubScope(source);
+      IScope target = new Scope("Selected");
+      scope.AddSubScope(target);
+
+      Select(source, target, copySelected.Data);
+
+      return null;
+    }
+
+    /// <summary>
+    /// Selects sub scopes from the specified <paramref name="source"/> and moves or copies it to the
+    /// specified <paramref name="target"/>.
+    /// </summary>
+    /// <param name="source">The source scope where to select the sub scopes.</param>
+    /// <param name="target">The target where to add the sub scopes.</param>
+    /// <param name="copySelected">Boolean flag whether to copy or move the selected sub scopes.</param>
+    protected abstract void Select(IScope source, IScope target, bool copySelected);
+  }
+}
Index: trunk/sources/HeuristicLab.Selection/3.3/StochasticSelectorBase.cs
===================================================================
--- trunk/sources/HeuristicLab.Selection/3.3/StochasticSelectorBase.cs	(revision 1692)
+++ trunk/sources/HeuristicLab.Selection/3.3/StochasticSelectorBase.cs	(revision 1692)
@@ -0,0 +1,71 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Operators;
+
+namespace HeuristicLab.Selection {
+  /// <summary>
+  /// Base class for all selectors that use a random number generator.
+  /// </summary>
+  public abstract class StochasticSelectorBase : SelectorBase {
+    /// <summary>
+    /// Initializes a new instance of <see cref="StochasticSelectorBase"/> with two variable infos
+    /// (<c>Random</c> and <c>Selected</c>).
+    /// </summary>
+    public StochasticSelectorBase()
+      : base() {
+      AddVariableInfo(new VariableInfo("Random", "Pseudo random number generator", typeof(IRandom), VariableKind.In));
+      AddVariableInfo(new VariableInfo("Selected", "Number of selected sub-scopes", typeof(IntData), VariableKind.In));
+    }
+
+    /// <summary>
+    /// Copies or moves randomly chosen sub scopes from the given <paramref name="source"/> to the specified 
+    /// <paramref name="target"/>.
+    /// </summary>
+    /// <remarks>Calls <see cref="Select(HeuristicLab.Core.IRandom, HeuristicLab.Core.IScope, int,
+    /// HeuristicLab.Core.IScope, bool)"/></remarks>
+    /// <param name="source">The source scope from where to copy/move the sub scopes.</param>
+    /// <param name="target">The target scope where to add the sub scopes.</param>
+    /// <param name="copySelected">Boolean flag whether the sub scopes shall be moved or copied.</param>
+    protected sealed override void Select(IScope source, IScope target, bool copySelected) {
+      IRandom random = GetVariableValue<IRandom>("Random", source, true);
+      IntData selected = GetVariableValue<IntData>("Selected", source, true);
+
+      Select(random, source, selected.Data, target, copySelected);
+    }
+
+    /// <summary>
+    /// Copies or moves randomly chosen sub scopes from the given <paramref name="source"/> to the specified 
+    /// <paramref name="target"/>.
+    /// </summary>
+    /// <param name="random">The random number generator.</param>
+    /// <param name="source">The source scope from where to copy/move the sub scopes.</param>
+    /// <param name="selected">The number of sub scopes to copy/move.</param>
+    /// <param name="target">The target scope where to add the sub scopes.</param>
+    /// <param name="copySelected">Boolean flag whether the sub scopes shall be moved or copied.</param>
+    protected abstract void Select(IRandom random, IScope source, int selected, IScope target, bool copySelected);
+  }
+}
Index: trunk/sources/HeuristicLab.Selection/3.3/TournamentSelector.cs
===================================================================
--- trunk/sources/HeuristicLab.Selection/3.3/TournamentSelector.cs	(revision 1692)
+++ trunk/sources/HeuristicLab.Selection/3.3/TournamentSelector.cs	(revision 1692)
@@ -0,0 +1,90 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+
+namespace HeuristicLab.Selection {
+  /// <summary>
+  /// Moves or copies a defined number of the best sub scopes from a source scope to a target scope.
+  /// </summary>
+  public class TournamentSelector : StochasticSelectorBase {
+    /// <inheritdoc select="summary"/>
+    public override string Description {
+      get { return @"TODO\r\nOperator description still missing ..."; }
+    }
+
+    /// <summary>
+    /// Initializes a new instance of <see cref="TournamentSelector"/> with three variable infos 
+    /// (<c>Maximization</c>, <c>Quality</c> and <c>GroupSize</c>, being a local variable and set to 
+    /// <c>2</c>) with <c>CopySelected</c> set to <c>true</c>.
+    /// </summary>
+    public TournamentSelector() {
+      AddVariableInfo(new VariableInfo("Maximization", "Maximization problem", typeof(BoolData), VariableKind.In));
+      AddVariableInfo(new VariableInfo("Quality", "Quality value", typeof(DoubleData), VariableKind.In));
+      AddVariableInfo(new VariableInfo("GroupSize", "Size of the tournament group", typeof(IntData), VariableKind.In));
+      GetVariableInfo("GroupSize").Local = true;
+      AddVariable(new Variable("GroupSize", new IntData(2)));
+      GetVariable("CopySelected").GetValue<BoolData>().Data = true;
+    }
+
+    /// <summary>
+    /// Copies or moves the best sub scopes from the given <paramref name="source"/> to the specified
+    /// <paramref name="target"/>.
+    /// </summary>
+    /// <exception cref="InvalidOperationException">Thrown when no source sub scopes are available.</exception>
+    /// <param name="random">The random number generator.</param>
+    /// <param name="source">The source scope from where to copy/move the sub scopes.</param>
+    /// <param name="selected">The number of sub scopes to copy/move.</param>
+    /// <param name="target">The target scope where to add the sub scopes.</param>
+    /// <param name="copySelected">Boolean flag whether the sub scopes shall be moved or copied.</param>
+    protected override void Select(IRandom random, IScope source, int selected, IScope target, bool copySelected) {
+      IVariableInfo qualityInfo = GetVariableInfo("Quality");
+      bool maximization = GetVariableValue<BoolData>("Maximization", source, true).Data;
+      int groupSize = GetVariableValue<IntData>("GroupSize", source, true).Data;
+      for (int i = 0; i < selected; i++) {
+        if (source.SubScopes.Count < 1) throw new InvalidOperationException("No source scopes available to select.");
+
+        IScope selectedScope = source.SubScopes[random.Next(source.SubScopes.Count)];
+        double best = selectedScope.GetVariableValue<DoubleData>(qualityInfo.FormalName, false).Data;
+        for (int j = 1; j < groupSize; j++) {
+          IScope scope = source.SubScopes[random.Next(source.SubScopes.Count)];
+          double quality = scope.GetVariableValue<DoubleData>(qualityInfo.FormalName, false).Data;
+          if (((maximization) && (quality > best)) ||
+              ((!maximization) && (quality < best))) {
+            best = quality;
+            selectedScope = scope;
+          }
+        }
+
+        if (copySelected)
+          target.AddSubScope((IScope)selectedScope.Clone());
+        else {
+          source.RemoveSubScope(selectedScope);
+          target.AddSubScope(selectedScope);
+        }
+      }
+    }
+  }
+}
