Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/22/12 11:11:38 (12 years ago)
Author:
jkarder
Message:

#1331:

  • synced branch with trunk
  • added custom interface (ISimilarityBasedOperator) to mark operators that conduct similarity calculation
  • similarity calculators are now parameterized by the algorithm
  • deleted SolutionPool2TierUpdateMethod
  • deleted KnapsackMultipleGuidesPathRelinker
  • moved IImprovementOperator, IPathRelinker and ISimilarityCalculator to HeuristicLab.Optimization
  • added parameter descriptions
  • fixed plugin references
  • fixed count of EvaluatedSolutions
  • fixed check for duplicate solutions
  • minor code improvements
Location:
branches/ScatterSearch (trunk integration)
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/ScatterSearch (trunk integration)

  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/Improvers/SingleObjectiveTestFunctionImprovementOperator.cs

    r7954 r8086  
    2727using HeuristicLab.Encodings.RealVectorEncoding;
    2828using HeuristicLab.Operators;
    29 using HeuristicLab.Optimization.Operators;
     29using HeuristicLab.Optimization;
    3030using HeuristicLab.Parameters;
    3131using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    6363      get { return (IValueLookupParameter<IntValue>)Parameters["ImprovementAttempts"]; }
    6464    }
    65     public IValueLookupParameter<IRandom> RandomParameter {
    66       get { return (IValueLookupParameter<IRandom>)Parameters["Random"]; }
    67     }
    6865    public IValueLookupParameter<IItem> TargetParameter {
    6966      get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
     
    8986    public ISingleObjectiveTestFunctionProblemEvaluator Evaluator {
    9087      get { return EvaluatorParameter.ActualValue; }
    91       set { EvaluatorParameter.ActualValue = value; }
    9288    }
    9389    private DoubleValue Gamma {
     
    9692    public IntValue ImprovementAttempts {
    9793      get { return ImprovementAttemptsParameter.ActualValue; }
    98       set { ImprovementAttemptsParameter.ActualValue = value; }
    99     }
    100     public IRandom Random {
    101       get { return RandomParameter.ActualValue; }
    102       set { RandomParameter.ActualValue = value; }
    103     }
    104     private IItem Target {
    105       get { return TargetParameter.ActualValue; }
    10694    }
    10795    #endregion
     
    115103      Parameters.Add(new ValueParameter<DoubleValue>("Alpha", new DoubleValue(1.0)));
    116104      Parameters.Add(new ValueParameter<DoubleValue>("Beta", new DoubleValue(2.0)));
    117       Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds"));
    118       Parameters.Add(new ScopeParameter("CurrentScope"));
     105      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension."));
     106      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the solution to be improved."));
    119107      Parameters.Add(new ValueParameter<DoubleValue>("Delta", new DoubleValue(0.5)));
    120       Parameters.Add(new ValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator>("Evaluator"));
     108      Parameters.Add(new ValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator>("Evaluator", "The operator used to evaluate solutions."));
    121109      Parameters.Add(new ValueParameter<DoubleValue>("Gamma", new DoubleValue(0.5)));
    122       Parameters.Add(new ValueLookupParameter<IntValue>("ImprovementAttempts", new IntValue(100)));
    123       Parameters.Add(new ValueLookupParameter<IItem>("Target"));
    124       Parameters.Add(new ValueLookupParameter<IRandom>("Random"));
     110      Parameters.Add(new ValueLookupParameter<IntValue>("ImprovementAttempts", "The number of improvement attempts the operator should perform.", new IntValue(100)));
     111      Parameters.Add(new ValueLookupParameter<IItem>("Target", "This parameter is used for name translation only."));
    125112      #endregion
    126113    }
     
    132119    public override IOperation Apply() {
    133120      RealVector bestSol = CurrentScope.Variables[TargetParameter.ActualName].Value as RealVector;
     121      if (bestSol == null)
     122        throw new ArgumentException("Cannot improve solution because it has the wrong type.");
     123
    134124      MethodInfo evaluationMethod = Evaluator.GetType().GetMethod("Apply",
    135125                                                                  BindingFlags.Public | BindingFlags.Static,
     
    207197
    208198      CurrentScope.Variables[TargetParameter.ActualName].Value = simplex[0];
     199      CurrentScope.Variables.Add(new Variable("LocalEvaluatedSolutions", ImprovementAttempts));
    209200
    210201      return base.Apply();
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/PathRelinkers/SingleObjectiveTestFunctionPathRelinker.cs

    r7789 r8086  
    4747    private IntValue RelinkingIntensity {
    4848      get { return RelinkingIntensityParameter.Value; }
    49       set { RelinkingIntensityParameter.Value = value; }
    5049    }
    5150    #endregion
     
    5756      : base() {
    5857      #region Create parameters
    59       Parameters.Add(new ValueParameter<IntValue>("RelinkingIntensity", new IntValue(10)));
     58      Parameters.Add(new ValueParameter<IntValue>("RelinkingIntensity", "Determines how strong path relinking should be applied.", new IntValue(10)));
    6059      #endregion
    6160    }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/Plugin.cs.frame

    r7259 r8086  
    3636  [PluginDependency("HeuristicLab.Operators", "3.3")]
    3737  [PluginDependency("HeuristicLab.Optimization", "3.3")]
     38  [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")]
    3839  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3940  [PluginDependency("HeuristicLab.Persistence", "3.3")]
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/SimilarityCalculators/SingleObjectiveTestFunctionSimilarityCalculator.cs

    r7954 r8086  
    2626using HeuristicLab.Encodings.RealVectorEncoding;
    2727using HeuristicLab.Optimization.Operators;
    28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2928
    3029namespace HeuristicLab.Problems.TestFunctions {
     
    3332  /// </summary>
    3433  [Item("SingleObjectiveTestFunctionSimilarityCalculator", "An operator that performs similarity calculation between two test functions solutions.")]
    35   [StorableClass]
    3634  public sealed class SingleObjectiveTestFunctionSimilarityCalculator : SimilarityCalculator {
    3735    #region Properties
     
    3937    #endregion
    4038
    41     [StorableConstructor]
    4239    private SingleObjectiveTestFunctionSimilarityCalculator(bool deserializing) : base(deserializing) { }
    4340    private SingleObjectiveTestFunctionSimilarityCalculator(SingleObjectiveTestFunctionSimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
    4441    public SingleObjectiveTestFunctionSimilarityCalculator() : base() { }
    4542
    46     public override IDeepCloneable Clone(Cloner cloner) {
    47       return new SingleObjectiveTestFunctionSimilarityCalculator(this, cloner);
     43    public static double CalculateSimilarity(RealVector left, RealVector right, DoubleMatrix bounds) {
     44      if (left == null || right == null)
     45        throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null.");
     46      if (bounds == null)
     47        throw new ArgumentException("Cannot calculate similarity because no bounds were provided.");
     48
     49      double maxSum = 0.0;
     50      for (int i = 0; i < left.Length; i++)
     51        maxSum += Math.Pow(bounds[0, 0] - bounds[0, 1], 2);
     52      double maxDistance = Math.Sqrt(maxSum) / left.Length;
     53
     54      double sum = 0.0;
     55      for (int i = 0; i < left.Length; i++)
     56        sum += Math.Pow(left[i] - right[i], 2);
     57      double distance = Math.Sqrt(sum) / left.Length;
     58
     59      return 1.0 - distance / maxDistance;
    4860    }
    4961
    5062    protected override double CalculateSimilarity(IScope left, IScope right) {
    51       RealVector sol1 = left.Variables["Point"].Value as RealVector;
    52       RealVector sol2 = right.Variables["Point"].Value as RealVector;
     63      RealVector sol1 = left.Variables[Target].Value as RealVector;
     64      RealVector sol2 = right.Variables[Target].Value as RealVector;
    5365
    54       double maxSum = 0.0;
    55       for (int i = 0; i < sol1.Length; i++)
    56         maxSum += Math.Pow(Bounds[0, 0] - Bounds[0, 1], 2);
    57       double maxDistance = Math.Sqrt(maxSum) / sol1.Length;
    58 
    59       double sum = 0.0;
    60       for (int i = 0; i < sol1.Length; i++)
    61         sum += Math.Pow(sol1[i] - sol2[i], 2);
    62       double distance = Math.Sqrt(sum) / sol1.Length;
    63 
    64       return 1.0 - distance / maxDistance;
     66      return CalculateSimilarity(sol1, sol2, Bounds);
    6567    }
    6668  }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r7954 r8086  
    2828using HeuristicLab.Encodings.RealVectorEncoding;
    2929using HeuristicLab.Optimization;
    30 using HeuristicLab.Optimization.Operators;
    3130using HeuristicLab.Parameters;
    3231using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    377376      }
    378377      foreach (SingleObjectiveTestFunctionSimilarityCalculator op in Operators.OfType<ISimilarityCalculator>()) {
    379         op.TargetParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    380         op.TargetParameter.Hidden = true;
     378        op.Target = SolutionCreator.RealVectorParameter.ActualName;
    381379        op.Bounds = Bounds;
    382380      }
Note: See TracChangeset for help on using the changeset viewer.