Changeset 5293 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding
- Timestamp:
- 01/14/11 00:41:58 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/Crossovers/ParameterConfigurationCrossover.cs
r5277 r5293 38 38 } 39 39 40 /// <summary> 41 /// Whether the problem is a maximization or minimization problem. 42 /// </summary> 43 public ValueLookupParameter<BoolValue> MaximizationParameter { 44 get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 45 } 46 47 /// <summary> 48 /// The quality of the parents. 49 /// </summary> 50 public ScopeTreeLookupParameter<DoubleValue> QualityParameter { 51 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 52 } 53 40 54 [StorableConstructor] 41 55 protected ParameterConfigurationCrossover(bool deserializing) : base(deserializing) { } … … 46 60 Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("Parents", "The parent vectors which should be crossed.")); 47 61 Parameters.Add(new LookupParameter<ParameterConfigurationTree>("Child", "The child vector resulting from the crossover.")); 48 62 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "Whether the problem is a maximization problem or not.")); 63 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality values of the parents.")); 49 64 Parameters.Add(new ValueLookupParameter<IIntValueCrossover>(MetaOptimizationProblem.IntValueCrossoverParameterName, "")); 50 65 Parameters.Add(new ValueLookupParameter<IDoubleValueCrossover>(MetaOptimizationProblem.DoubleValueCrossoverParameterName, "")); … … 55 70 56 71 public override IOperation Apply() { 57 ParameterConfigurationTree child1 = (ParameterConfigurationTree)ParentsParameter.ActualValue[0].Clone(); 58 ParameterConfigurationTree child2 = (ParameterConfigurationTree)ParentsParameter.ActualValue[1]; 72 if (MaximizationParameter.ActualValue == null) throw new InvalidOperationException("HeuristicCrossover: Parameter " + MaximizationParameter.ActualName + " could not be found."); 73 if (QualityParameter.ActualValue == null || QualityParameter.ActualValue.Length != 2) throw new InvalidOperationException("ParameterConfigurationCrossover: Parameter " + QualityParameter.ActualName + " could not be found, or not in the same quantity as there are parents."); 74 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 75 bool maximization = MaximizationParameter.ActualValue.Value; 76 77 ParameterConfigurationTree child1; 78 ParameterConfigurationTree child2; 79 80 if (maximization && qualities[0].Value >= qualities[1].Value || !maximization && qualities[0].Value <= qualities[1].Value) { 81 child1 = (ParameterConfigurationTree)ParentsParameter.ActualValue[0].Clone(); 82 child2 = (ParameterConfigurationTree)ParentsParameter.ActualValue[1]; 83 } else { 84 child1 = (ParameterConfigurationTree)ParentsParameter.ActualValue[1].Clone(); 85 child2 = (ParameterConfigurationTree)ParentsParameter.ActualValue[0]; 86 } 59 87 60 88 child1.Cross(RandomParameter.ActualValue, child2, Cross, IntValueCrossoverParameter.ActualValue, DoubleValueCrossoverParameter.ActualValue);
Note: See TracChangeset
for help on using the changeset viewer.