Changeset 3379


Ignore:
Timestamp:
04/17/10 03:05:50 (11 years ago)
Author:
abeham
Message:

Added first working version of offspring selection GA #976
Had to implement a new parameter type (better solution!?)
Updated engine files (they're still throwing exceptions upon load though).
Fixed bug in OffspringSelector

Location:
trunk/sources
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab 3.3.sln

    r3378 r3379  
    12351235    {125D3006-67F5-48CB-913E-73C0548F17FA}.Services|x86.ActiveCfg = Release|x86
    12361236    {F5C0ECAC-EDBA-4024-872A-1F74AFCB20B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    1237     {F5C0ECAC-EDBA-4024-872A-1F74AFCB20B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
    12381237    {F5C0ECAC-EDBA-4024-872A-1F74AFCB20B4}.Debug|x64.ActiveCfg = Debug|x64
    12391238    {F5C0ECAC-EDBA-4024-872A-1F74AFCB20B4}.Debug|x64.Build.0 = Debug|x64
     
    12501249    {F5C0ECAC-EDBA-4024-872A-1F74AFCB20B4}.Services|x86.ActiveCfg = Release|x86
    12511250    {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    1252     {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Debug|Any CPU.Build.0 = Debug|Any CPU
    12531251    {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Debug|x64.ActiveCfg = Debug|x64
    12541252    {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Debug|x64.Build.0 = Debug|x64
  • trunk/sources/HeuristicLab 3.3/Files.txt

    r3373 r3379  
    88HeuristicLab.Algorithms.LocalSearch\3.3:HeuristicLab.Algorithms.LocalSearch-3.3.dll
    99HeuristicLab.Algorithms.MultipopulationAlgorithm\3.3:HeuristicLab.Algorithms.MultipopulationAlgorithm-3.3.dll
     10HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm\3.3:HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm-3.3.dll
    1011HeuristicLab.Algorithms.ParticleSwarmOptimization\3.3:HeuristicLab.Algorithms.ParticleSwarmOptimization-3.3.dll
    1112HeuristicLab.Algorithms.SimulatedAnnealing\3.3:HeuristicLab.Algorithms.SimulatedAnnealing-3.3.dll
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs

    r3378 r3379  
    3838  /// An offspring selection genetic algorithm.
    3939  /// </summary>
    40   [Item("Offspring Selection Genetic Algorithm", "An offspring selection genetic algorithm (Affenzeller, M. and Wagner, S. 2005. Offspring Selection: A New Self-Adaptive Selection Scheme for Genetic Algorithms. Adaptive and Natural Computing Algorithms, pp. 218-221, Springer).")]
     40  [Item("Offspring Selection Genetic Algorithm", "An offspring selection genetic algorithm (Affenzeller, M. et al. 2009. Genetic Algorithms and Genetic Programming - Modern Concepts and Practical Applications. CRC Press).")]
    4141  [Creatable("Algorithms")]
    4242  [StorableClass]
     
    8080      get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
    8181    }
     82    private ValueLookupParameter<DoubleValue> SuccessRatioParameter {
     83      get { return (ValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; }
     84    }
     85    private ValueLookupParameter<DoubleValue> ComparisonFactorLowerBoundParameter {
     86      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorLowerBound"]; }
     87    }
     88    private ValueLookupParameter<DoubleValue> ComparisonFactorUpperBoundParameter {
     89      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorUpperBound"]; }
     90    }
     91    private ConstrainedValueParameter<IDiscreteDoubleValueModifier> ComparisonFactorModifierParameter {
     92      get { return (ConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; }
     93    }
     94    private ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
     95      get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
     96    }
     97    private ValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
     98      get { return (ValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; }
     99    }
    82100    #endregion
    83101
     
    119137      set { MaximumGenerationsParameter.Value = value; }
    120138    }
     139    private DoubleValue SuccessRatio {
     140      get { return SuccessRatioParameter.Value; }
     141      set { SuccessRatioParameter.Value = value; }
     142    }
     143    private DoubleValue ComparisonFactorLowerBound {
     144      get { return ComparisonFactorLowerBoundParameter.Value; }
     145      set { ComparisonFactorLowerBoundParameter.Value = value; }
     146    }
     147    private DoubleValue ComparisonFactorUpperBound {
     148      get { return ComparisonFactorUpperBoundParameter.Value; }
     149      set { ComparisonFactorUpperBoundParameter.Value = value; }
     150    }
     151    private IDiscreteDoubleValueModifier ComparisonFactorModifier {
     152      get { return ComparisonFactorModifierParameter.Value; }
     153      set { ComparisonFactorModifierParameter.Value = value; }
     154    }
     155    private DoubleValue MaximumSelectionPressure {
     156      get { return MaximumSelectionPressureParameter.Value; }
     157      set { MaximumSelectionPressureParameter.Value = value; }
     158    }
     159    private BoolValue OffspringSelectionBeforeMutation {
     160      get { return OffspringSelectionBeforeMutationParameter.Value; }
     161      set { OffspringSelectionBeforeMutationParameter.Value = value; }
     162    }
    121163    private RandomCreator RandomCreator {
    122164      get { return (RandomCreator)OperatorGraph.InitialOperator; }
     
    132174      get { return selectors; }
    133175    }
     176    private List<IDiscreteDoubleValueModifier> comparisonFactorModifiers;
    134177    #endregion
    135178
     179    [StorableConstructor]
     180    private OffspringSelectionGeneticAlgorithm(bool deserializing) : base(deserializing) { }
    136181    public OffspringSelectionGeneticAlgorithm()
    137182      : base() {
     
    145190      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
    146191      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
     192      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
     193      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0)));
     194      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(1)));
     195      Parameters.Add(new ConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor."));
     196      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
     197      Parameters.Add(new ValueLookupParameter<BoolValue>("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation.", new BoolValue(false)));
    147198
    148199      RandomCreator randomCreator = new RandomCreator();
     
    161212      solutionsCreator.Successor = mainLoop;
    162213
     214      mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
    163215      mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
    164216      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
     
    172224      Initialize();
    173225    }
    174     [StorableConstructor]
    175     private OffspringSelectionGeneticAlgorithm(bool deserializing) : base(deserializing) { }
    176226
    177227    public override IDeepCloneable Clone(Cloner cloner) {
     
    192242      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
    193243      ParameterizeSolutionsCreator();
    194       ParameterizeGeneticAlgorithmMainLoop();
     244      ParameterizMainLoop();
    195245      ParameterizeSelectors();
    196246      UpdateCrossovers();
     
    209259      ParameterizeStochasticOperator(Problem.Evaluator);
    210260      ParameterizeSolutionsCreator();
    211       ParameterizeGeneticAlgorithmMainLoop();
     261      ParameterizMainLoop();
    212262      ParameterizeSelectors();
    213263      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
     
    216266    protected override void Problem_VisualizerChanged(object sender, EventArgs e) {
    217267      ParameterizeStochasticOperator(Problem.Visualizer);
    218       ParameterizeGeneticAlgorithmMainLoop();
     268      ParameterizMainLoop();
    219269      if (Problem.Visualizer != null) Problem.Visualizer.VisualizationParameter.ActualNameChanged += new EventHandler(Visualizer_VisualizationParameter_ActualNameChanged);
    220270      base.Problem_VisualizerChanged(sender, e);
     
    235285    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
    236286      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
     287      MainLoop.PopulationSizeParameter.Value = new IntValue(PopulationSize.Value - Elites.Value);
    237288      ParameterizeSelectors();
    238289    }
    239290    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
     291      MainLoop.PopulationSizeParameter.Value = new IntValue(PopulationSize.Value - Elites.Value);
    240292      ParameterizeSelectors();
    241293    }
    242294    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    243       ParameterizeGeneticAlgorithmMainLoop();
     295      ParameterizMainLoop();
    244296      ParameterizeSelectors();
    245297    }
    246298    private void Visualizer_VisualizationParameter_ActualNameChanged(object sender, EventArgs e) {
    247       ParameterizeGeneticAlgorithmMainLoop();
     299      ParameterizMainLoop();
    248300    }
    249301    #endregion
     
    254306      InitializeSelectors();
    255307      UpdateSelectors();
     308      InitializeComparisonFactorModifiers();
     309      UpdateComparisonFactorModifiers();
    256310      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
    257311      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
     
    270324      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
    271325    }
    272     private void ParameterizeGeneticAlgorithmMainLoop() {
     326    private void ParameterizMainLoop() {
    273327      MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
    274328      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
     
    288342      ParameterizeSelectors();
    289343    }
     344    private void InitializeComparisonFactorModifiers() {
     345      comparisonFactorModifiers = new List<IDiscreteDoubleValueModifier>();
     346      comparisonFactorModifiers.AddRange(ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name));
     347      ParameterizeComparisonFactorModifiers();
     348    }
    290349    private void ParameterizeSelectors() {
    291350      foreach (ISelector selector in Selectors) {
     
    301360      }
    302361    }
     362    private void ParameterizeComparisonFactorModifiers() {
     363      foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers) {
     364        modifier.IndexParameter.ActualName = "Generations"; // FIXME: hmmm, not so good, this variable is defined within the main loop
     365        modifier.EndIndexParameter.ActualName = MaximumGenerationsParameter.Name;
     366        modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
     367        modifier.StartIndexParameter.Value = new IntValue(0);
     368        modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
     369        modifier.ValueParameter.ActualName = "ComparisonFactor"; // FIXME: hmmm, not so good, this variable is defined within the main loop
     370      }
     371    }
    303372    private void UpdateSelectors() {
    304373      ISelector oldSelector = SelectorParameter.Value;
     
    314383        if (selector != null) SelectorParameter.Value = selector;
    315384      }
     385    }
     386    private void UpdateComparisonFactorModifiers() {
     387      IDiscreteDoubleValueModifier oldModifier = ComparisonFactorModifier;
     388      ComparisonFactorModifierParameter.ValidValues.Clear();
     389      foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers)
     390        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
     391      if (oldModifier != null) {
     392        IDiscreteDoubleValueModifier modifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldModifier.GetType());
     393        if (modifier != null) ComparisonFactorModifierParameter.Value = modifier;
     394      } else if (ComparisonFactorModifierParameter.ValidValues.Count > 0) ComparisonFactorModifierParameter.Value = ComparisonFactorModifierParameter.ValidValues.First();
    316395    }
    317396    private void UpdateCrossovers() {
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithmMainLoop.cs

    r3378 r3379  
    181181
    182182      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0)));
     183      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("SelectionPressure", new DoubleValue(0)));
    183184      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("CurrentSuccessRatio", new DoubleValue(0)));
    184185
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/OffspringSelector.cs

    r3378 r3379  
    3838    }
    3939    public ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
    40       get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximiumSelectionPressure"]; }
     40      get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
    4141    }
    4242    public ValueLookupParameter<DoubleValue> SuccessRatioParameter {
     
    4949      get { return (LookupParameter<DoubleValue>)Parameters["CurrentSuccessRatio"]; }
    5050    }
    51     public SubScopesLookupParameter<BoolValue> SuccessfulOffspringParameter {
    52       get { return (SubScopesLookupParameter<BoolValue>)Parameters["SuccessfulOffspring"]; }
     51    public SelectedSubScopesLookupParameter<BoolValue> SuccessfulOffspringParameter {
     52      get { return (SelectedSubScopesLookupParameter<BoolValue>)Parameters["SuccessfulOffspring"]; }
    5353    }
    5454    public LookupParameter<ItemList<IScope>> WinnersParameter {
     
    7474      Parameters.Add(new ValueLookupParameter<DoubleValue>("SelectionPressure", "The amount of selection pressure currently necessary to fulfill the success ratio."));
    7575      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentSuccessRatio", "The current success ratio indicates how much of the successful offspring have already been generated."));
    76       Parameters.Add(new SubScopesLookupParameter<BoolValue>("SuccessfulOffspring", "True if the offspring was successful, otherwise false."));
     76      Parameters.Add(new SelectedSubScopesLookupParameter<BoolValue>("SuccessfulOffspring", "True if the offspring was successful, otherwise false."));
    7777      Parameters.Add(new LookupParameter<ItemList<IScope>>("Winners", "Temporary store of the successful offspring."));
    7878      Parameters.Add(new LookupParameter<ItemList<IScope>>("LuckyLosers", "Temporary store of the lucky losers."));
     
    145145        scope.SubScopes.Remove(parents);
    146146        scope.SubScopes.Remove(children);
    147         for (int i = 0; i < parents.SubScopes.Count; i++)
    148           scope.SubScopes.Add(parents.SubScopes[i]);
     147        while(parents.SubScopes.Count > 0)
     148          scope.SubScopes.Add(parents.SubScopes[0]);
    149149
    150150        IOperator moreOffspring = OffspringCreatorParameter.ActualValue as IOperator;
  • trunk/sources/HeuristicLab.Parameters/3.3/HeuristicLab.Parameters-3.3.csproj

    r3106 r3379  
    8686    <None Include="HeuristicLabParametersPlugin.cs.frame" />
    8787    <Compile Include="ConstrainedValueParameter.cs" />
     88    <Compile Include="SelectedSubScopesLookupParameter.cs" />
    8889    <Compile Include="OptionalConstrainedValueParameter.cs" />
    8990    <Compile Include="ValueParameter.cs" />
Note: See TracChangeset for help on using the changeset viewer.