Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3479


Ignore:
Timestamp:
04/21/10 22:05:40 (14 years ago)
Author:
abeham
Message:

added first draft of SASEGASA #839

Location:
trunk/sources
Files:
2 added
7 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm-3.3.csproj

    r3429 r3479  
    8080  </ItemGroup>
    8181  <ItemGroup>
     82    <Compile Include="SASEGASA.cs" />
     83    <Compile Include="SASEGASAMainLoop.cs" />
    8284    <Compile Include="HeuristicLabAlgorithmsOffspringSelectionGeneticAlgorithmPlugin.cs" />
    83     <Compile Include="OffspringSelectionIslandGeneticAlgorithm.cs" />
    84     <Compile Include="OffspringSelectionIslandGeneticAlgorithmMainLoop.cs" />
     85    <Compile Include="IslandOffspringSelectionGeneticAlgorithm.cs" />
     86    <Compile Include="IslandOffspringSelectionGeneticAlgorithmMainLoop.cs" />
    8587    <Compile Include="OffspringSelectionGeneticAlgorithm.cs" />
    8688    <Compile Include="OffspringSelectionGeneticAlgorithmMainLoop.cs" />
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/IslandOffspringSelectionGeneticAlgorithm.cs

    r3450 r3479  
    3939  /// An offspring selection island genetic algorithm.
    4040  /// </summary>
    41   [Item("Offspring Selection Island Genetic Algorithm", "An offspring selection island genetic algorithm.")]
     41  [Item("Island Offspring Selection Genetic Algorithm", "An island offspring selection genetic algorithm.")]
    4242  [Creatable("Algorithms")]
    4343  [StorableClass]
    44   public sealed class OffspringSelectionIslandGeneticAlgorithm : EngineAlgorithm {
     44  public sealed class IslandOffspringSelectionGeneticAlgorithm : EngineAlgorithm {
    4545
    4646    #region Problem Properties
     
    229229      get { return (SolutionsCreator)IslandProcessor.Operator; }
    230230    }
    231     private OffspringSelectionIslandGeneticAlgorithmMainLoop MainLoop {
    232       get { return (OffspringSelectionIslandGeneticAlgorithmMainLoop)IslandProcessor.Successor; }
     231    private IslandOffspringSelectionGeneticAlgorithmMainLoop MainLoop {
     232      get { return (IslandOffspringSelectionGeneticAlgorithmMainLoop)IslandProcessor.Successor; }
    233233    }
    234234    #endregion
    235235
    236236    [StorableConstructor]
    237     private OffspringSelectionIslandGeneticAlgorithm(bool deserializing) : base(deserializing) { }
    238     public OffspringSelectionIslandGeneticAlgorithm()
     237    private IslandOffspringSelectionGeneticAlgorithm(bool deserializing) : base(deserializing) { }
     238    public IslandOffspringSelectionGeneticAlgorithm()
    239239      : base() {
    240240      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
     
    246246      Parameters.Add(new ConstrainedValueParameter<ISelector>("EmigrantsSelector", "Selects the individuals that will be migrated."));
    247247      Parameters.Add(new ConstrainedValueParameter<ISelector>("ImmigrationSelector", "Selects the population from the unification of the original population and the immigrants."));
    248       Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
     248      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions of each island.", new IntValue(100)));
    249249      Parameters.Add(new ValueParameter<IntValue>("MaximumMigrations", "The maximum number of migrations that should occur.", new IntValue(100)));
    250250      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
     
    265265      UniformSubScopesProcessor ussp1 = new UniformSubScopesProcessor();
    266266      SolutionsCreator solutionsCreator = new SolutionsCreator();
    267       OffspringSelectionIslandGeneticAlgorithmMainLoop mainLoop = new OffspringSelectionIslandGeneticAlgorithmMainLoop();
     267      IslandOffspringSelectionGeneticAlgorithmMainLoop mainLoop = new IslandOffspringSelectionGeneticAlgorithmMainLoop();
    268268      OperatorGraph.InitialOperator = randomCreator;
    269269
     
    313313
    314314    public override IDeepCloneable Clone(Cloner cloner) {
    315       OffspringSelectionIslandGeneticAlgorithm clone = (OffspringSelectionIslandGeneticAlgorithm)base.Clone(cloner);
     315      IslandOffspringSelectionGeneticAlgorithm clone = (IslandOffspringSelectionGeneticAlgorithm)base.Clone(cloner);
    316316      clone.Initialize();
    317317      return clone;
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/IslandOffspringSelectionGeneticAlgorithmMainLoop.cs

    r3450 r3479  
    3737namespace HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm {
    3838  /// <summary>
    39   /// An offspring selection island genetic algorithm main loop operator.
     39  /// An island offspring selection genetic algorithm main loop operator.
    4040  /// </summary>
    41   [Item("OffspringSelectionIslandGeneticAlgorithmMainLoop", "An offspring selection island genetic algorithm main loop operator.")]
     41  [Item("IslandOffspringSelectionGeneticAlgorithmMainLoop", "An island offspring selection genetic algorithm main loop operator.")]
    4242  [StorableClass]
    43   public sealed class OffspringSelectionIslandGeneticAlgorithmMainLoop : AlgorithmOperator {
     43  public sealed class IslandOffspringSelectionGeneticAlgorithmMainLoop : AlgorithmOperator {
    4444    #region Parameter Properties
    4545    public ValueLookupParameter<IRandom> RandomParameter {
     
    127127
    128128    [StorableConstructor]
    129     private OffspringSelectionIslandGeneticAlgorithmMainLoop(bool deserializing) : base() { }
    130     public OffspringSelectionIslandGeneticAlgorithmMainLoop()
     129    private IslandOffspringSelectionGeneticAlgorithmMainLoop(bool deserializing) : base() { }
     130    public IslandOffspringSelectionGeneticAlgorithmMainLoop()
    131131      : base() {
    132132      #region Create parameters
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs

    r3426 r3479  
    212212      solutionsCreator.Successor = mainLoop;
    213213
    214       mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
    215214      mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
    216215      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
     
    285284    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
    286285      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
    287       MainLoop.PopulationSizeParameter.Value = new IntValue(PopulationSize.Value - Elites.Value);
    288286      ParameterizeSelectors();
    289287    }
    290288    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
    291       MainLoop.PopulationSizeParameter.Value = new IntValue(PopulationSize.Value - Elites.Value);
    292289      ParameterizeSelectors();
    293290    }
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithmMainLoop.cs

    r3446 r3479  
    4343      get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
    4444    }
    45     public ValueLookupParameter<IntValue> PopulationSizeParameter {
    46       get { return (ValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }
    47     }
    4845    public SubScopesLookupParameter<DoubleValue> QualityParameter {
    4946      get { return (SubScopesLookupParameter<DoubleValue>)Parameters["Quality"]; }
     
    113110      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
    114111      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
    115       Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population."));
    116112      Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
    117113      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
     
    189185      initializationBranch.ConditionParameter.ActualName = "IsInitialized";
    190186
    191       variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0)));
     187      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // this variable is referenced in SASEGASAMainLoop, do not change!
    192188      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue(0)));
    193189      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("SelectionPressure", new DoubleValue(0)));
     
    196192      variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("IsInitialized", new BoolValue(true)));
    197193
    198       variableAssigner.LeftSideParameter.ActualName = "ComparisonFactor";
     194      variableAssigner.LeftSideParameter.ActualName = "ComparisonFactor"; // this variable is referenced in SASEGASA, OffspringSelectionGeneticAlgorithm, do not change!
    199195      variableAssigner.RightSideParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
    200196
     
    313309      offspringSelector.LuckyLosersParameter.ActualName = "OSLuckyLosers";
    314310      offspringSelector.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
    315       offspringSelector.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
    316311      offspringSelector.SelectionPressureParameter.ActualName = "SelectionPressure";
    317312      offspringSelector.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
     
    382377
    383378      conditionalBranch2.Name = "MaximumGenerations reached?";
    384       conditionalBranch2.ConditionParameter.ActualName = "TerminateMaximumGenerations";
     379      conditionalBranch2.ConditionParameter.ActualName = "TerminateMaximumGenerations"; // this variable is referenced in SASEGASAMainLoop, do not change!
    385380      #endregion
    386381
  • trunk/sources/HeuristicLab.Analysis/3.3/DataTableValuesCollector.cs

    r3376 r3479  
    5252
    5353      foreach (IParameter param in CollectedValues) {
    54         DoubleValue data = param.ActualValue as DoubleValue;
    55         if (data == null) data = new DoubleValue(double.NaN);
    56 
    57         DataRow row;
    58         table.Rows.TryGetValue(param.Name, out row);
    59         if (row == null) {
    60           row = new DataRow(param.Name, param.Description);
    61           row.Values.Add(data.Value);
    62           table.Rows.Add(row);
     54        if (param.ActualValue is DoubleValue) {
     55          DoubleValue data = param.ActualValue as DoubleValue;
     56          DataRow row;
     57          table.Rows.TryGetValue(param.Name, out row);
     58          if (row == null) {
     59            row = new DataRow(param.Name, param.Description);
     60            row.Values.Add(data.Value);
     61            table.Rows.Add(row);
     62          } else {
     63            row.Values.Add(data.Value);
     64          }
     65        } else if (param.ActualValue is ItemArray<DoubleValue>) {
     66          ItemArray<DoubleValue> dataArray = param.ActualValue as ItemArray<DoubleValue>;
     67          DataRow row;
     68          for (int i = 0; i < dataArray.Length; i++) {
     69            table.Rows.TryGetValue(param.Name + i.ToString(), out row);
     70            if (row == null) {
     71              row = new DataRow(param.Name + i.ToString(), param.Description);
     72              row.Values.Add(dataArray[i].Value);
     73              table.Rows.Add(row);
     74            } else {
     75              row.Values.Add(dataArray[i].Value);
     76            }
     77          }
    6378        } else {
    64           row.Values.Add(data.Value);
     79          DataRow row;
     80          table.Rows.TryGetValue(param.Name, out row);
     81          if (row == null) {
     82            row = new DataRow(param.Name, param.Description);
     83            row.Values.Add(double.NaN);
     84            table.Rows.Add(row);
     85          } else {
     86            row.Values.Add(double.NaN);
     87          }
    6588        }
    6689      }
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/SASEGASAReunificator.cs

    r3451 r3479  
    2626using HeuristicLab.Operators;
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Data;
     29using HeuristicLab.Parameters;
    2830
    2931namespace HeuristicLab.Optimization.Operators {
     
    3234  /// scopes by 1 and uniformly partitions the sub sub scopes again, maintaining the order.
    3335  /// </summary>
    34   /*[Item("SASEGASAReunificator", "This operator merges the villages in a migration phase and redistributes the individuals. It is implemented as described in Affenzeller, M. et al. 2009. Genetic Algorithms and Genetic Programming - Modern Concepts and Practical Applications, CRC Press.")]
     36  [Item("SASEGASAReunificator", "This operator merges the villages in a migration phase and redistributes the individuals. It is implemented as described in Affenzeller, M. et al. 2009. Genetic Algorithms and Genetic Programming - Modern Concepts and Practical Applications, CRC Press.")]
    3537  [StorableClass]
    3638  public class SASEGASAReunificator : SingleSuccessorOperator, IMigrator {
    3739
     40    public LookupParameter<IntValue> VillageCountParameter {
     41      get { return (LookupParameter<IntValue>)Parameters["VillageCount"]; }
     42    }
     43
     44    public SASEGASAReunificator()
     45      : base() {
     46      Parameters.Add(new LookupParameter<IntValue>("VillageCount", "The number of villages left after the reunification."));
     47    }
    3848    /// <summary>
    3949    /// Joins all sub sub scopes of the given <paramref name="scope"/>, reduces the number of sub
    4050    /// scopes by 1 and uniformly partitions the sub sub scopes again, maintaining the order.
    4151    /// </summary>
    42     /// <exception cref="InvalidOperationException">Thrown when only 0 or 1 sub scope is available.</exception>
     52    /// <exception cref="InvalidOperationException">Thrown when there are less than 2 sub-scopes available or when VillageCount does not equal the number of sub-scopes.</exception>
    4353    /// <param name="scope">The current scope whose sub scopes to reduce.</param>
    4454    /// <returns><c>null</c>.</returns>
    4555    public override IOperation Apply() {
    4656      IScope scope = ExecutionContext.Scope;
    47       int villageCount = scope.SubScopes.Count;
     57      if (VillageCountParameter.ActualValue == null) VillageCountParameter.ActualValue = new IntValue(scope.SubScopes.Count);
     58      int villageCount = VillageCountParameter.ActualValue.Value;
    4859      if (villageCount <= 1)
    49         throw new InvalidOperationException("SASEGASA reunification requires 2 or more sub-scopes");
     60        throw new InvalidOperationException(Name + ": Reunification requires 2 or more sub-scopes");
     61      if (villageCount != scope.SubScopes.Count)
     62        throw new InvalidOperationException(Name + ": VillageCount does not equal the number of sub-scopes");
    5063
    5164      // get all villages
    52       IList<IScope> population = new List<IScope>();
     65      List<IScope> population = new List<IScope>();
    5366      for (int i = 0; i < villageCount; i++) {
    54         while (scope.SubScopes[i].SubScopes[0].SubScopes.Count > 0) {
    55           population.Add(scope.SubScopes[i].SubScopes[0].SubScopes[0]);
    56           scope.SubScopes[i].SubScopes.Remove(scope.SubScopes[i].SubScopes[0].SubScopes[0]);
    57         }
     67        population.AddRange(scope.SubScopes[i].SubScopes);
    5868        scope.SubScopes[i].SubScopes.Clear();
    5969      }
     
    6474      int populationPerVillage = population.Count / villageCount;
    6575      for (int i = 0; i < villageCount; i++) {
    66         scope.SubScopes[i].SubScopes.Add(new Scope());
    67         scope.SubScopes[i].SubScopes.Add(new Scope());
    68         for (int j = 0; j < populationPerVillage; j++) {
    69           scope.SubScopes[i].SubScopes[1].SubScopes.Add(population[0]);
    70           population.RemoveAt(0);
    71         }
     76        scope.SubScopes[i].SubScopes.AddRange(population.GetRange(0, populationPerVillage));
     77        population.RemoveRange(0, populationPerVillage);
    7278      }
    7379
    7480      // add remaining sub-sub-scopes to last sub-scope
    75       while (population.Count > 0) {
    76         scope.SubScopes[scope.SubScopes.Count - 1].SubScopes[1].SubScopes.Add(population[0]);
    77         population.RemoveAt(0);
    78       }
     81      scope.SubScopes[scope.SubScopes.Count - 1].SubScopes.AddRange(population);
     82      population.Clear();
     83
     84      VillageCountParameter.ActualValue.Value = villageCount;
    7985
    8086      return base.Apply();
    8187    }
    82   }*/
     88  }
    8389}
  • trunk/sources/HeuristicLab.Parameters/3.3/SubScopesLookupParameter.cs

    r3017 r3479  
    3535    public SubScopesLookupParameter(string name) : base(name) { }
    3636    public SubScopesLookupParameter(string name, string description) : base(name, description) { }
     37    public SubScopesLookupParameter(string name, string description, string actualName) : base(name, description, actualName) { }
    3738
    3839    protected override IItem GetActualValue() {
  • trunk/sources/HeuristicLab.Selection/3.3/OffspringSelector.cs

    r3413 r3479  
    3434  public class OffspringSelector : SingleSuccessorOperator {
    3535
    36     public ValueLookupParameter<IntValue> PopulationSizeParameter {
    37       get { return (ValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }
    38     }
    3936    public ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
    4037      get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
     
    6663    public OffspringSelector()
    6764      : base() {
    68       Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The number of offspring to create."));
    6965      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure which prematurely terminates the offspring selection step."));
    7066      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful offspring that has to be produced."));
     
    7773
    7874    public override IOperation Apply() {
    79       int populationSize = PopulationSizeParameter.ActualValue.Value;
    8075      double maxSelPress = MaximumSelectionPressureParameter.ActualValue.Value;
    8176      double successRatio = SuccessRatioParameter.ActualValue.Value;
     
    8378      IScope parents = scope.SubScopes[0];
    8479      IScope children = scope.SubScopes[1];
     80      int populationSize = parents.SubScopes.Count;
    8581
    8682      // retrieve actual selection pressure and success ratio
Note: See TracChangeset for help on using the changeset viewer.