Changeset 3479
- Timestamp:
- 04/21/10 22:05:40 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 added
- 7 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm-3.3.csproj ¶
r3429 r3479 80 80 </ItemGroup> 81 81 <ItemGroup> 82 <Compile Include="SASEGASA.cs" /> 83 <Compile Include="SASEGASAMainLoop.cs" /> 82 84 <Compile Include="HeuristicLabAlgorithmsOffspringSelectionGeneticAlgorithmPlugin.cs" /> 83 <Compile Include=" OffspringSelectionIslandGeneticAlgorithm.cs" />84 <Compile Include=" OffspringSelectionIslandGeneticAlgorithmMainLoop.cs" />85 <Compile Include="IslandOffspringSelectionGeneticAlgorithm.cs" /> 86 <Compile Include="IslandOffspringSelectionGeneticAlgorithmMainLoop.cs" /> 85 87 <Compile Include="OffspringSelectionGeneticAlgorithm.cs" /> 86 88 <Compile Include="OffspringSelectionGeneticAlgorithmMainLoop.cs" /> -
TabularUnified trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/IslandOffspringSelectionGeneticAlgorithm.cs ¶
r3450 r3479 39 39 /// An offspring selection island genetic algorithm. 40 40 /// </summary> 41 [Item(" Offspring Selection Island Genetic Algorithm", "An offspring selection islandgenetic algorithm.")]41 [Item("Island Offspring Selection Genetic Algorithm", "An island offspring selection genetic algorithm.")] 42 42 [Creatable("Algorithms")] 43 43 [StorableClass] 44 public sealed class OffspringSelectionIslandGeneticAlgorithm : EngineAlgorithm {44 public sealed class IslandOffspringSelectionGeneticAlgorithm : EngineAlgorithm { 45 45 46 46 #region Problem Properties … … 229 229 get { return (SolutionsCreator)IslandProcessor.Operator; } 230 230 } 231 private OffspringSelectionIslandGeneticAlgorithmMainLoop MainLoop {232 get { return ( OffspringSelectionIslandGeneticAlgorithmMainLoop)IslandProcessor.Successor; }231 private IslandOffspringSelectionGeneticAlgorithmMainLoop MainLoop { 232 get { return (IslandOffspringSelectionGeneticAlgorithmMainLoop)IslandProcessor.Successor; } 233 233 } 234 234 #endregion 235 235 236 236 [StorableConstructor] 237 private OffspringSelectionIslandGeneticAlgorithm(bool deserializing) : base(deserializing) { }238 public OffspringSelectionIslandGeneticAlgorithm()237 private IslandOffspringSelectionGeneticAlgorithm(bool deserializing) : base(deserializing) { } 238 public IslandOffspringSelectionGeneticAlgorithm() 239 239 : base() { 240 240 Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); … … 246 246 Parameters.Add(new ConstrainedValueParameter<ISelector>("EmigrantsSelector", "Selects the individuals that will be migrated.")); 247 247 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))); 249 249 Parameters.Add(new ValueParameter<IntValue>("MaximumMigrations", "The maximum number of migrations that should occur.", new IntValue(100))); 250 250 Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.")); … … 265 265 UniformSubScopesProcessor ussp1 = new UniformSubScopesProcessor(); 266 266 SolutionsCreator solutionsCreator = new SolutionsCreator(); 267 OffspringSelectionIslandGeneticAlgorithmMainLoop mainLoop = new OffspringSelectionIslandGeneticAlgorithmMainLoop();267 IslandOffspringSelectionGeneticAlgorithmMainLoop mainLoop = new IslandOffspringSelectionGeneticAlgorithmMainLoop(); 268 268 OperatorGraph.InitialOperator = randomCreator; 269 269 … … 313 313 314 314 public override IDeepCloneable Clone(Cloner cloner) { 315 OffspringSelectionIslandGeneticAlgorithm clone = (OffspringSelectionIslandGeneticAlgorithm)base.Clone(cloner);315 IslandOffspringSelectionGeneticAlgorithm clone = (IslandOffspringSelectionGeneticAlgorithm)base.Clone(cloner); 316 316 clone.Initialize(); 317 317 return clone; -
TabularUnified trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/IslandOffspringSelectionGeneticAlgorithmMainLoop.cs ¶
r3450 r3479 37 37 namespace HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm { 38 38 /// <summary> 39 /// An offspring selection islandgenetic algorithm main loop operator.39 /// An island offspring selection genetic algorithm main loop operator. 40 40 /// </summary> 41 [Item(" OffspringSelectionIslandGeneticAlgorithmMainLoop", "An offspring selection islandgenetic algorithm main loop operator.")]41 [Item("IslandOffspringSelectionGeneticAlgorithmMainLoop", "An island offspring selection genetic algorithm main loop operator.")] 42 42 [StorableClass] 43 public sealed class OffspringSelectionIslandGeneticAlgorithmMainLoop : AlgorithmOperator {43 public sealed class IslandOffspringSelectionGeneticAlgorithmMainLoop : AlgorithmOperator { 44 44 #region Parameter Properties 45 45 public ValueLookupParameter<IRandom> RandomParameter { … … 127 127 128 128 [StorableConstructor] 129 private OffspringSelectionIslandGeneticAlgorithmMainLoop(bool deserializing) : base() { }130 public OffspringSelectionIslandGeneticAlgorithmMainLoop()129 private IslandOffspringSelectionGeneticAlgorithmMainLoop(bool deserializing) : base() { } 130 public IslandOffspringSelectionGeneticAlgorithmMainLoop() 131 131 : base() { 132 132 #region Create parameters -
TabularUnified trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs ¶
r3426 r3479 212 212 solutionsCreator.Successor = mainLoop; 213 213 214 mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;215 214 mainLoop.SelectorParameter.ActualName = SelectorParameter.Name; 216 215 mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name; … … 285 284 private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) { 286 285 PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged); 287 MainLoop.PopulationSizeParameter.Value = new IntValue(PopulationSize.Value - Elites.Value);288 286 ParameterizeSelectors(); 289 287 } 290 288 private void PopulationSize_ValueChanged(object sender, EventArgs e) { 291 MainLoop.PopulationSizeParameter.Value = new IntValue(PopulationSize.Value - Elites.Value);292 289 ParameterizeSelectors(); 293 290 } -
TabularUnified trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithmMainLoop.cs ¶
r3446 r3479 43 43 get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 44 44 } 45 public ValueLookupParameter<IntValue> PopulationSizeParameter {46 get { return (ValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }47 }48 45 public SubScopesLookupParameter<DoubleValue> QualityParameter { 49 46 get { return (SubScopesLookupParameter<DoubleValue>)Parameters["Quality"]; } … … 113 110 Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator.")); 114 111 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."));116 112 Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 117 113 Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far.")); … … 189 185 initializationBranch.ConditionParameter.ActualName = "IsInitialized"; 190 186 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! 192 188 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue(0))); 193 189 variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("SelectionPressure", new DoubleValue(0))); … … 196 192 variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("IsInitialized", new BoolValue(true))); 197 193 198 variableAssigner.LeftSideParameter.ActualName = "ComparisonFactor"; 194 variableAssigner.LeftSideParameter.ActualName = "ComparisonFactor"; // this variable is referenced in SASEGASA, OffspringSelectionGeneticAlgorithm, do not change! 199 195 variableAssigner.RightSideParameter.ActualName = ComparisonFactorLowerBoundParameter.Name; 200 196 … … 313 309 offspringSelector.LuckyLosersParameter.ActualName = "OSLuckyLosers"; 314 310 offspringSelector.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name; 315 offspringSelector.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;316 311 offspringSelector.SelectionPressureParameter.ActualName = "SelectionPressure"; 317 312 offspringSelector.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name; … … 382 377 383 378 conditionalBranch2.Name = "MaximumGenerations reached?"; 384 conditionalBranch2.ConditionParameter.ActualName = "TerminateMaximumGenerations"; 379 conditionalBranch2.ConditionParameter.ActualName = "TerminateMaximumGenerations"; // this variable is referenced in SASEGASAMainLoop, do not change! 385 380 #endregion 386 381 -
TabularUnified trunk/sources/HeuristicLab.Analysis/3.3/DataTableValuesCollector.cs ¶
r3376 r3479 52 52 53 53 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 } 63 78 } 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 } 65 88 } 66 89 } -
TabularUnified trunk/sources/HeuristicLab.Optimization.Operators/3.3/SASEGASAReunificator.cs ¶
r3451 r3479 26 26 using HeuristicLab.Operators; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Data; 29 using HeuristicLab.Parameters; 28 30 29 31 namespace HeuristicLab.Optimization.Operators { … … 32 34 /// scopes by 1 and uniformly partitions the sub sub scopes again, maintaining the order. 33 35 /// </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.")] 35 37 [StorableClass] 36 38 public class SASEGASAReunificator : SingleSuccessorOperator, IMigrator { 37 39 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 } 38 48 /// <summary> 39 49 /// Joins all sub sub scopes of the given <paramref name="scope"/>, reduces the number of sub 40 50 /// scopes by 1 and uniformly partitions the sub sub scopes again, maintaining the order. 41 51 /// </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> 43 53 /// <param name="scope">The current scope whose sub scopes to reduce.</param> 44 54 /// <returns><c>null</c>.</returns> 45 55 public override IOperation Apply() { 46 56 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; 48 59 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"); 50 63 51 64 // get all villages 52 IList<IScope> population = new List<IScope>();65 List<IScope> population = new List<IScope>(); 53 66 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); 58 68 scope.SubScopes[i].SubScopes.Clear(); 59 69 } … … 64 74 int populationPerVillage = population.Count / villageCount; 65 75 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); 72 78 } 73 79 74 80 // 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; 79 85 80 86 return base.Apply(); 81 87 } 82 } */88 } 83 89 } -
TabularUnified trunk/sources/HeuristicLab.Parameters/3.3/SubScopesLookupParameter.cs ¶
r3017 r3479 35 35 public SubScopesLookupParameter(string name) : base(name) { } 36 36 public SubScopesLookupParameter(string name, string description) : base(name, description) { } 37 public SubScopesLookupParameter(string name, string description, string actualName) : base(name, description, actualName) { } 37 38 38 39 protected override IItem GetActualValue() { -
TabularUnified trunk/sources/HeuristicLab.Selection/3.3/OffspringSelector.cs ¶
r3413 r3479 34 34 public class OffspringSelector : SingleSuccessorOperator { 35 35 36 public ValueLookupParameter<IntValue> PopulationSizeParameter {37 get { return (ValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }38 }39 36 public ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter { 40 37 get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; } … … 66 63 public OffspringSelector() 67 64 : base() { 68 Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The number of offspring to create."));69 65 Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure which prematurely terminates the offspring selection step.")); 70 66 Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful offspring that has to be produced.")); … … 77 73 78 74 public override IOperation Apply() { 79 int populationSize = PopulationSizeParameter.ActualValue.Value;80 75 double maxSelPress = MaximumSelectionPressureParameter.ActualValue.Value; 81 76 double successRatio = SuccessRatioParameter.ActualValue.Value; … … 83 78 IScope parents = scope.SubScopes[0]; 84 79 IScope children = scope.SubScopes[1]; 80 int populationSize = parents.SubScopes.Count; 85 81 86 82 // retrieve actual selection pressure and success ratio
Note: See TracChangeset
for help on using the changeset viewer.