Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/17/12 16:05:58 (12 years ago)
Author:
mkommend
Message:

#1997: Adapted SymbolicDataAnalysisIslandGA to calculate the fixed samples partition for every island.

Location:
branches/DataAnalysis.IslandAlgorithms
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis.IslandAlgorithms/DataAnalysis.IslandAlgorithms.sln

    r9048 r9067  
    1010Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Algorithms.DataAnalysis.Symbolic", "HeuristicLab.Algorithms.DataAnalysis.Symbolic\3.3\HeuristicLab.Algorithms.DataAnalysis.Symbolic.csproj", "{F0D5AF15-76A8-4023-AB77-7B138D579860}"
    1111EndProject
     12Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Algorithms.GeneticAlgorithm-3.3", "HeuristicLab.Algorithms.GeneticAlgorithm\3.3\HeuristicLab.Algorithms.GeneticAlgorithm-3.3.csproj", "{A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}"
     13EndProject
    1214Global
    1315  GlobalSection(SolutionConfigurationPlatforms) = preSolution
    1416    Debug|Any CPU = Debug|Any CPU
     17    Debug|x64 = Debug|x64
     18    Debug|x86 = Debug|x86
    1519    Release|Any CPU = Release|Any CPU
     20    Release|x64 = Release|x64
     21    Release|x86 = Release|x86
    1622  EndGlobalSection
    1723  GlobalSection(ProjectConfigurationPlatforms) = postSolution
    1824    {F0D5AF15-76A8-4023-AB77-7B138D579860}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    1925    {F0D5AF15-76A8-4023-AB77-7B138D579860}.Debug|Any CPU.Build.0 = Debug|Any CPU
     26    {F0D5AF15-76A8-4023-AB77-7B138D579860}.Debug|x64.ActiveCfg = Debug|Any CPU
     27    {F0D5AF15-76A8-4023-AB77-7B138D579860}.Debug|x86.ActiveCfg = Debug|Any CPU
    2028    {F0D5AF15-76A8-4023-AB77-7B138D579860}.Release|Any CPU.ActiveCfg = Release|Any CPU
    2129    {F0D5AF15-76A8-4023-AB77-7B138D579860}.Release|Any CPU.Build.0 = Release|Any CPU
     30    {F0D5AF15-76A8-4023-AB77-7B138D579860}.Release|x64.ActiveCfg = Release|Any CPU
     31    {F0D5AF15-76A8-4023-AB77-7B138D579860}.Release|x86.ActiveCfg = Release|Any CPU
     32    {A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     33    {A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}.Debug|Any CPU.Build.0 = Debug|Any CPU
     34    {A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}.Debug|x64.ActiveCfg = Debug|x64
     35    {A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}.Debug|x64.Build.0 = Debug|x64
     36    {A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}.Debug|x86.ActiveCfg = Debug|x86
     37    {A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}.Debug|x86.Build.0 = Debug|x86
     38    {A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}.Release|Any CPU.ActiveCfg = Release|Any CPU
     39    {A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}.Release|Any CPU.Build.0 = Release|Any CPU
     40    {A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}.Release|x64.ActiveCfg = Release|x64
     41    {A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}.Release|x64.Build.0 = Release|x64
     42    {A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}.Release|x86.ActiveCfg = Release|x86
     43    {A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}.Release|x86.Build.0 = Release|x86
    2244  EndGlobalSection
    2345  GlobalSection(SolutionProperties) = preSolution
  • branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/HeuristicLab.Algorithms.DataAnalysis.Symbolic.csproj

    r9051 r9067  
    3838  </PropertyGroup>
    3939  <ItemGroup>
    40     <Reference Include="HeuristicLab.Algorithms.GeneticAlgorithm-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    41       <SpecificVersion>False</SpecificVersion>
    42       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Algorithms.GeneticAlgorithm-3.3.dll</HintPath>
    43     </Reference>
    4440    <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    4541      <SpecificVersion>False</SpecificVersion>
     
    6157      <SpecificVersion>False</SpecificVersion>
    6258      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Data-3.3.dll</HintPath>
     59    </Reference>
     60    <Reference Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     61      <SpecificVersion>False</SpecificVersion>
     62      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.dll</HintPath>
    6363    </Reference>
    6464    <Reference Include="HeuristicLab.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     
    101101    <Reference Include="System" />
    102102    <Reference Include="System.Core" />
     103    <Reference Include="System.Drawing" />
    103104    <Reference Include="System.Xml.Linq" />
    104105    <Reference Include="System.Data.DataSetExtensions" />
     
    110111    <Compile Include="Plugin.cs" />
    111112    <Compile Include="Properties\AssemblyInfo.cs" />
     113    <Compile Include="SymbolicDataAnalysisIslandGAEvaluator.cs" />
    112114    <Compile Include="SymbolicDataAnalysisIslandGeneticAlgorithm.cs" />
    113115  </ItemGroup>
     
    116118    <None Include="Plugin.cs.frame" />
    117119    <None Include="Properties\AssemblyInfo.cs.frame" />
     120  </ItemGroup>
     121  <ItemGroup>
     122    <ProjectReference Include="..\..\HeuristicLab.Algorithms.GeneticAlgorithm\3.3\HeuristicLab.Algorithms.GeneticAlgorithm-3.3.csproj">
     123      <Project>{a51da44f-cb35-4f6f-99f5-2a2e904ab93b}</Project>
     124      <Name>HeuristicLab.Algorithms.GeneticAlgorithm-3.3</Name>
     125    </ProjectReference>
    118126  </ItemGroup>
    119127  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/SymbolicDataAnalysisIslandGeneticAlgorithm.cs

    r9051 r9067  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using HeuristicLab.Algorithms.GeneticAlgorithm;
    25 using HeuristicLab.Analysis;
    2626using HeuristicLab.Common;
    2727using HeuristicLab.Core;
    2828using HeuristicLab.Data;
    29 using HeuristicLab.Operators;
    30 using HeuristicLab.Optimization;
    31 using HeuristicLab.Optimization.Operators;
    3229using HeuristicLab.Parameters;
    3330using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    34 using HeuristicLab.PluginInfrastructure;
    3531using HeuristicLab.Problems.DataAnalysis.Symbolic;
    36 using HeuristicLab.Random;
    3732
    3833namespace HeuristicLab.Algorithms.DataAnalysis.Symbolic {
     
    4035  [Creatable("Algorithms")]
    4136  [StorableClass]
    42   public sealed class SymbolicDataAnalysisIslandGeneticAlgorithm : HeuristicOptimizationEngineAlgorithm, IStorableContent {
    43     public string Filename { get; set; }
     37  public sealed class SymbolicDataAnalysisIslandGeneticAlgorithm : IslandGeneticAlgorithm {
     38    private const string FixedSamplesParameterName = "NumberOfFixedSamples";
     39    private const string FixedSamplesPartitionsParameterName = "FixedSamplesPartitions";
     40    private const string RandomSamplesParameterName = "NumberOfRandomSamples";
    4441
    4542    #region Problem Properties
     
    5350    #endregion
    5451
    55     #region Parameter Properties
    56     private ValueParameter<IntValue> SeedParameter {
    57       get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
     52    #region parameters
     53    public IFixedValueParameter<IntValue> FixedSamplesParameter {
     54      get { return (IFixedValueParameter<IntValue>)Parameters[FixedSamplesParameterName]; }
    5855    }
    59     private ValueParameter<BoolValue> SetSeedRandomlyParameter {
    60       get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
     56    public IValueParameter<ItemArray<IntRange>> FixedSamplesPartitionsParameter {
     57      get { return (IValueParameter<ItemArray<IntRange>>)Parameters[FixedSamplesPartitionsParameterName]; }
    6158    }
    62     private ValueParameter<IntValue> NumberOfIslandsParameter {
    63       get { return (ValueParameter<IntValue>)Parameters["NumberOfIslands"]; }
    64     }
    65     private ValueParameter<IntValue> MigrationIntervalParameter {
    66       get { return (ValueParameter<IntValue>)Parameters["MigrationInterval"]; }
    67     }
    68     private ValueParameter<PercentValue> MigrationRateParameter {
    69       get { return (ValueParameter<PercentValue>)Parameters["MigrationRate"]; }
    70     }
    71     public IConstrainedValueParameter<IMigrator> MigratorParameter {
    72       get { return (IConstrainedValueParameter<IMigrator>)Parameters["Migrator"]; }
    73     }
    74     public IConstrainedValueParameter<ISelector> EmigrantsSelectorParameter {
    75       get { return (IConstrainedValueParameter<ISelector>)Parameters["EmigrantsSelector"]; }
    76     }
    77     public IConstrainedValueParameter<IReplacer> ImmigrationReplacerParameter {
    78       get { return (IConstrainedValueParameter<IReplacer>)Parameters["ImmigrationReplacer"]; }
    79     }
    80     private ValueParameter<IntValue> PopulationSizeParameter {
    81       get { return (ValueParameter<IntValue>)Parameters["PopulationSize"]; }
    82     }
    83     private ValueParameter<IntValue> MaximumGenerationsParameter {
    84       get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
    85     }
    86     public IConstrainedValueParameter<ISelector> SelectorParameter {
    87       get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
    88     }
    89     public IConstrainedValueParameter<ICrossover> CrossoverParameter {
    90       get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
    91     }
    92     private ValueParameter<PercentValue> MutationProbabilityParameter {
    93       get { return (ValueParameter<PercentValue>)Parameters["MutationProbability"]; }
    94     }
    95     public IConstrainedValueParameter<IManipulator> MutatorParameter {
    96       get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
    97     }
    98     private ValueParameter<IntValue> ElitesParameter {
    99       get { return (ValueParameter<IntValue>)Parameters["Elites"]; }
    100     }
    101     private ValueParameter<MultiAnalyzer> AnalyzerParameter {
    102       get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
    103     }
    104     private ValueParameter<MultiAnalyzer> IslandAnalyzerParameter {
    105       get { return (ValueParameter<MultiAnalyzer>)Parameters["IslandAnalyzer"]; }
     59    public IFixedValueParameter<IntValue> RandomSamplesParameter {
     60      get { return (IFixedValueParameter<IntValue>)Parameters[RandomSamplesParameterName]; }
    10661    }
    10762    #endregion
    10863
    109     #region Properties
    110     public IntValue Seed {
    111       get { return SeedParameter.Value; }
    112       set { SeedParameter.Value = value; }
     64    #region properties
     65    public int FixedSamples {
     66      get { return FixedSamplesParameter.Value.Value; }
     67      set { FixedSamplesParameter.Value.Value = value; }
    11368    }
    114     public BoolValue SetSeedRandomly {
    115       get { return SetSeedRandomlyParameter.Value; }
    116       set { SetSeedRandomlyParameter.Value = value; }
     69    public ItemArray<IntRange> FixedSamplesPartitions {
     70      get { return FixedSamplesPartitionsParameter.Value; }
     71      set { FixedSamplesPartitionsParameter.Value = value; }
    11772    }
    118     public IntValue NumberOfIslands {
    119       get { return NumberOfIslandsParameter.Value; }
    120       set { NumberOfIslandsParameter.Value = value; }
     73    public int RandomSamples {
     74      get { return RandomSamplesParameter.Value.Value; }
     75      set { RandomSamplesParameter.Value.Value = value; }
    12176    }
    122     public IntValue MigrationInterval {
    123       get { return MigrationIntervalParameter.Value; }
    124       set { MigrationIntervalParameter.Value = value; }
    125     }
    126     public PercentValue MigrationRate {
    127       get { return MigrationRateParameter.Value; }
    128       set { MigrationRateParameter.Value = value; }
    129     }
    130     public IMigrator Migrator {
    131       get { return MigratorParameter.Value; }
    132       set { MigratorParameter.Value = value; }
    133     }
    134     public ISelector EmigrantsSelector {
    135       get { return EmigrantsSelectorParameter.Value; }
    136       set { EmigrantsSelectorParameter.Value = value; }
    137     }
    138     public IReplacer ImmigrationReplacer {
    139       get { return ImmigrationReplacerParameter.Value; }
    140       set { ImmigrationReplacerParameter.Value = value; }
    141     }
    142     public IntValue PopulationSize {
    143       get { return PopulationSizeParameter.Value; }
    144       set { PopulationSizeParameter.Value = value; }
    145     }
    146     public IntValue MaximumGenerations {
    147       get { return MaximumGenerationsParameter.Value; }
    148       set { MaximumGenerationsParameter.Value = value; }
    149     }
    150     public ISelector Selector {
    151       get { return SelectorParameter.Value; }
    152       set { SelectorParameter.Value = value; }
    153     }
    154     public ICrossover Crossover {
    155       get { return CrossoverParameter.Value; }
    156       set { CrossoverParameter.Value = value; }
    157     }
    158     public PercentValue MutationProbability {
    159       get { return MutationProbabilityParameter.Value; }
    160       set { MutationProbabilityParameter.Value = value; }
    161     }
    162     public IManipulator Mutator {
    163       get { return MutatorParameter.Value; }
    164       set { MutatorParameter.Value = value; }
    165     }
    166     public IntValue Elites {
    167       get { return ElitesParameter.Value; }
    168       set { ElitesParameter.Value = value; }
    169     }
    170     public MultiAnalyzer Analyzer {
    171       get { return AnalyzerParameter.Value; }
    172       set { AnalyzerParameter.Value = value; }
    173     }
    174     public MultiAnalyzer IslandAnalyzer {
    175       get { return IslandAnalyzerParameter.Value; }
    176       set { IslandAnalyzerParameter.Value = value; }
    177     }
    178     private RandomCreator RandomCreator {
    179       get { return (RandomCreator)OperatorGraph.InitialOperator; }
    180     }
    181     private UniformSubScopesProcessor IslandProcessor {
    182       get { return OperatorGraph.Iterate().OfType<UniformSubScopesProcessor>().First(x => x.Operator is SolutionsCreator); }
    183     }
    184     private SolutionsCreator SolutionsCreator {
    185       get { return (SolutionsCreator)IslandProcessor.Operator; }
    186     }
    187     private IslandGeneticAlgorithmMainLoop MainLoop {
    188       get { return FindMainLoop(IslandProcessor.Successor); }
    189     }
    190     [Storable]
    191     private BestAverageWorstQualityAnalyzer islandQualityAnalyzer;
    192     [Storable]
    193     private BestAverageWorstQualityAnalyzer qualityAnalyzer;
    19477    #endregion
    19578
     
    19881    [StorableHook(HookType.AfterDeserialization)]
    19982    private void AfterDeserialization() {
    200       Initialize();
     83      RegisterParameterEvents();
    20184    }
    20285    private SymbolicDataAnalysisIslandGeneticAlgorithm(SymbolicDataAnalysisIslandGeneticAlgorithm original, Cloner cloner)
    20386      : base(original, cloner) {
    204       islandQualityAnalyzer = cloner.Clone(original.islandQualityAnalyzer);
    205       qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
    206       Initialize();
     87      RegisterParameterEvents();
    20788    }
    20889    public override IDeepCloneable Clone(Cloner cloner) {
     
    21293    public SymbolicDataAnalysisIslandGeneticAlgorithm()
    21394      : base() {
    214       Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    215       Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
    216       Parameters.Add(new ValueParameter<IntValue>("NumberOfIslands", "The number of islands.", new IntValue(5)));
    217       Parameters.Add(new ValueParameter<IntValue>("MigrationInterval", "The number of generations that should pass between migration phases.", new IntValue(20)));
    218       Parameters.Add(new ValueParameter<PercentValue>("MigrationRate", "The proportion of individuals that should migrate between the islands.", new PercentValue(0.15)));
    219       Parameters.Add(new ConstrainedValueParameter<IMigrator>("Migrator", "The migration strategy."));
    220       Parameters.Add(new ConstrainedValueParameter<ISelector>("EmigrantsSelector", "Selects the individuals that will be migrated."));
    221       Parameters.Add(new ConstrainedValueParameter<IReplacer>("ImmigrationReplacer", "Selects the population from the unification of the original population and the immigrants."));
    222       Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
    223       Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations that should be processed.", new IntValue(1000)));
    224       Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
    225       Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
    226       Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
    227       Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
    228       Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
    229       Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the islands.", new MultiAnalyzer()));
    230       Parameters.Add(new ValueParameter<MultiAnalyzer>("IslandAnalyzer", "The operator used to analyze each island.", new MultiAnalyzer()));
     95      Parameters.Add(new FixedValueParameter<IntValue>(FixedSamplesParameterName, "The number of fixed samples used for fitness calculation in each island.", new IntValue(0)));
     96      Parameters.Add(new ValueParameter<ItemArray<IntRange>>(FixedSamplesPartitionsParameterName, "The fixed samples partitions used for fitness calculation for every island."));
     97      Parameters.Add(new FixedValueParameter<IntValue>(RandomSamplesParameterName, "The number of random samples used for fitness calculation in each island..", new IntValue(0)));
    23198
    232       RandomCreator randomCreator = new RandomCreator();
    233       UniformSubScopesProcessor ussp0 = new UniformSubScopesProcessor();
    234       LocalRandomCreator localRandomCreator = new LocalRandomCreator();
    235       RandomCreator globalRandomResetter = new RandomCreator();
    236       SubScopesCreator populationCreator = new SubScopesCreator();
    237       UniformSubScopesProcessor ussp1 = new UniformSubScopesProcessor();
    238       SolutionsCreator solutionsCreator = new SolutionsCreator();
    239       VariableCreator variableCreator = new VariableCreator();
    240       UniformSubScopesProcessor ussp2 = new UniformSubScopesProcessor();
    241       SubScopesCounter subScopesCounter = new SubScopesCounter();
    242       ResultsCollector resultsCollector = new ResultsCollector();
    243       IslandGeneticAlgorithmMainLoop mainLoop = new IslandGeneticAlgorithmMainLoop();
    244       OperatorGraph.InitialOperator = randomCreator;
    245 
    246       randomCreator.RandomParameter.ActualName = "GlobalRandom";
    247       randomCreator.SeedParameter.ActualName = SeedParameter.Name;
    248       randomCreator.SeedParameter.Value = null;
    249       randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
    250       randomCreator.SetSeedRandomlyParameter.Value = null;
    251       randomCreator.Successor = populationCreator;
    252 
    253       populationCreator.NumberOfSubScopesParameter.ActualName = NumberOfIslandsParameter.Name;
    254       populationCreator.Successor = ussp0;
    255 
    256       ussp0.Operator = localRandomCreator;
    257       ussp0.Successor = globalRandomResetter;
    258 
    259       // BackwardsCompatibility3.3
    260       // the global random is resetted to ensure the same algorithm results
    261       #region Backwards compatible code, remove with 3.4
    262       globalRandomResetter.RandomParameter.ActualName = "GlobalRandom";
    263       globalRandomResetter.SeedParameter.ActualName = SeedParameter.Name;
    264       globalRandomResetter.SeedParameter.Value = null;
    265       globalRandomResetter.SetSeedRandomlyParameter.Value = new BoolValue(false);
    266       globalRandomResetter.Successor = ussp1;
    267       #endregion
    268 
    269       ussp1.Operator = solutionsCreator;
    270       ussp1.Successor = variableCreator;
    271 
    272       solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
    273       //don't create solutions in parallel because the hive engine would distribute these tasks
    274       solutionsCreator.ParallelParameter.Value = new BoolValue(false);
    275       solutionsCreator.Successor = null;
    276 
    277       variableCreator.Name = "Initialize EvaluatedSolutions";
    278       variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue()));
    279       variableCreator.Successor = ussp2;
    280 
    281       ussp2.Operator = subScopesCounter;
    282       ussp2.Successor = resultsCollector;
    283 
    284       subScopesCounter.Name = "Count EvaluatedSolutions";
    285       subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
    286       subScopesCounter.Successor = null;
    287 
    288       resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
    289       resultsCollector.ResultsParameter.ActualName = "Results";
    290       resultsCollector.Successor = mainLoop;
    291 
    292       mainLoop.EmigrantsSelectorParameter.ActualName = EmigrantsSelectorParameter.Name;
    293       mainLoop.ImmigrationReplacerParameter.ActualName = ImmigrationReplacerParameter.Name;
    294       mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
    295       mainLoop.MigrationIntervalParameter.ActualName = MigrationIntervalParameter.Name;
    296       mainLoop.MigrationRateParameter.ActualName = MigrationRateParameter.Name;
    297       mainLoop.MigratorParameter.ActualName = MigratorParameter.Name;
    298       mainLoop.NumberOfIslandsParameter.ActualName = NumberOfIslandsParameter.Name;
    299       mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
    300       mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
    301       mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
    302       mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
    303       mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
    304       mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
    305       mainLoop.ResultsParameter.ActualName = "Results";
    306       mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
    307       mainLoop.IslandAnalyzerParameter.ActualName = IslandAnalyzerParameter.Name;
    308       mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
    309       mainLoop.Successor = null;
    310 
    311       foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
    312         SelectorParameter.ValidValues.Add(selector);
    313       ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
    314       if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
    315 
    316       foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
    317         EmigrantsSelectorParameter.ValidValues.Add(selector);
    318 
    319       foreach (IReplacer replacer in ApplicationManager.Manager.GetInstances<IReplacer>().OrderBy(x => x.Name))
    320         ImmigrationReplacerParameter.ValidValues.Add(replacer);
    321 
    322       ParameterizeSelectors();
    323 
    324       foreach (IMigrator migrator in ApplicationManager.Manager.GetInstances<IMigrator>().OrderBy(x => x.Name))
    325         MigratorParameter.ValidValues.Add(migrator);
    326 
    327       qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
    328       islandQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
    329       ParameterizeAnalyzers();
    330       UpdateAnalyzers();
    331 
    332       Initialize();
     99      RegisterParameterEvents();
     100      RecalculateFixedSamplesPartitions();
    333101    }
    334102
    335     public override void Prepare() {
    336       if (Problem != null) base.Prepare();
     103    private void RegisterParameterEvents() {
     104      NumberOfIslandsParameter.ValueChanged += NumberOfIslandsParameter_ValueChanged;
     105      NumberOfIslandsParameter.Value.ValueChanged += (o, ev) => RecalculateFixedSamplesPartitions();
     106      FixedSamplesParameter.Value.ValueChanged += (o, e) => RecalculateFixedSamplesPartitions();
    337107    }
    338108
    339     #region Events
    340     protected override void OnProblemChanged() {
    341       ParameterizeStochasticOperator(Problem.SolutionCreator);
    342       ParameterizeStochasticOperatorForIsland(Problem.Evaluator);
    343       foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
    344       ParameterizeSolutionsCreator();
    345       ParameterizeMainLoop();
    346       ParameterizeSelectors();
    347       ParameterizeAnalyzers();
    348       ParameterizeIterationBasedOperators();
    349       UpdateCrossovers();
    350       UpdateMutators();
    351       UpdateAnalyzers();
    352       Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    353       base.OnProblemChanged();
     109    private void NumberOfIslandsParameter_ValueChanged(object sender, EventArgs e) {
     110      NumberOfIslands.ValueChanged += (o, ev) => RecalculateFixedSamplesPartitions();
     111      RecalculateFixedSamplesPartitions();
    354112    }
    355113
    356     protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
    357       ParameterizeStochasticOperator(Problem.SolutionCreator);
    358       ParameterizeSolutionsCreator();
    359       base.Problem_SolutionCreatorChanged(sender, e);
     114    protected override void Problem_Reset(object sender, EventArgs e) {
     115      RecalculateFixedSamplesPartitions();
     116      base.Problem_Reset(sender, e);
    360117    }
    361     protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
    362       ParameterizeStochasticOperatorForIsland(Problem.Evaluator);
    363       ParameterizeSolutionsCreator();
    364       ParameterizeMainLoop();
    365       ParameterizeSelectors();
    366       ParameterizeAnalyzers();
    367       Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    368       base.Problem_EvaluatorChanged(sender, e);
     118
     119    protected override void OnProblemChanged() {
     120      base.OnProblemChanged();
     121      Problem.FitnessCalculationPartition.ValueChanged += (o, e) => RecalculateFixedSamplesPartitions();
     122      RecalculateFixedSamplesPartitions();
    369123    }
    370     protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
    371       foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
    372       ParameterizeIterationBasedOperators();
    373       UpdateCrossovers();
    374       UpdateMutators();
    375       UpdateAnalyzers();
    376       base.Problem_OperatorsChanged(sender, e);
     124
     125    private void RecalculateFixedSamplesPartitions() {
     126      if (Problem == null) {
     127        FixedSamplesPartitions = new ItemArray<IntRange>(Enumerable.Repeat(new IntRange(), NumberOfIslands.Value));
     128        return;
     129      }
     130      var samplesStart = Problem.FitnessCalculationPartition.Start;
     131      var samplesEnd = Problem.FitnessCalculationPartition.End;
     132      var totalSamples = Problem.FitnessCalculationPartition.Size;
     133      var fixedSamples = FixedSamples;
     134      var islands = NumberOfIslands.Value;
     135
     136      int offset = 0;
     137      //fixed samples partition do not overlap
     138      if (((double)totalSamples) / fixedSamples <= islands) {
     139        offset = totalSamples / islands;
     140      } else {
     141        offset = (totalSamples - fixedSamples) / (islands - 1);
     142      }
     143
     144      List<IntRange> partitions = new List<IntRange>();
     145      for (int i = 0; i < islands; i++) {
     146        var partitionStart = samplesStart + offset * i;
     147        partitions.Add(new IntRange(partitionStart, partitionStart + fixedSamples));
     148      }
     149
     150      //it can be the case that the last partitions exceeds the allowed samples
     151      //move the last partition forward.
     152      int exceedsSamples = partitions[partitions.Count - 1].End - samplesEnd;
     153      if (exceedsSamples > 0) {
     154        partitions[partitions.Count - 1].Start -= exceedsSamples;
     155        partitions[partitions.Count - 1].End -= exceedsSamples;
     156      }
     157      FixedSamplesPartitions = new ItemArray<IntRange>(partitions);
    377158    }
    378     private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
    379       Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
    380       ParameterizeSelectors();
    381     }
    382     private void Elites_ValueChanged(object sender, EventArgs e) {
    383       ParameterizeSelectors();
    384     }
    385     private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
    386       NumberOfIslands.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
    387       ParameterizeSelectors();
    388     }
    389     private void PopulationSize_ValueChanged(object sender, EventArgs e) {
    390       ParameterizeSelectors();
    391     }
    392     private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    393       ParameterizeMainLoop();
    394       ParameterizeSelectors();
    395       ParameterizeAnalyzers();
    396     }
    397     private void MigrationRateParameter_ValueChanged(object sender, EventArgs e) {
    398       MigrationRate.ValueChanged += new EventHandler(MigrationRate_ValueChanged);
    399       ParameterizeSelectors();
    400     }
    401     private void MigrationRate_ValueChanged(object sender, EventArgs e) {
    402       ParameterizeSelectors();
    403     }
    404     #endregion
    405159
    406     #region Helpers
    407     private void Initialize() {
    408       PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
    409       PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
    410       MigrationRateParameter.ValueChanged += new EventHandler(MigrationRateParameter_ValueChanged);
    411       MigrationRate.ValueChanged += new EventHandler(MigrationRate_ValueChanged);
    412       ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
    413       Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
    414       if (Problem != null) {
    415         Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    416       }
    417     }
    418     private void ParameterizeSolutionsCreator() {
    419       SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
    420       SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
    421     }
    422     private void ParameterizeMainLoop() {
    423       MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
    424       MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
    425       MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    426       MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    427     }
    428     private void ParameterizeStochasticOperator(IOperator op) {
    429       IStochasticOperator stochasticOp = op as IStochasticOperator;
    430       if (stochasticOp != null) {
    431         stochasticOp.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
    432         stochasticOp.RandomParameter.Hidden = true;
    433       }
    434     }
    435     private void ParameterizeStochasticOperatorForIsland(IOperator op) {
    436       IStochasticOperator stochasticOp = op as IStochasticOperator;
    437       if (stochasticOp != null) {
    438         stochasticOp.RandomParameter.ActualName = "LocalRandom";
    439         stochasticOp.RandomParameter.Hidden = true;
    440       }
    441     }
    442     private void ParameterizeSelectors() {
    443       foreach (ISelector selector in SelectorParameter.ValidValues) {
    444         selector.CopySelected = new BoolValue(true);
    445         selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(2 * (PopulationSize.Value - Elites.Value));
    446         selector.NumberOfSelectedSubScopesParameter.Hidden = true;
    447         ParameterizeStochasticOperatorForIsland(selector);
    448       }
    449       foreach (ISelector selector in EmigrantsSelectorParameter.ValidValues) {
    450         selector.CopySelected = new BoolValue(true);
    451         selector.NumberOfSelectedSubScopesParameter.Value = new IntValue((int)Math.Ceiling(PopulationSize.Value * MigrationRate.Value));
    452         selector.NumberOfSelectedSubScopesParameter.Hidden = true;
    453         ParameterizeStochasticOperator(selector);
    454       }
    455       foreach (IReplacer replacer in ImmigrationReplacerParameter.ValidValues) {
    456         ParameterizeStochasticOperator(replacer);
    457       }
    458       if (Problem != null) {
    459         foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
    460           selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    461           selector.MaximizationParameter.Hidden = true;
    462           selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    463           selector.QualityParameter.Hidden = true;
    464         }
    465         foreach (ISingleObjectiveSelector selector in EmigrantsSelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
    466           selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    467           selector.MaximizationParameter.Hidden = true;
    468           selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    469           selector.QualityParameter.Hidden = true;
    470         }
    471         foreach (ISingleObjectiveReplacer selector in ImmigrationReplacerParameter.ValidValues.OfType<ISingleObjectiveReplacer>()) {
    472           selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    473           selector.MaximizationParameter.Hidden = true;
    474           selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    475           selector.QualityParameter.Hidden = true;
    476         }
    477       }
    478     }
    479     private void ParameterizeAnalyzers() {
    480       islandQualityAnalyzer.ResultsParameter.ActualName = "Results";
    481       islandQualityAnalyzer.ResultsParameter.Hidden = true;
    482       islandQualityAnalyzer.QualityParameter.Depth = 1;
    483       qualityAnalyzer.ResultsParameter.ActualName = "Results";
    484       qualityAnalyzer.ResultsParameter.Hidden = true;
    485       qualityAnalyzer.QualityParameter.Depth = 2;
    486 
    487       if (Problem != null) {
    488         islandQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    489         islandQualityAnalyzer.MaximizationParameter.Hidden = true;
    490         islandQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    491         islandQualityAnalyzer.QualityParameter.Hidden = true;
    492         islandQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
    493         islandQualityAnalyzer.BestKnownQualityParameter.Hidden = true;
    494         qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    495         qualityAnalyzer.MaximizationParameter.Hidden = true;
    496         qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    497         qualityAnalyzer.QualityParameter.Hidden = true;
    498         qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
    499         qualityAnalyzer.BestKnownQualityParameter.Hidden = true;
    500       }
    501     }
    502     private void ParameterizeIterationBasedOperators() {
    503       if (Problem != null) {
    504         foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
    505           op.IterationsParameter.ActualName = "Generations";
    506           op.IterationsParameter.Hidden = true;
    507           op.MaximumIterationsParameter.ActualName = "MaximumGenerations";
    508           op.MaximumIterationsParameter.Hidden = true;
    509         }
    510       }
    511     }
    512     private void UpdateCrossovers() {
    513       ICrossover oldCrossover = CrossoverParameter.Value;
    514       ICrossover defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
    515       CrossoverParameter.ValidValues.Clear();
    516       foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name)) {
    517         ParameterizeStochasticOperatorForIsland(crossover);
    518         CrossoverParameter.ValidValues.Add(crossover);
    519       }
    520       if (oldCrossover != null) {
    521         ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
    522         if (crossover != null) CrossoverParameter.Value = crossover;
    523         else oldCrossover = null;
    524       }
    525       if (oldCrossover == null && defaultCrossover != null)
    526         CrossoverParameter.Value = defaultCrossover;
    527     }
    528     private void UpdateMutators() {
    529       IManipulator oldMutator = MutatorParameter.Value;
    530       MutatorParameter.ValidValues.Clear();
    531       foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name)) {
    532         ParameterizeStochasticOperatorForIsland(mutator);
    533         MutatorParameter.ValidValues.Add(mutator);
    534       }
    535       if (oldMutator != null) {
    536         IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
    537         if (mutator != null) MutatorParameter.Value = mutator;
    538       }
    539     }
    540     private void UpdateAnalyzers() {
    541       IslandAnalyzer.Operators.Clear();
    542       Analyzer.Operators.Clear();
    543       IslandAnalyzer.Operators.Add(islandQualityAnalyzer, islandQualityAnalyzer.EnabledByDefault);
    544       if (Problem != null) {
    545         foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
    546           foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
    547             param.Depth = 2;
    548           Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
    549         }
    550       }
    551       Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
    552     }
    553     private IslandGeneticAlgorithmMainLoop FindMainLoop(IOperator start) {
    554       IOperator mainLoop = start;
    555       while (mainLoop != null && !(mainLoop is IslandGeneticAlgorithmMainLoop))
    556         mainLoop = ((SingleSuccessorOperator)mainLoop).Successor;
    557       if (mainLoop == null) return null;
    558       else return (IslandGeneticAlgorithmMainLoop)mainLoop;
    559     }
    560     #endregion
    561160  }
    562161}
Note: See TracChangeset for help on using the changeset viewer.