Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/14/11 00:41:58 (14 years ago)
Author:
cneumuel
Message:

#1215

  • added NormalCrossover operators
  • renamed MedianQualityAnalyzer to ReferenceQualityAnalyzer
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/Crossovers/ParameterConfigurationCrossover.cs

    r5277 r5293  
    3838    }
    3939
     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
    4054    [StorableConstructor]
    4155    protected ParameterConfigurationCrossover(bool deserializing) : base(deserializing) { }
     
    4660      Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("Parents", "The parent vectors which should be crossed."));
    4761      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."));
    4964      Parameters.Add(new ValueLookupParameter<IIntValueCrossover>(MetaOptimizationProblem.IntValueCrossoverParameterName, ""));
    5065      Parameters.Add(new ValueLookupParameter<IDoubleValueCrossover>(MetaOptimizationProblem.DoubleValueCrossoverParameterName, ""));
     
    5570
    5671    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      }
    5987
    6088      child1.Cross(RandomParameter.ActualValue, child2, Cross, IntValueCrossoverParameter.ActualValue, DoubleValueCrossoverParameter.ActualValue);
Note: See TracChangeset for help on using the changeset viewer.