Changeset 2890 for trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGA.cs
- Timestamp:
- 03/01/10 03:01:01 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGA.cs
r2884 r2890 43 43 private SGAOperator sgaOperator; 44 44 45 private ValueParameter<IntData> PopulationSizeParameter {46 get { return ( ValueParameter<IntData>)Parameters["PopulationSize"]; }45 private OptionalValueParameter<IntData> PopulationSizeParameter { 46 get { return (OptionalValueParameter<IntData>)Parameters["PopulationSize"]; } 47 47 } 48 48 private ConstrainedValueParameter<ISelector> SelectorParameter { … … 55 55 get { return (ConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; } 56 56 } 57 private ValueParameter<IntData> ElitesParameter {58 get { return ( ValueParameter<IntData>)Parameters["Elites"]; }57 private OptionalValueParameter<IntData> ElitesParameter { 58 get { return (OptionalValueParameter<IntData>)Parameters["Elites"]; } 59 59 } 60 60 … … 69 69 public SGA() 70 70 : base() { 71 Parameters.Add(new ValueParameter<IntData>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntData(0)));72 Parameters.Add(new ValueParameter<BoolData>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolData(true)));73 Parameters.Add(new ValueParameter<IntData>("PopulationSize", "The size of the population of solutions.", new IntData(100)));71 Parameters.Add(new OptionalValueParameter<IntData>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntData(0))); 72 Parameters.Add(new OptionalValueParameter<BoolData>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolData(true))); 73 Parameters.Add(new OptionalValueParameter<IntData>("PopulationSize", "The size of the population of solutions.", new IntData(100))); 74 74 Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.")); 75 75 Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.")); 76 Parameters.Add(new ValueParameter<DoubleData>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new DoubleData(0.05)));76 Parameters.Add(new OptionalValueParameter<DoubleData>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new DoubleData(0.05))); 77 77 Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.")); 78 Parameters.Add(new ValueParameter<IntData>("Elites", "The numer of elite solutions which are kept in each generation.", new IntData(1)));79 Parameters.Add(new ValueParameter<IntData>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntData(1000)));78 Parameters.Add(new OptionalValueParameter<IntData>("Elites", "The numer of elite solutions which are kept in each generation.", new IntData(1))); 79 Parameters.Add(new OptionalValueParameter<IntData>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntData(1000))); 80 80 81 81 PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged); … … 109 109 110 110 var selectors = ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)); 111 selectors.Select(x => x.CopySelected = new BoolData(true));112 selectors.Select(x => x.NumberOfSelectedSubScopesParameter.Value = new IntData(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value)));113 selectors.OfType<IStochasticOperator>().Select(x => x.RandomParameter.ActualName = "Random");114 foreach (ISelector selector in selectors)111 foreach (ISelector selector in selectors) { 112 selector.CopySelected = new BoolData(true); 113 selector.NumberOfSelectedSubScopesParameter.Value = new IntData(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value)); 114 if (selector is IStochasticOperator) ((IStochasticOperator)selector).RandomParameter.ActualName = "Random"; 115 115 SelectorParameter.ValidValues.Add(selector); 116 } 116 117 } 117 118 … … 124 125 125 126 private void ElitesParameter_ValueChanged(object sender, EventArgs e) { 126 SelectorParameter.ValidValues.Select(x => x.NumberOfSelectedSubScopesParameter.Value = new IntData(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value))); 127 foreach (ISelector selector in SelectorParameter.ValidValues) 128 selector.NumberOfSelectedSubScopesParameter.Value = new IntData(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value)); 127 129 } 128 130 private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) { 129 SelectorParameter.ValidValues.Select(x => x.NumberOfSelectedSubScopesParameter.Value = new IntData(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value))); 131 foreach (ISelector selector in SelectorParameter.ValidValues) 132 selector.NumberOfSelectedSubScopesParameter.Value = new IntData(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value)); 130 133 } 131 134 … … 142 145 if (Problem.SolutionCreator is IStochasticOperator) ((IStochasticOperator)Problem.SolutionCreator).RandomParameter.ActualName = "Random"; 143 146 if (Problem.Evaluator is IStochasticOperator) ((IStochasticOperator)Problem.Evaluator).RandomParameter.ActualName = "Random"; 144 Problem.Operators.OfType<IStochasticOperator>().Select(x => x.RandomParameter.ActualName = "Random"); 147 foreach (IStochasticOperator op in Problem.Operators.OfType<IStochasticOperator>()) 148 op.RandomParameter.ActualName = "Random"; 145 149 146 150 populationCreator.SolutionCreatorParameter.Value = Problem.SolutionCreator; … … 150 154 sgaOperator.EvaluatorParameter.Value = Problem.Evaluator; 151 155 152 SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>().Select(x => x.MaximizationParameter.Value = Problem.Maximization); 153 SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>().Select(x => x.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName); 156 foreach (ISingleObjectiveSelector op in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) { 157 op.MaximizationParameter.Value = Problem.Maximization; 158 op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 159 } 154 160 155 161 CrossoverParameter.ValidValues.Clear(); … … 170 176 protected override void Problem_EvaluatorChanged(object sender, EventArgs e) { 171 177 if (Problem.Evaluator is IStochasticOperator) ((IStochasticOperator)Problem.Evaluator).RandomParameter.ActualName = "Random"; 172 SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>().Select(x => x.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName); 178 179 foreach (ISingleObjectiveSelector op in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) { 180 op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 181 } 182 173 183 populationCreator.EvaluatorParameter.Value = Problem.Evaluator; 174 184 sgaOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; … … 178 188 private void Problem_MaximizationChanged(object sender, EventArgs e) { 179 189 sgaOperator.MaximizationParameter.Value = Problem.Maximization; 180 SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>().Select(x => x.MaximizationParameter.Value = Problem.Maximization); 190 foreach (ISingleObjectiveSelector op in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) { 191 op.MaximizationParameter.Value = Problem.Maximization; 192 } 181 193 } 182 194 }
Note: See TracChangeset
for help on using the changeset viewer.