Changeset 2852 for trunk/sources/HeuristicLab.SGA/3.3
- Timestamp:
- 02/23/10 06:50:50 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.SGA/3.3
- Files:
-
- 3 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.SGA/3.3/SGA.cs
r2851 r2852 20 20 #endregion 21 21 22 using System;23 22 using HeuristicLab.Core; 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;25 using HeuristicLab.Collections;26 using HeuristicLab.Parameters;27 23 using HeuristicLab.Data; 24 using HeuristicLab.Evolutionary; 28 25 using HeuristicLab.Operators; 29 26 using HeuristicLab.Optimization; 30 using HeuristicLab.Evolutionary; 27 using HeuristicLab.Parameters; 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using System; 31 30 32 31 namespace HeuristicLab.SGA { … … 36 35 [Item("SGA", "A standard genetic algorithm.")] 37 36 [Creatable("Algorithms")] 38 [EmptyStorableClass]39 37 public sealed class SGA : EngineAlgorithm { 38 [Storable] 39 private PopulationCreator populationCreator; 40 [Storable] 41 private SGAOperator sgaOperator; 42 43 public override Type ProblemType { 44 get { return typeof(ISingleObjectiveProblem); } 45 } 46 public new ISingleObjectiveProblem Problem { 47 get { return (ISingleObjectiveProblem)base.Problem; } 48 set { base.Problem = value; } 49 } 50 40 51 public new IScope GlobalScope { 41 52 get { return base.GlobalScope; } … … 44 55 public SGA() 45 56 : base() { 46 // Parameters.Add(new ValueLookupParameter<BoolData>("Maximization", "True if the problem is a maximization problem, otherwise false."));47 // Parameters.Add(new SubScopesLookupParameter<DoubleData>("Quality", "The value which represents the quality of a solution."));48 57 Parameters.Add(new ValueParameter<IntData>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntData(0))); 49 58 Parameters.Add(new ValueParameter<BoolData>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolData(true))); … … 52 61 Parameters.Add(new ValueParameter<DoubleData>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new DoubleData(0.05))); 53 62 Parameters.Add(new OperatorParameter("MutationOperator", "The operator used to mutate solutions.")); 54 // Parameters.Add(new ValueLookupParameter<IOperator>("SolutionEvaluator", "The operator used to evaluate solutions."));55 63 Parameters.Add(new ValueParameter<IntData>("Elites", "The numer of elite solutions which are kept in each generation.", new IntData(1))); 56 64 Parameters.Add(new ValueParameter<IntData>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntData(1000))); 57 65 58 66 RandomCreator randomCreator = new RandomCreator(); 59 PopulationCreatorpopulationCreator = new PopulationCreator();60 SGAOperatorsgaOperator = new SGAOperator();67 populationCreator = new PopulationCreator(); 68 sgaOperator = new SGAOperator(); 61 69 62 70 randomCreator.RandomParameter.ActualName = "Random"; … … 69 77 populationCreator.PopulationSizeParameter.ActualName = "PopulationSize"; 70 78 populationCreator.PopulationSizeParameter.Value = null; 71 populationCreator.SolutionCreatorParameter.ActualName = "SolutionCreator";72 populationCreator.SolutionEvaluatorParameter.ActualName = "SolutionEvaluator";73 79 populationCreator.Successor = sgaOperator; 74 80 75 81 sgaOperator.CrossoverOperatorParameter.ActualName = "CrossoverOperator"; 76 82 sgaOperator.ElitesParameter.ActualName = "Elites"; 77 sgaOperator.MaximizationParameter.ActualName = "Maximization";78 83 sgaOperator.MaximumGenerationsParameter.ActualName = "MaximumGenerations"; 79 84 sgaOperator.MutationOperatorParameter.ActualName = "MutationOperator"; 80 85 sgaOperator.MutationProbabilityParameter.ActualName = "MutationProbability"; 81 sgaOperator.QualityParameter.ActualName = "Quality";82 86 sgaOperator.RandomParameter.ActualName = "Random"; 83 sgaOperator.SolutionEvaluatorParameter.ActualName = "SolutionEvaluator";84 87 85 88 OperatorGraph.InitialOperator = randomCreator; 86 89 } 90 91 public override IDeepCloneable Clone(Cloner cloner) { 92 SGA clone = (SGA)base.Clone(cloner); 93 clone.populationCreator = (PopulationCreator)cloner.Clone(populationCreator); 94 clone.sgaOperator = (SGAOperator)cloner.Clone(sgaOperator); 95 return clone; 96 } 97 98 protected override void DeregisterProblemEvents() { 99 Problem.MaximizationChanged -= new EventHandler(Problem_MaximizationChanged); 100 base.DeregisterProblemEvents(); 101 } 102 protected override void RegisterProblemEvents() { 103 base.RegisterProblemEvents(); 104 Problem.MaximizationChanged += new EventHandler(Problem_MaximizationChanged); 105 } 106 107 protected override void OnProblemChanged() { 108 Problem.SolutionCreator.RandomParameter.ActualName = "Random"; 109 populationCreator.SolutionCreatorParameter.Value = Problem.SolutionCreator; 110 populationCreator.SolutionEvaluatorParameter.Value = Problem.Evaluator; 111 sgaOperator.MaximizationParameter.Value = Problem.Maximization; 112 sgaOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.Name; 113 sgaOperator.SolutionEvaluatorParameter.Value = Problem.Evaluator; 114 base.OnProblemChanged(); 115 } 116 protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) { 117 Problem.SolutionCreator.RandomParameter.ActualName = "Random"; 118 populationCreator.SolutionCreatorParameter.Value = Problem.SolutionCreator; 119 base.Problem_SolutionCreatorChanged(sender, e); 120 } 121 protected override void Problem_EvaluatorChanged(object sender, EventArgs e) { 122 populationCreator.SolutionEvaluatorParameter.Value = Problem.Evaluator; 123 sgaOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.Name; 124 sgaOperator.SolutionEvaluatorParameter.Value = Problem.Evaluator; 125 base.Problem_EvaluatorChanged(sender, e); 126 } 127 private void Problem_MaximizationChanged(object sender, EventArgs e) { 128 sgaOperator.MaximizationParameter.Value = Problem.Maximization; 129 } 87 130 } 88 131 }
Note: See TracChangeset
for help on using the changeset viewer.