Changeset 2890 for trunk/sources
- Timestamp:
- 03/01/10 03:01:01 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 10 edited
- 1 moved
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 } -
trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGAOperator.cs
r2884 r2890 25 25 using HeuristicLab.Operators; 26 26 using HeuristicLab.Parameters; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;28 27 using HeuristicLab.Selection; 29 28 -
trunk/sources/HeuristicLab.Operators/3.3/Comparator.cs
r2834 r2890 40 40 get { return (ValueLookupParameter<IItem>)Parameters["RightSide"]; } 41 41 } 42 private ValueParameter<ComparisonData> ComparisonParameter {43 get { return ( ValueParameter<ComparisonData>)Parameters["Comparison"]; }42 private OptionalValueParameter<ComparisonData> ComparisonParameter { 43 get { return (OptionalValueParameter<ComparisonData>)Parameters["Comparison"]; } 44 44 } 45 45 public LookupParameter<BoolData> ResultParameter { … … 55 55 Parameters.Add(new LookupParameter<IItem>("LeftSide", "The left side of the comparison.")); 56 56 Parameters.Add(new ValueLookupParameter<IItem>("RightSide", "The right side of the comparison.")); 57 Parameters.Add(new ValueParameter<ComparisonData>("Comparison", "The type of comparison.", new ComparisonData()));57 Parameters.Add(new OptionalValueParameter<ComparisonData>("Comparison", "The type of comparison.", new ComparisonData())); 58 58 Parameters.Add(new LookupParameter<BoolData>("Result", "The result of the comparison.")); 59 59 } -
trunk/sources/HeuristicLab.Operators/3.3/SubScopesRemover.cs
r2834 r2890 33 33 [Creatable("Test")] 34 34 public sealed class SubScopesRemover : SingleSuccessorOperator { 35 private ValueParameter<BoolData> RemoveAllSubScopesParameter {36 get { return ( ValueParameter<BoolData>)Parameters["RemoveAllSubScopes"]; }35 private OptionalValueParameter<BoolData> RemoveAllSubScopesParameter { 36 get { return (OptionalValueParameter<BoolData>)Parameters["RemoveAllSubScopes"]; } 37 37 } 38 38 public ValueLookupParameter<IntData> SubScopeIndexParameter { … … 53 53 public SubScopesRemover() 54 54 : base() { 55 Parameters.Add(new ValueParameter<BoolData>("RemoveAllSubScopes", "True if all sub-scopes of the current scope should be removed, otherwise false.", new BoolData(true)));55 Parameters.Add(new OptionalValueParameter<BoolData>("RemoveAllSubScopes", "True if all sub-scopes of the current scope should be removed, otherwise false.", new BoolData(true))); 56 56 Parameters.Add(new ValueLookupParameter<IntData>("SubScopeIndex", "The index of the sub-scope which should be removed. This parameter is ignored, if RemoveAllSubScopes is true.")); 57 57 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope from which one or all sub-scopes should be removed.")); -
trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueParameterView.cs
r2870 r2890 30 30 /// The visual representation of a <see cref="Parameter"/>. 31 31 /// </summary> 32 [Content(typeof( ValueParameter<>), true)]32 [Content(typeof(OptionalValueParameter<>), true)] 33 33 [Content(typeof(IValueParameter<>), false)] 34 34 public partial class ValueParameterView<T> : ParameterView where T : class, IItem { -
trunk/sources/HeuristicLab.Parameters/3.3/HeuristicLab.Parameters-3.3.csproj
r2852 r2890 69 69 <Compile Include="ConstrainedValueParameter.cs" /> 70 70 <Compile Include="LookupParameter.cs" /> 71 <Compile Include="OptionalValueParameter.cs" /> 71 72 <Compile Include="SubScopesLookupParameter.cs" /> 72 73 <Compile Include="ValueLookupParameter.cs" /> 73 <Compile Include="ValueParameter.cs" />74 74 <Compile Include="ScopeParameter.cs" /> 75 75 <Compile Include="HeuristicLabParametersPlugin.cs" /> -
trunk/sources/HeuristicLab.Parameters/3.3/OperatorParameter.cs
r2818 r2890 30 30 [EmptyStorableClass] 31 31 [Creatable("Test")] 32 public class OperatorParameter : ValueParameter<IOperator> {32 public class OperatorParameter : OptionalValueParameter<IOperator> { 33 33 public OperatorParameter() 34 34 : base("Anonymous") { -
trunk/sources/HeuristicLab.Parameters/3.3/OptionalValueParameter.cs
r2889 r2890 27 27 namespace HeuristicLab.Parameters { 28 28 /// <summary> 29 /// A parameter whose value is defined it the parameter itself. 29 /// A parameter whose value is defined it the parameter itself. The value of the parameter can be null, if the parameter is not set. 30 30 /// </summary> 31 [Item(" ValueParameter<T>", "A parameter whose value is defined it the parameter itself.")]32 public class ValueParameter<T> : Parameter, IValueParameter<T> where T : class, IItem {31 [Item("OptionalValueParameter<T>", "A parameter whose value is defined it the parameter itself. The value of the parameter can be null, if the parameter is not set.")] 32 public class OptionalValueParameter<T> : Parameter, IValueParameter<T> where T : class, IItem { 33 33 private T value; 34 34 [Storable] … … 57 57 } 58 58 59 public ValueParameter()59 public OptionalValueParameter() 60 60 : base("Anonymous", typeof(T)) { 61 61 } 62 public ValueParameter(string name)62 public OptionalValueParameter(string name) 63 63 : base(name, typeof(T)) { 64 64 } 65 public ValueParameter(string name, T value)65 public OptionalValueParameter(string name, T value) 66 66 : base(name, typeof(T)) { 67 67 Value = value; 68 68 } 69 public ValueParameter(string name, string description)69 public OptionalValueParameter(string name, string description) 70 70 : base(name, description, typeof(T)) { 71 71 } 72 public ValueParameter(string name, string description, T value)72 public OptionalValueParameter(string name, string description, T value) 73 73 : base(name, description, typeof(T)) { 74 74 Value = value; … … 76 76 77 77 public override IDeepCloneable Clone(Cloner cloner) { 78 ValueParameter<T> clone = (ValueParameter<T>)base.Clone(cloner);78 OptionalValueParameter<T> clone = (OptionalValueParameter<T>)base.Clone(cloner); 79 79 clone.Value = (T)cloner.Clone(value); 80 80 return clone; -
trunk/sources/HeuristicLab.Problems.TSP/3.3/TSP.cs
r2883 r2890 75 75 public TSP() 76 76 : base() { 77 ValueParameter<BoolData> maximizationParameter = new ValueParameter<BoolData>("Maximization", "Set to false as the Traveling Salesman Problem is a minimization problem.", new BoolData(false)); 78 maximizationParameter.ValueChanged += new EventHandler(MaximizationParameter_ValueChanged); 79 Parameters.Add(maximizationParameter); 77 Parameters.Add(new OptionalValueParameter<BoolData>("Maximization", "Set to false as the Traveling Salesman Problem is a minimization problem.", new BoolData(false))); 78 Parameters.Add(new OptionalValueParameter<DoubleMatrixData>("Coordinates", "The x- and y-Coordinates of the cities.", new DoubleMatrixData(0, 0))); 79 Parameters.Add(new OptionalValueParameter<IPermutationCreator>("SolutionCreator", "The operator which should be used to create new TSP solutions.")); 80 Parameters.Add(new OptionalValueParameter<ITSPEvaluator>("Evaluator", "The operator which should be used to evaluate TSP solutions.")); 81 Parameters.Add(new OptionalValueParameter<DoubleData>("BestKnownQuality", "The quality of the best known solution of this TSP instance.")); 80 82 81 Parameters.Add(new ValueParameter<DoubleMatrixData>("Coordinates", "The x- and y-Coordinates of the cities.", new DoubleMatrixData(0, 0))); 82 83 ValueParameter<IPermutationCreator> solutionCreatorParameter = new ValueParameter<IPermutationCreator>("SolutionCreator", "The operator which should be used to create new TSP solutions."); 84 solutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged); 85 Parameters.Add(solutionCreatorParameter); 86 87 ValueParameter<ITSPEvaluator> evaluatorParameter = new ValueParameter<ITSPEvaluator>("Evaluator", "The operator which should be used to evaluate TSP solutions."); 88 evaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged); 89 Parameters.Add(evaluatorParameter); 90 91 Parameters.Add(new ValueParameter<DoubleData>("BestKnownQuality", "The quality of the best known solution of this TSP instance.")); 83 MaximizationParameter.ValueChanged += new EventHandler(MaximizationParameter_ValueChanged); 84 SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged); 85 EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged); 92 86 93 87 RandomPermutationCreator creator = new RandomPermutationCreator(); … … 101 95 EvaluatorParameter.Value = evaluator; 102 96 103 var ops = ApplicationManager.Manager.GetInstances<IPermutationOperator>().ToList(); 104 ops.ForEach(x => { 105 IPermutationCrossover y = x as IPermutationCrossover; 106 if (y != null) { 107 y.ParentsParameter.ActualName = creator.PermutationParameter.ActualName; 108 y.ChildParameter.ActualName = creator.PermutationParameter.ActualName; 109 } 110 }); 111 ops.ForEach(x => { 112 IPermutationManipulator y = x as IPermutationManipulator; 113 if (y != null) 114 y.PermutationParameter.ActualName = creator.PermutationParameter.ActualName; 115 }); 97 var ops = ApplicationManager.Manager.GetInstances<IPermutationOperator>(); 98 foreach (IPermutationCrossover op in ops.OfType<IPermutationCrossover>()) { 99 op.ParentsParameter.ActualName = creator.PermutationParameter.ActualName; 100 op.ChildParameter.ActualName = creator.PermutationParameter.ActualName; 101 } 102 foreach (IPermutationManipulator op in ops.OfType<IPermutationManipulator>()) { 103 op.PermutationParameter.ActualName = creator.PermutationParameter.ActualName; 104 } 116 105 operators = new OperatorSet(ops.Cast<IOperator>()); 117 106 } -
trunk/sources/HeuristicLab.Selection/3.3/ProportionalSelector.cs
r2830 r2890 36 36 [Creatable("Test")] 37 37 public sealed class ProportionalSelector : StochasticSingleObjectiveSelector { 38 private ValueParameter<BoolData> WindowingParameter {39 get { return ( ValueParameter<BoolData>)Parameters["Windowing"]; }38 private OptionalValueParameter<BoolData> WindowingParameter { 39 get { return (OptionalValueParameter<BoolData>)Parameters["Windowing"]; } 40 40 } 41 41 … … 47 47 public ProportionalSelector() 48 48 : base() { 49 Parameters.Add(new ValueParameter<BoolData>("Windowing", "Apply windowing strategy (selection probability is proportional to the quality differences and not to the total quality).", new BoolData(true)));49 Parameters.Add(new OptionalValueParameter<BoolData>("Windowing", "Apply windowing strategy (selection probability is proportional to the quality differences and not to the total quality).", new BoolData(true))); 50 50 CopySelected.Value = true; 51 51 } -
trunk/sources/HeuristicLab.Selection/3.3/Selector.cs
r2882 r2890 35 35 [EmptyStorableClass] 36 36 public abstract class Selector : SingleSuccessorOperator, ISelector { 37 protected ValueParameter<BoolData> CopySelectedParameter {38 get { return ( ValueParameter<BoolData>)Parameters["CopySelected"]; }37 protected OptionalValueParameter<BoolData> CopySelectedParameter { 38 get { return (OptionalValueParameter<BoolData>)Parameters["CopySelected"]; } 39 39 } 40 40 public IValueLookupParameter<IntData> NumberOfSelectedSubScopesParameter { … … 55 55 protected Selector() 56 56 : base() { 57 Parameters.Add(new ValueParameter<BoolData>("CopySelected", "True if the selected sub-scopes should be copied, otherwise false.", new BoolData(false)));57 Parameters.Add(new OptionalValueParameter<BoolData>("CopySelected", "True if the selected sub-scopes should be copied, otherwise false.", new BoolData(false))); 58 58 Parameters.Add(new ValueLookupParameter<IntData>("NumberOfSelectedSubScopes", "The number of sub-scopes which should be selected.")); 59 59 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope from which sub-scopes should be selected."));
Note: See TracChangeset
for help on using the changeset viewer.