Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/24/12 15:04:37 (12 years ago)
Author:
jkarder
Message:

#1331:

  • applied some of the changes suggested by ascheibe in comment:32:ticket:1331
  • restructured path relinking and improvement operators and similarity calculators
  • fixed bug in TSPMultipleGuidesPathRelinker
Location:
branches/ScatterSearch (trunk integration)
Files:
7 added
2 deleted
32 edited
2 moved

Legend:

Unmodified
Added
Removed
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/HeuristicLab.Algorithms.ScatterSearch-3.3.csproj

    r8306 r8319  
    8585  </ItemGroup>
    8686  <ItemGroup>
    87     <Compile Include="IScatterSearchOperator.cs" />
    8887    <Compile Include="OffspringProcessor.cs" />
    8988    <None Include="HeuristicLab.snk" />
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/OffspringProcessor.cs

    r8086 r8319  
    3232  [Item("OffspringProcessor", "An operator that creates a subscope with subscopes for every variable in the current scope.")]
    3333  [StorableClass]
    34   public sealed class OffspringProcessor : SingleSuccessorOperator, IScatterSearchOperator {
     34  public sealed class OffspringProcessor : SingleSuccessorOperator {
    3535    #region Parameter properties
    3636    public ScopeParameter CurrentScopeParameter {
    3737      get { return (ScopeParameter)Parameters["CurrentScope"]; }
    38     }
    39     public IValueLookupParameter<IItem> TargetParameter {
    40       get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
    4138    }
    4239    #endregion
     
    4542    private IScope CurrentScope {
    4643      get { return CurrentScopeParameter.ActualValue; }
    47     }
    48     private IItem Target {
    49       get { return TargetParameter.ActualValue; }
    5044    }
    5145    #endregion
     
    5852      #region Create parameters
    5953      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the offspring as variables."));
    60       Parameters.Add(new ValueLookupParameter<IItem>("Target", "This parameter is used for name translation only."));
    6154      #endregion
    6255    }
     
    6760
    6861    public override IOperation Apply() {
    69       VariableCollection offspringSolutions = CurrentScope.Variables;
    70       IScope offspringScope = new Scope("Offspring");
    71       foreach (var solution in offspringSolutions) {
    72         IScope scope = new Scope();
    73         scope.Variables.Add(new Variable(TargetParameter.ActualName, solution.Value));
    74         offspringScope.SubScopes.Add(scope);
    75       }
     62      var child = new Scope();
     63      child.Variables.AddRange(CurrentScope.Variables);
     64      var offspringScope = new Scope();
     65      offspringScope.SubScopes.Add(child);
     66      var parents = CurrentScope.SubScopes.ToArray();
     67      CurrentScope.Variables.Clear();
     68      CurrentScope.SubScopes.Clear();
     69      CurrentScope.SubScopes.AddRange(parents);
    7670      CurrentScope.SubScopes.Add(offspringScope);
    77       CurrentScope.Variables.Clear();
    7871      return base.Apply();
    7972    }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/PopulationRebuildMethod.cs

    r8086 r8319  
    3434  [Item("PopulationRebuildMethod", "An operator that updates the reference set and rebuilds the population.")]
    3535  [StorableClass]
    36   public sealed class PopulationRebuildMethod : SingleSuccessorOperator, IScatterSearchOperator {
     36  public sealed class PopulationRebuildMethod : SingleSuccessorOperator {
    3737    #region Parameter properties
    3838    public ScopeParameter CurrentScopeParameter {
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs

    r8304 r8319  
    3939  public sealed class ReferenceSetUpdateMethod : SingleSuccessorOperator, ISimilarityBasedOperator {
    4040    #region ISimilarityBasedOperator Members
    41     public ISimilarityCalculator SimilarityCalculator { get; set; }
     41    public ISolutionSimilarityCalculator SimilarityCalculator { get; set; }
    4242    #endregion
    4343
     
    7676
    7777    public override IOperation Apply() {
    78       IDictionary<IScope, double> population = new Dictionary<IScope, double>();
    79       foreach (var pScope in CurrentScope.SubScopes[0].SubScopes) {
    80         double similarity = 0;
    81         foreach (var rScope in CurrentScope.SubScopes[1].SubScopes) {
    82           similarity += SimilarityCalculator.CalculateIndividualSimilarity(pScope, rScope);
    83         }
    84         population[pScope] = similarity;
     78      var populationSimilarity = new Dictionary<IScope, double>();
     79      var populationScope = CurrentScope.SubScopes[0];
     80      var refSetScope = CurrentScope.SubScopes[1];
     81      var similarityMatrix = SimilarityCalculator.CalculateSolutionCrowdSimilarity(populationScope, refSetScope);
     82      for (int i = 0; i < populationScope.SubScopes.Count; i++) {
     83        populationSimilarity[populationScope.SubScopes[i]] = similarityMatrix[i].Sum();
    8584      }
    8685      int numberOfHighQualitySolutions = CurrentScope.SubScopes[1].SubScopes.Count;
    87       foreach (var entry in population.OrderBy(x => x.Value).Take(ReferenceSetSize.Value - numberOfHighQualitySolutions)) {
     86      foreach (var entry in populationSimilarity.OrderBy(x => x.Value).Take(ReferenceSetSize.Value - numberOfHighQualitySolutions)) {
    8887        CurrentScope.SubScopes[1].SubScopes.Add(entry.Key);
    8988        CurrentScope.SubScopes[0].SubScopes.Remove(entry.Key);
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs

    r8299 r8319  
    2222using System;
    2323using System.Linq;
    24 using System.Reflection;
    2524using HeuristicLab.Analysis;
    2625using HeuristicLab.Common;
     
    8988      get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
    9089    }
    91     public ConstrainedValueParameter<ISimilarityCalculator> SimilarityCalculatorParameter {
    92       get { return (ConstrainedValueParameter<ISimilarityCalculator>)Parameters["SimilarityCalculator"]; }
     90    public ConstrainedValueParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
     91      get { return (ConstrainedValueParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    9392    }
    9493    #endregion
     
    139138      set { SetSeedRandomlyParameter.Value = value; }
    140139    }
    141     private ISimilarityCalculator SimilarityCalculator {
     140    private ISolutionSimilarityCalculator SimilarityCalculator {
    142141      get { return SimilarityCalculatorParameter.Value; }
    143142      set { SimilarityCalculatorParameter.Value = value; }
     
    185184      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    186185      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
    187       Parameters.Add(new ConstrainedValueParameter<ISimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
     186      Parameters.Add(new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
    188187      #endregion
    189188
     
    382381    }
    383382    private void UpdateSimilarityCalculators() {
    384       ISimilarityCalculator oldDiversityCalculator = SimilarityCalculatorParameter.Value;
     383      ISolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
    385384      SimilarityCalculatorParameter.ValidValues.Clear();
    386       ISimilarityCalculator defaultDiversityCalculator = Problem.Operators.OfType<ISimilarityCalculator>().FirstOrDefault();
    387 
    388       foreach (ISimilarityCalculator diversityCalculator in Problem.Operators.OfType<ISimilarityCalculator>())
    389         SimilarityCalculatorParameter.ValidValues.Add(diversityCalculator);
    390 
    391       if (oldDiversityCalculator != null) {
    392         ISimilarityCalculator diversityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldDiversityCalculator.GetType());
    393         if (diversityCalculator != null) SimilarityCalculatorParameter.Value = diversityCalculator;
    394         else oldDiversityCalculator = null;
    395       }
    396       if (oldDiversityCalculator == null && defaultDiversityCalculator != null)
    397         SimilarityCalculatorParameter.Value = defaultDiversityCalculator;
     385      ISolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISolutionSimilarityCalculator>().FirstOrDefault();
     386
     387      foreach (ISolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISolutionSimilarityCalculator>())
     388        SimilarityCalculatorParameter.ValidValues.Add(similarityCalculator);
     389
     390      if (oldSimilarityCalculator != null) {
     391        ISolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
     392        if (similarityCalculator != null) SimilarityCalculatorParameter.Value = similarityCalculator;
     393        else oldSimilarityCalculator = null;
     394      }
     395      if (oldSimilarityCalculator == null && defaultSimilarityCalculator != null)
     396        SimilarityCalculatorParameter.Value = defaultSimilarityCalculator;
    398397    }
    399398    private void ParameterizeBestSelector() {
     
    410409        MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    411410        MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    412         MainLoop.TargetParameter.ActualName = Improver.TargetParameter.ActualName;
    413         foreach (var op in MainLoop.OperatorGraph.Operators.OfType<IScatterSearchOperator>()) {
    414           // parameter should be accessed direclty (using an interface definition)
    415           PropertyInfo propInfo = op.GetType().GetProperty(MainLoop.TargetParameter.Name + "Parameter");
    416           if (propInfo != null && propInfo.CanRead)
    417             (propInfo.GetValue(op, null) as IValueLookupParameter<IItem>).ActualName = MainLoop.TargetParameter.ActualName;
    418           propInfo = op.GetType().GetProperty(MainLoop.QualityParameter.Name + "Parameter");
    419           if (propInfo != null && propInfo.CanRead)
    420             (propInfo.GetValue(op, null) as IValueLookupParameter<IItem>).ActualName = MainLoop.QualityParameter.ActualName;
    421         }
     411        MainLoop.OperatorGraph.Operators.OfType<PopulationRebuildMethod>().Single().QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     412        MainLoop.OperatorGraph.Operators.OfType<SolutionPoolUpdateMethod>().Single().QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    422413        foreach (ISimilarityBasedOperator op in MainLoop.OperatorGraph.Operators.OfType<ISimilarityBasedOperator>())
    423414          op.SimilarityCalculator = SimilarityCalculator;
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearchMainLoop.cs

    r8086 r8319  
    8989      get { return (IValueLookupParameter<VariableCollection>)Parameters["Results"]; }
    9090    }
    91     public IValueLookupParameter<ISimilarityCalculator> SimilarityCalculatorParameter {
    92       get { return (IValueLookupParameter<ISimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    93     }
    94     public IValueLookupParameter<IItem> TargetParameter {
    95       get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
     91    public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
     92      get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    9693    }
    9794    #endregion
     
    166163      set { ResultsParameter.ActualValue = value; }
    167164    }
    168     private ISimilarityCalculator SimilarityCalculator {
     165    private ISolutionSimilarityCalculator SimilarityCalculator {
    169166      get { return SimilarityCalculatorParameter.ActualValue; }
    170167      set { SimilarityCalculatorParameter.ActualValue = value; }
    171     }
    172     private IItem Target {
    173       get { return TargetParameter.ActualValue; }
    174       set { TargetParameter.ActualValue = value; }
    175168    }
    176169    #endregion
     
    204197      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
    205198      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
    206       Parameters.Add(new ValueLookupParameter<ISimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
    207       Parameters.Add(new ValueLookupParameter<IItem>("Target", "This parameter is used for name translation only."));
     199      Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
    208200      #endregion
    209201
     
    298290      pathRelinker.Name = "PathRelinker";
    299291      pathRelinker.OperatorParameter.ActualName = PathRelinkerParameter.Name;
    300       pathRelinker.Successor = offspringProcessor;
     292      pathRelinker.Successor = rightSelector;
    301293
    302294      crossover.Name = "Crossover";
     
    304296      crossover.Successor = offspringProcessor;
    305297
    306       offspringProcessor.TargetParameter.ActualName = TargetParameter.ActualName;
    307298      offspringProcessor.Successor = rightSelector;
    308299
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs

    r8304 r8319  
    2828using HeuristicLab.Operators;
    2929using HeuristicLab.Optimization;
    30 using HeuristicLab.Optimization.Operators;
    3130using HeuristicLab.Parameters;
    3231using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3837  [Item("SolutionPoolUpdateMethod", "An operator that updates the solution pool.")]
    3938  [StorableClass]
    40   public sealed class SolutionPoolUpdateMethod : SingleSuccessorOperator, IScatterSearchOperator, ISimilarityBasedOperator {
     39  public sealed class SolutionPoolUpdateMethod : SingleSuccessorOperator, ISimilarityBasedOperator {
    4140    #region ISimilarityBasedOperator Members
    42     public ISimilarityCalculator SimilarityCalculator { get; set; }
     41    public ISolutionSimilarityCalculator SimilarityCalculator { get; set; }
    4342    #endregion
    4443
     
    130129      if (orderedOffspring.Any(hasBetterQuality)) {
    131130        // produce the set union
    132         var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), new SolutionEqualityComparer<IScope>(SimilarityCalculator.CalculateIndividualSimilarity));
     131        var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), new SolutionEqualityComparer<IScope>(SimilarityCalculator.CalculateSolutionSimilarity));
    133132        if (union.Count() > orderedParents.Count()) {
    134133          var orderedUnion = Maximization.Value ? union.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
     
    142141    }
    143142
     143    // derive SingleObjectiveSolutionSimilarityCalculator from EqualityComparer
     144    // delete this ...
    144145    public class SolutionEqualityComparer<T> : EqualityComparer<T> {
    145146      private readonly Func<T, T, double> similarityCalculator;
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization.Operators/3.3/HeuristicLab.Optimization.Operators-3.3.csproj

    r8086 r8319  
    109109  </ItemGroup>
    110110  <ItemGroup>
     111    <Compile Include="SingleObjectiveSolutionSimilarityCalculator.cs" />
    111112    <Compile Include="GeneralizedExponentialDiscreteDoubleValueModifier.cs" />
    112113    <Compile Include="MultiObjective\CrowdedComparisonSorter.cs" />
     
    115116    <Compile Include="MultiObjective\FastNonDominatedSort.cs" />
    116117    <Compile Include="MultiObjective\RankAndCrowdingSorter.cs" />
    117     <Compile Include="PathRelinker.cs" />
     118    <Compile Include="SingleObjectivePathRelinker.cs" />
    118119    <Compile Include="Plugin.cs" />
    119120    <Compile Include="ShakingOperator.cs" />
    120     <Compile Include="SimilarityCalculator.cs" />
     121    <Compile Include="SolutionSimilarityCalculator.cs" />
    121122    <Compile Include="UserDefinedCrossover.cs" />
    122123    <Compile Include="UserDefinedEvaluator.cs" />
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization.Operators/3.3/SolutionSimilarityCalculator.cs

    r8316 r8319  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using HeuristicLab.Common;
     
    3233  [Item("SimilarityCalculator", "A base class for items that perform similarity calculation between two solutions.")]
    3334  [StorableClass]
    34   public abstract class SimilarityCalculator : Item, ISimilarityCalculator {
    35     #region Properties
    36     [Storable]
    37     private string target;
    38     public string Target {
    39       get { return target; }
    40       set { target = value; }
    41     }
    42     #endregion
     35  public abstract class SolutionSimilarityCalculator : Item, ISolutionSimilarityCalculator, IEqualityComparer<IScope> {
     36    [StorableConstructor]
     37    protected SolutionSimilarityCalculator(bool deserializing) : base(deserializing) { }
     38    protected SolutionSimilarityCalculator(SolutionSimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
     39    protected SolutionSimilarityCalculator() : base() { }
    4340
    44     [StorableConstructor]
    45     protected SimilarityCalculator(bool deserializing) : base(deserializing) { }
    46     protected SimilarityCalculator(SimilarityCalculator original, Cloner cloner)
    47       : base(original, cloner) {
    48       if (original.Target != null)
    49         this.target = (string)original.Target.Clone();
    50     }
    51     protected SimilarityCalculator() : base() { }
    52 
    53     public double[][] CalculateCrowdSimilarity(IScope leftCrowd, IScope rightCrowd) {
    54       if (leftCrowd == null || rightCrowd == null)
     41    public double[][] CalculateSolutionCrowdSimilarity(IScope leftSolutionCrowd, IScope rightSolutionCrowd) {
     42      if (leftSolutionCrowd == null || rightSolutionCrowd == null)
    5543        throw new ArgumentException("Cannot calculate similarity because one of the provided crowds or both are null.");
    5644
    57       var leftIndividuals = leftCrowd.SubScopes;
    58       var rightIndividuals = rightCrowd.SubScopes;
     45      var leftIndividuals = leftSolutionCrowd.SubScopes;
     46      var rightIndividuals = rightSolutionCrowd.SubScopes;
    5947
    6048      if (!leftIndividuals.Any() || !rightIndividuals.Any())
     
    6553        similarityMatrix[i] = new double[rightIndividuals.Count];
    6654        for (int j = 0; j < rightIndividuals.Count; j++) {
    67           similarityMatrix[i][j] = CalculateIndividualSimilarity(leftIndividuals[i], rightIndividuals[j]);
     55          similarityMatrix[i][j] = CalculateSolutionSimilarity(leftIndividuals[i], rightIndividuals[j]);
    6856        }
    6957      }
     
    7260    }
    7361
    74     public abstract double CalculateIndividualSimilarity(IScope leftIndividual, IScope rightIndividual);
     62    public double[][] CalculateSolutionCrowdSimilarity(IScope solutionCrowd) {
     63      if (solutionCrowd == null)
     64        throw new ArgumentException("Cannot calculate similarity because the provided crowd is null.");
     65
     66      var individuals = solutionCrowd.SubScopes;
     67
     68      if (!individuals.Any())
     69        throw new ArgumentException("Cannot calculate similarity because the provided crowd is empty.");
     70
     71      var similarityMatrix = new double[individuals.Count][];
     72      for (int i = 0; i < individuals.Count; i++) {
     73        similarityMatrix[i] = new double[individuals.Count];
     74        for (int j = i; j < individuals.Count; j++) {
     75          similarityMatrix[i][j] = similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[i], individuals[j]);
     76        }
     77      }
     78
     79      return similarityMatrix;
     80    }
     81
     82    public bool Equals(IScope x, IScope y) {
     83      if (object.ReferenceEquals(x, y)) return true;
     84      if (x == null || y == null) return false;
     85      return CalculateSolutionSimilarity(x, y) == 1.0;
     86    }
     87
     88    public abstract double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution);
     89    public abstract int GetHashCode(IScope obj);
    7590  }
    7691}
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj

    r8086 r8319  
    142142      <DependentUpon>ExperimentListView.cs</DependentUpon>
    143143    </Compile>
     144    <Compile Include="ISimilarityCalculatorView.cs">
     145      <SubType>UserControl</SubType>
     146    </Compile>
     147    <Compile Include="ISimilarityCalculatorView.Designer.cs">
     148      <DependentUpon>ISimilarityCalculatorView.cs</DependentUpon>
     149    </Compile>
    144150    <Compile Include="Plugin.cs" />
    145151    <Compile Include="ProblemView.cs">
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r8086 r8319  
    114114  </ItemGroup>
    115115  <ItemGroup>
     116    <Compile Include="Interfaces\ISingleObjectivePathRelinker.cs" />
     117    <Compile Include="Interfaces\ISingleObjectiveImprovementOperator.cs" />
     118    <Compile Include="Interfaces\ISingleObjectiveSolutionSimilarityCalculator.cs" />
    116119    <Compile Include="Interfaces\IImprovementOperator.cs" />
    117120    <Compile Include="Interfaces\IPathRelinker.cs" />
    118121    <Compile Include="Interfaces\ISimilarityBasedOperator.cs" />
    119     <Compile Include="Interfaces\ISimilarityCalculator.cs" />
     122    <Compile Include="Interfaces\ISolutionSimilarityCalculator.cs" />
    120123    <Compile Include="RunCollectionModification\RunCollectionRunRemover.cs" />
    121124    <Compile Include="Plugin.cs" />
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization/3.3/Interfaces/IImprovementOperator.cs

    r8086 r8319  
    2727  /// </summary>
    2828  public interface IImprovementOperator : IOperator {
    29     IValueLookupParameter<IItem> TargetParameter { get; }
    3029  }
    3130}
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization/3.3/Interfaces/IPathRelinker.cs

    r8086 r8319  
    2727  /// </summary>
    2828  public interface IPathRelinker : IOperator {
    29     ILookupParameter<ItemArray<IItem>> ParentsParameter { get; }
    3029  }
    3130}
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization/3.3/Interfaces/ISimilarityBasedOperator.cs

    r8171 r8319  
    2424namespace HeuristicLab.Optimization {
    2525  public interface ISimilarityBasedOperator : IOperator {
    26     ISimilarityCalculator SimilarityCalculator { get; set; }
     26    ISolutionSimilarityCalculator SimilarityCalculator { get; set; }
    2727  }
    2828}
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization/3.3/Interfaces/ISolutionSimilarityCalculator.cs

    r8316 r8319  
    2626  /// An interface which represents an operator for similarity calculation.
    2727  /// </summary>
    28   public interface ISimilarityCalculator : IItem {
    29     string Target { get; set; }
     28  public interface ISolutionSimilarityCalculator : IItem {
     29    /// <summary>
     30    /// Calculates the similarity of two solutions.
     31    /// </summary>
     32    /// <param name="leftSolution">The first scope that contains a solution.</param>
     33    /// <param name="rightSolution">The second scope that contains a solution.</param>
     34    /// <returns>A double between zero and one. Zero means the two solutions differ in every aspect, one indicates that the two solutions are the same.</returns>
     35    double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution);
    3036
    31     double CalculateIndividualSimilarity(IScope leftIndividual, IScope rightIndividual);
    32     double[][] CalculateCrowdSimilarity(IScope leftCrowd, IScope rightCrowd);
     37    /// <summary>
     38    /// Calculates the similarity of solutions in one scope.
     39    /// </summary>
     40    /// <param name="solutionCrowd">The scope that contains solutions.</param>
     41    /// <returns>A similarity matrix. Zero means the two solutions differ in every aspect, one indicates that the two solutions are the same.</returns>
     42    double[][] CalculateSolutionCrowdSimilarity(IScope solutionCrowd);
     43
     44    /// <summary>
     45    /// Calculates the similarity of solutions in two scopes.
     46    /// </summary>
     47    /// <param name="leftSolutionCrowd">The first scope that contains solutions.</param>
     48    /// <param name="rightSolutionCrowd">The second scope that contains solutions.</param>
     49    /// <returns>A similarity matrix. Zero means the two solutions differ in every aspect, one indicates that the two solutions are the same.</returns>
     50    double[][] CalculateSolutionCrowdSimilarity(IScope leftSolutionCrowd, IScope rightSolutionCrowd);
    3351  }
    3452}
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/Improvers/KnapsackImprovementOperator.cs

    r8086 r8319  
    3535  /// An operator that improves knapsack solutions.
    3636  /// </summary>
     37  /// <remarks>
     38  /// It is implemented as described in Laguna, M. and Martí, R. (2003). Scatter Search: Methodology and Implementations in C. Operations Research/Computer Science Interfaces Series, Vol. 24. Springer.<br />
     39  /// The operator first orders the elements of the knapsack according to their value-to-weight ratio, then, if the solution is not feasible, removes the element with the lowest ratio until the solution is feasible and tries to add new elements with the best ratio that are not already included yet until the knapsack is full.
     40  /// </remarks>
    3741  [Item("KnapsackImprovementOperator", "An operator that improves knapsack solutions.")]
    3842  [StorableClass]
    39   public sealed class KnapsackImprovementOperator : SingleSuccessorOperator, IImprovementOperator {
     43  public sealed class KnapsackImprovementOperator : SingleSuccessorOperator, ISingleObjectiveImprovementOperator {
    4044    #region Parameter properties
    4145    public ScopeParameter CurrentScopeParameter {
     
    4852      get { return (ILookupParameter<DoubleValue>)Parameters["Penalty"]; }
    4953    }
    50     public IValueLookupParameter<IItem> TargetParameter {
    51       get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
     54    public IValueLookupParameter<IItem> SolutionParameter {
     55      get { return (IValueLookupParameter<IItem>)Parameters["Solution"]; }
    5256    }
    5357    public ILookupParameter<IntArray> ValuesParameter {
     
    9094      Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity", "Capacity of the Knapsack."));
    9195      Parameters.Add(new LookupParameter<DoubleValue>("Penalty", "The penalty value for each unit of overweight."));
    92       Parameters.Add(new ValueLookupParameter<IItem>("Target", "This parameter is used for name translation only."));
     96      Parameters.Add(new ValueLookupParameter<IItem>("Solution", "The solution to be improved. This parameter is used for name translation only."));
    9397      Parameters.Add(new LookupParameter<IntArray>("Values", "The values of the items."));
    9498      Parameters.Add(new LookupParameter<IntArray>("Weights", "The weights of the items."));
     
    101105
    102106    public override IOperation Apply() {
    103       BinaryVector sol = CurrentScope.Variables[TargetParameter.ActualName].Value as BinaryVector;
     107      BinaryVector sol = CurrentScope.Variables[SolutionParameter.ActualName].Value as BinaryVector;
    104108      if (sol == null)
    105109        throw new ArgumentException("Cannot improve solution because it has the wrong type.");
     
    143147      }
    144148
    145       CurrentScope.Variables[TargetParameter.ActualName].Value = sol;
     149      CurrentScope.Variables[SolutionParameter.ActualName].Value = sol;
    146150      CurrentScope.Variables.Add(new Variable("LocalEvaluatedSolutions", new IntValue(evaluatedSolutions)));
    147151
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r8086 r8319  
    291291        op.ValuesParameter.Hidden = true;
    292292      }
    293       foreach (var op in Operators.OfType<IBinaryVectorMultiNeighborhoodShakingOperator>()) {
     293      foreach (IBinaryVectorMultiNeighborhoodShakingOperator op in Operators.OfType<IBinaryVectorMultiNeighborhoodShakingOperator>()) {
    294294        op.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName;
    295295        op.BinaryVectorParameter.Hidden = true;
    296296      }
    297       foreach (IImprovementOperator op in Operators.OfType<IImprovementOperator>()) {
    298         op.TargetParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName;
    299         op.TargetParameter.Hidden = true;
    300       }
    301       foreach (IPathRelinker op in Operators.OfType<IPathRelinker>()) {
     297      foreach (ISingleObjectiveImprovementOperator op in Operators.OfType<ISingleObjectiveImprovementOperator>()) {
     298        op.SolutionParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName;
     299        op.SolutionParameter.Hidden = true;
     300      }
     301      foreach (ISingleObjectivePathRelinker op in Operators.OfType<ISingleObjectivePathRelinker>()) {
    302302        op.ParentsParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName;
    303303        op.ParentsParameter.Hidden = true;
    304304      }
    305       foreach (ISimilarityCalculator op in Operators.OfType<ISimilarityCalculator>()) {
    306         op.Target = SolutionCreator.BinaryVectorParameter.ActualName;
     305      foreach (KnapsackSimilarityCalculator op in Operators.OfType<KnapsackSimilarityCalculator>()) {
     306        op.SolutionVariableName = SolutionCreator.BinaryVectorParameter.ActualName;
    307307      }
    308308    }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/PathRelinkers/KnapsackPathRelinker.cs

    r7789 r8319  
    3434  /// An operator that relinks paths between knapsack solutions.
    3535  /// </summary>
     36  /// <remarks>
     37  /// The operator incrementally assimilates the initiating solution into the guiding solution by adding and removing elements as needed.
     38  /// </remarks>
    3639  [Item("KnapsackPathRelinker", "An operator that relinks paths between knapsack solutions.")]
    3740  [StorableClass]
    38   public sealed class KnapsackPathRelinker : PathRelinker {
     41  public sealed class KnapsackPathRelinker : SingleObjectivePathRelinker {
    3942    [StorableConstructor]
    4043    private KnapsackPathRelinker(bool deserializing) : base(deserializing) { }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/PathRelinkers/KnapsackSimultaneousPathRelinker.cs

    r7789 r8319  
    3434  /// An operator that relinks paths between knapsack solutions starting from both ends.
    3535  /// </summary>
     36  /// <remarks>
     37  /// The operator incrementally assimilates the initiating solution into the guiding solution and vice versa by adding and removing elements as needed.
     38  /// </remarks>
    3639  [Item("KnapsackSimultaneousPathRelinker", "An operator that relinks paths between knapsack solutions starting from both ends.")]
    3740  [StorableClass]
    38   public sealed class KnapsackSimultaneousPathRelinker : PathRelinker {
     41  public sealed class KnapsackSimultaneousPathRelinker : SingleObjectivePathRelinker {
    3942    [StorableConstructor]
    4043    private KnapsackSimultaneousPathRelinker(bool deserializing) : base(deserializing) { }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/SimilarityCalculators/KnapsackSimilarityCalculator.cs

    r8304 r8319  
    3030  /// An operator that performs similarity calculation between two knapsack solutions.
    3131  /// </summary>
     32  /// <remarks>
     33  /// The operator calculates the similarity based on the number of elements the two solutions have in common.
     34  /// </remarks>
    3235  [Item("KnapsackSimilarityCalculator", "An operator that performs similarity calculation between two knapsack solutions.")]
    33   public sealed class KnapsackSimilarityCalculator : SimilarityCalculator {
     36  public sealed class KnapsackSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
    3437    private KnapsackSimilarityCalculator(bool deserializing) : base(deserializing) { }
    3538    private KnapsackSimilarityCalculator(KnapsackSimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
     
    4346      if (left == null || right == null)
    4447        throw new ArgumentException("Cannot calculate diversity because one or both of the provided scopes is null.");
     48      if (left.Length != right.Length)
     49        throw new ArgumentException("Cannot calculate similarity because the provided solutions have different lengths.");
    4550      if (left == right) return 1.0;
    4651
     
    5156    }
    5257
    53     public override double CalculateIndividualSimilarity(IScope left, IScope right) {
    54       var sol1 = left.Variables[Target].Value as BinaryVector;
    55       var sol2 = right.Variables[Target].Value as BinaryVector;
     58    public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) {
     59      var sol1 = leftSolution.Variables[SolutionVariableName].Value as BinaryVector;
     60      var sol2 = rightSolution.Variables[SolutionVariableName].Value as BinaryVector;
    5661
    5762      return CalculateSimilarity(sol1, sol2);
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/Improvers/SingleObjectiveTestFunctionImprovementOperator.cs

    r8086 r8319  
    3535  /// An operator that improves test functions solutions.
    3636  /// </summary>
     37  /// <remarks>
     38  /// It is implemented as described in Gao, F. and Han, L. (2010). Implementing the Nelder-Mead simplex algorithm with adaptive parameters. Computational Optimization and Applications, Vol. 51. Springer.<br />
     39  /// The operator is an implementation of the Nelder-Mead method and conducts relection, expansion, contraction and reduction on the test functions solution.
     40  /// </remarks>
    3741  [Item("SingleObjectiveTestFunctionImprovementOperator", "An operator that improves test functions solutions.")]
    3842  [StorableClass]
    39   public sealed class SingleObjectiveTestFunctionImprovementOperator : SingleSuccessorOperator, IImprovementOperator {
     43  public sealed class SingleObjectiveTestFunctionImprovementOperator : SingleSuccessorOperator, ISingleObjectiveImprovementOperator {
    4044    #region Parameter properties
    4145    public IValueParameter<DoubleValue> AlphaParameter {
     
    6367      get { return (IValueLookupParameter<IntValue>)Parameters["ImprovementAttempts"]; }
    6468    }
    65     public IValueLookupParameter<IItem> TargetParameter {
    66       get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
     69    public IValueLookupParameter<IItem> SolutionParameter {
     70      get { return (IValueLookupParameter<IItem>)Parameters["Solution"]; }
    6771    }
    6872    #endregion
     
    109113      Parameters.Add(new ValueParameter<DoubleValue>("Gamma", new DoubleValue(0.5)));
    110114      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."));
     115      Parameters.Add(new ValueLookupParameter<IItem>("Solution", "The solution to be improved. This parameter is used for name translation only."));
    112116      #endregion
    113117    }
     
    118122
    119123    public override IOperation Apply() {
    120       RealVector bestSol = CurrentScope.Variables[TargetParameter.ActualName].Value as RealVector;
     124      RealVector bestSol = CurrentScope.Variables[SolutionParameter.ActualName].Value as RealVector;
    121125      if (bestSol == null)
    122126        throw new ArgumentException("Cannot improve solution because it has the wrong type.");
     
    196200      }
    197201
    198       CurrentScope.Variables[TargetParameter.ActualName].Value = simplex[0];
     202      CurrentScope.Variables[SolutionParameter.ActualName].Value = simplex[0];
    199203      CurrentScope.Variables.Add(new Variable("LocalEvaluatedSolutions", ImprovementAttempts));
    200204
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/PathRelinkers/SingleObjectiveTestFunctionPathRelinker.cs

    r8086 r8319  
    3535  /// An operator that relinks paths between test functions solutions.
    3636  /// </summary>
     37  /// <remarks>
     38  /// TODO: add reference and remarks
     39  /// </remarks>
    3740  [Item("SingleObjectiveTestFunctionPathRelinker", "An operator that relinks paths between test functions solutions.")]
    3841  [StorableClass]
    39   public sealed class SingleObjectiveTestFunctionPathRelinker : PathRelinker {
     42  public sealed class SingleObjectiveTestFunctionPathRelinker : SingleObjectivePathRelinker {
    4043    #region Parameter properties
    4144    public IValueParameter<IntValue> RelinkingIntensityParameter {
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/SimilarityCalculators/SingleObjectiveTestFunctionSimilarityCalculator.cs

    r8304 r8319  
    3232  /// An operator that performs similarity calculation between two test functions solutions.
    3333  /// </summary>
     34  /// <remarks>
     35  /// The operator calculates the similarity based on the euclidean distance of the two solutions in n-dimensional space.
     36  /// </remarks>
    3437  [Item("SingleObjectiveTestFunctionSimilarityCalculator", "An operator that performs similarity calculation between two test functions solutions.")]
    3538  [StorableClass]
    36   public sealed class SingleObjectiveTestFunctionSimilarityCalculator : SimilarityCalculator {
     39  public sealed class SingleObjectiveTestFunctionSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
    3740    #region Properties
    3841    [Storable]
     
    5760      if (bounds == null)
    5861        throw new ArgumentException("Cannot calculate similarity because no bounds were provided.");
     62      if (left.Length != right.Length)
     63        throw new ArgumentException("Cannot calculate similarity because the provided solutions have different lengths.");
    5964      if (left == right) return 1.0;
    6065
     
    7277    }
    7378
    74     public override double CalculateIndividualSimilarity(IScope left, IScope right) {
    75       var sol1 = left.Variables[Target].Value as RealVector;
    76       var sol2 = right.Variables[Target].Value as RealVector;
     79    public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) {
     80      var sol1 = leftSolution.Variables[SolutionVariableName].Value as RealVector;
     81      var sol2 = rightSolution.Variables[SolutionVariableName].Value as RealVector;
    7782
    7883      return CalculateSimilarity(sol1, sol2, Bounds);
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r8086 r8319  
    363363        op.MaximizationParameter.Hidden = true;
    364364      }
    365       foreach (var op in Operators.OfType<IRealVectorMultiNeighborhoodShakingOperator>()) {
    366         op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    367         op.RealVectorParameter.Hidden = true;
    368       }
    369       foreach (IImprovementOperator op in Operators.OfType<IImprovementOperator>()) {
    370         op.TargetParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    371         op.TargetParameter.Hidden = true;
    372       }
    373       foreach (IPathRelinker op in Operators.OfType<IPathRelinker>()) {
     365      foreach (IRealVectorMultiNeighborhoodShakingOperator op in Operators.OfType<IRealVectorMultiNeighborhoodShakingOperator>()) {
     366        op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
     367        op.RealVectorParameter.Hidden = true;
     368      }
     369      foreach (ISingleObjectiveImprovementOperator op in Operators.OfType<ISingleObjectiveImprovementOperator>()) {
     370        op.SolutionParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
     371        op.SolutionParameter.Hidden = true;
     372      }
     373      foreach (ISingleObjectivePathRelinker op in Operators.OfType<ISingleObjectivePathRelinker>()) {
    374374        op.ParentsParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    375375        op.ParentsParameter.Hidden = true;
    376376      }
    377       foreach (SingleObjectiveTestFunctionSimilarityCalculator op in Operators.OfType<ISimilarityCalculator>()) {
    378         op.Target = SolutionCreator.RealVectorParameter.ActualName;
     377      foreach (SingleObjectiveTestFunctionSimilarityCalculator op in Operators.OfType<SingleObjectiveTestFunctionSimilarityCalculator>()) {
     378        op.SolutionVariableName = SolutionCreator.RealVectorParameter.ActualName;
    379379        op.Bounds = Bounds;
    380380      }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/Improvers/TSPImprovementOperator.cs

    r8086 r8319  
    3434  /// An operator that improves traveling salesman solutions.
    3535  /// </summary>
     36  /// <remarks>
     37  /// The operator tries to improve the traveling salesman solution by swapping two randomly chosen edges for a certain number of times.
     38  /// </remarks>
    3639  [Item("TSPImprovementOperator", "An operator that improves traveling salesman solutions.")]
    3740  [StorableClass]
    38   public sealed class TSPImprovementOperator : SingleSuccessorOperator, IImprovementOperator {
     41  public sealed class TSPImprovementOperator : SingleSuccessorOperator, ISingleObjectiveImprovementOperator {
    3942    #region Parameter properties
    4043    public ScopeParameter CurrentScopeParameter {
     
    5053      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    5154    }
    52     public IValueLookupParameter<IItem> TargetParameter {
    53       get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
     55    public IValueLookupParameter<IItem> SolutionParameter {
     56      get { return (IValueLookupParameter<IItem>)Parameters["Solution"]; }
    5457    }
    5558    #endregion
     
    8386      Parameters.Add(new ValueParameter<IntValue>("ImprovementAttempts", "The number of improvement attempts the operator should perform.", new IntValue(100)));
    8487      Parameters.Add(new LookupParameter<IRandom>("Random", "A pseudo random number generator."));
    85       Parameters.Add(new ValueLookupParameter<IItem>("Target", "This parameter is used for name translation only."));
     88      Parameters.Add(new ValueLookupParameter<IItem>("Solution", "The solution to be improved. This parameter is used for name translation only."));
    8689      #endregion
    8790    }
     
    9295
    9396    public override IOperation Apply() {
    94       Permutation currSol = CurrentScope.Variables[TargetParameter.ActualName].Value as Permutation;
     97      Permutation currSol = CurrentScope.Variables[SolutionParameter.ActualName].Value as Permutation;
    9598      if (currSol == null)
    9699        throw new ArgumentException("Cannot improve solution because it has the wrong type.");
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers/TSPMultipleGuidesPathRelinker.cs

    r8086 r8319  
    3535  /// An operator that relinks paths between traveling salesman solutions using a multiple guiding strategy.
    3636  /// </summary>
     37  /// <remarks>
     38  /// The operator incrementally changes the initiating solution towards the guiding solution by correcting edges as needed. For each city it choses the best edge from all guiding solutions.
     39  /// </remarks>
    3740  [Item("TSPMultipleGuidesPathRelinker", "An operator that relinks paths between traveling salesman solutions using a multiple guiding strategy.")]
    3841  [StorableClass]
    39   public sealed class TSPMultipleGuidesPathRelinker : PathRelinker {
     42  public sealed class TSPMultipleGuidesPathRelinker : SingleObjectivePathRelinker {
    4043    #region Parameter properties
    4144    public ILookupParameter<DistanceMatrix> DistanceMatrixParameter {
     
    9396          }
    9497        });
    95         Invert(v1, i, bestCityIndex);
     98        Invert(v1, currCityIndex + 1, bestCityIndex);
    9699        solutions.Add(v1.Clone() as Permutation);
    97100      }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers/TSPPathRelinker.cs

    r7789 r8319  
    3434  /// An operator that relinks paths between traveling salesman solutions.
    3535  /// </summary>
     36  /// <remarks>
     37  /// The operator incrementally assimilates the initiating solution into the guiding solution by correcting edges as needed.
     38  /// </remarks>
    3639  [Item("TSPPathRelinker", "An operator that relinks paths between traveling salesman solutions.")]
    3740  [StorableClass]
    38   public sealed class TSPPathRelinker : PathRelinker {
     41  public sealed class TSPPathRelinker : SingleObjectivePathRelinker {
    3942    [StorableConstructor]
    4043    private TSPPathRelinker(bool deserializing) : base(deserializing) { }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers/TSPSimultaneousPathRelinker.cs

    r7789 r8319  
    3434  /// An operator that relinks paths between traveling salesman solutions starting from both ends.
    3535  /// </summary>
     36  /// <remarks>
     37  /// The operator incrementally assimilates the initiating solution into the guiding solution and vice versa by correcting edges as needed.
     38  /// </remarks>
    3639  [Item("TSPSimultaneousPathRelinker", "An operator that relinks paths between traveling salesman solutions starting from both ends.")]
    3740  [StorableClass]
    38   public sealed class TSPSimultaneousPathRelinker : PathRelinker {
     41  public sealed class TSPSimultaneousPathRelinker : SingleObjectivePathRelinker {
    3942    [StorableConstructor]
    4043    private TSPSimultaneousPathRelinker(bool deserializing) : base(deserializing) { }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/SimilarityCalculators/TSPSimilarityCalculator.cs

    r8304 r8319  
    3030  /// An operator that performs similarity calculation between two traveling salesman solutions.
    3131  /// </summary>
     32  /// <remarks>
     33  /// The operator calculates the similarity based on the number of edges the two solutions have in common.
     34  /// </remarks>
    3235  [Item("TSPSimilarityCalculator", "An operator that performs similarity calculation between two traveling salesman solutions.")]
    33   public sealed class TSPSimilarityCalculator : SimilarityCalculator {
     36  public sealed class TSPSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
    3437    private TSPSimilarityCalculator(bool deserializing) : base(deserializing) { }
    3538    private TSPSimilarityCalculator(TSPSimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
     
    4346      if (left == null || right == null)
    4447        throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null.");
    45       if (left == right) return 1.0;
     48      if (left.PermutationType != right.PermutationType)
     49        throw new ArgumentException("Cannot calculate similarity because the provided solutions have different types.");
     50      if (left.Length != right.Length)
     51        throw new ArgumentException("Cannot calculate similarity because the provided solutions have different lengths.");
     52      var comparer = new PermutationEqualityComparer();
     53      if (object.ReferenceEquals(left, right) || comparer.Equals(left, right)) return 1.0;
    4654
     55      switch (left.PermutationType) {
     56        case PermutationTypes.Absolute:
     57          return CalculateAbsolute(left, right);
     58        case PermutationTypes.RelativeDirected:
     59          return CalculateRelativeDirected(left, right);
     60        case PermutationTypes.RelativeUndirected:
     61          return CalculateRelativeUndirected(left, right);
     62        default:
     63          throw new InvalidOperationException("unknown permutation type");
     64      }
     65    }
     66
     67    private static double CalculateAbsolute(Permutation left, Permutation right) {
     68      double similarity = 0.0;
     69      for (int i = 0; i < left.Length && left[i] == right[i]; similarity = ++i) ;
     70      return similarity / left.Length;
     71    }
     72
     73    private static double CalculateRelativeDirected(Permutation left, Permutation right) {
     74      throw new NotImplementedException();
     75    }
     76
     77    private static double CalculateRelativeUndirected(Permutation left, Permutation right) {
    4778      int[,] edges = new int[right.Length, 2];
    4879      for (int i = 0; i < right.Length; i++) {
     
    6192    }
    6293
    63     public override double CalculateIndividualSimilarity(IScope left, IScope right) {
    64       var sol1 = left.Variables[Target].Value as Permutation;
    65       var sol2 = right.Variables[Target].Value as Permutation;
     94    public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) {
     95      var sol1 = leftSolution.Variables[SolutionVariableName].Value as Permutation;
     96      var sol2 = rightSolution.Variables[SolutionVariableName].Value as Permutation;
    6697
    6798      return CalculateSimilarity(sol1, sol2);
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs

    r8086 r8319  
    342342        op.PermutationParameter.Hidden = true;
    343343      }
    344       foreach (IImprovementOperator op in Operators.OfType<IImprovementOperator>()) {
    345         op.TargetParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
    346         op.TargetParameter.Hidden = true;
    347       }
    348       foreach (IPathRelinker op in Operators.OfType<IPathRelinker>()) {
     344      foreach (ISingleObjectiveImprovementOperator op in Operators.OfType<ISingleObjectiveImprovementOperator>()) {
     345        op.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     346        op.SolutionParameter.Hidden = true;
     347      }
     348      foreach (ISingleObjectivePathRelinker op in Operators.OfType<ISingleObjectivePathRelinker>()) {
    349349        op.ParentsParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
    350350        op.ParentsParameter.Hidden = true;
    351351      }
    352       foreach (ISimilarityCalculator op in Operators.OfType<ISimilarityCalculator>()) {
    353         op.Target = SolutionCreator.PermutationParameter.ActualName;
     352      foreach (TSPSimilarityCalculator op in Operators.OfType<TSPSimilarityCalculator>()) {
     353        op.SolutionVariableName = SolutionCreator.PermutationParameter.ActualName;
    354354      }
    355355    }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/Improvers/VRPImprovementOperator.cs

    r8086 r8319  
    3737  [Item("VRPImprovementOperator", "An operator that improves vehicle routing solutions.")]
    3838  [StorableClass]
    39   public sealed class VRPImprovementOperator : SingleSuccessorOperator, IImprovementOperator {
     39  public sealed class VRPImprovementOperator : SingleSuccessorOperator, ISingleObjectiveImprovementOperator {
    4040    #region Parameter properties
    4141    public ILookupParameter<DoubleValue> CapacityParameter {
     
    9090      get { return (ILookupParameter<DoubleValue>)Parameters["EvalTardinessPenalty"]; }
    9191    }
    92     public IValueLookupParameter<IItem> TargetParameter {
    93       get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
     92    public IValueLookupParameter<IItem> SolutionParameter {
     93      get { return (IValueLookupParameter<IItem>)Parameters["Solution"]; }
    9494    }
    9595    public ILookupParameter<DoubleValue> EvalTimeFactorParameter {
     
    127127      Parameters.Add(new LookupParameter<DoubleArray>("ServiceTime", "The service time of each customer."));
    128128      Parameters.Add(new LookupParameter<DoubleValue>("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation."));
    129       Parameters.Add(new ValueLookupParameter<IItem>("Target", "This parameter is used for name translation only."));
     129      Parameters.Add(new ValueLookupParameter<IItem>("Solution", "The solution to be improved. This parameter is used for name translation only."));
    130130      Parameters.Add(new LookupParameter<DoubleValue>("EvalTimeFactor", "The time factor considered in the evaluation."));
    131131      Parameters.Add(new LookupParameter<BoolValue>("UseDistanceMatrix", "True if a distance matrix should be calculated and used for evaluation, otherwise false"));
     
    139139
    140140    public override IOperation Apply() {
    141       AlbaEncoding solution = TargetParameter.ActualValue is AlbaEncoding ?
    142         TargetParameter.ActualValue as AlbaEncoding :
    143         AlbaEncoding.ConvertFrom(TargetParameter.ActualValue as IVRPEncoding, VehiclesParameter.ActualValue.Value, DistanceMatrixParameter);
     141      AlbaEncoding solution = SolutionParameter.ActualValue is AlbaEncoding ?
     142        SolutionParameter.ActualValue as AlbaEncoding :
     143        AlbaEncoding.ConvertFrom(SolutionParameter.ActualValue as IVRPEncoding, VehiclesParameter.ActualValue.Value, DistanceMatrixParameter);
    144144
    145145      if (solution == null)
     
    156156        EvalTardinessPenaltyParameter.ActualValue, UseDistanceMatrixParameter.ActualValue);
    157157
    158       TargetParameter.ActualValue = PotvinEncoding.ConvertFrom(solution, DistanceMatrixParameter);
     158      SolutionParameter.ActualValue = PotvinEncoding.ConvertFrom(solution, DistanceMatrixParameter);
    159159      CurrentScopeParameter.ActualValue.Variables.Add(new Variable("LocalEvaluatedSolutions", new IntValue(evaluatedSolutions)));
    160160
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/PathRelinkers/VRPPathRelinker.cs

    r8086 r8319  
    3939  [Item("VRPPathRelinker", "An operator that relinks paths between vehicle routing solutions.")]
    4040  [StorableClass]
    41   public sealed class VRPPathRelinker : PathRelinker, IStochasticOperator {
     41  public sealed class VRPPathRelinker : SingleObjectivePathRelinker, IStochasticOperator {
    4242    #region Parameters
    4343    public ILookupParameter<DoubleMatrix> CoordinatesParameter {
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/SimilarityCalculators/VRPSimilarityCalculator.cs

    r8304 r8319  
    3333  /// An operator that performs similarity calculation between two vehicle routing solutions.
    3434  /// </summary>
     35  /// <remarks>
     36  /// The operator calculates the similarity based on the number of edges the two solutions have in common.
     37  /// </remarks>
    3538  [Item("VRPSimilarityCalculator", "An operator that performs similarity calculation between two vehicle routing solutions.")]
    36   public sealed class VRPSimilarityCalculator : SimilarityCalculator {
     39  public sealed class VRPSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
    3740    private VRPSimilarityCalculator(bool deserializing) : base(deserializing) { }
    3841    private VRPSimilarityCalculator(VRPSimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
     
    7881    }
    7982
    80     public override double CalculateIndividualSimilarity(IScope left, IScope right) {
    81       var sol1 = left.Variables[Target].Value as PotvinEncoding;
    82       var sol2 = right.Variables[Target].Value as PotvinEncoding;
     83    public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) {
     84      var sol1 = leftSolution.Variables[SolutionVariableName].Value as PotvinEncoding;
     85      var sol2 = rightSolution.Variables[SolutionVariableName].Value as PotvinEncoding;
    8386
    8487      return CalculateSimilarity(sol1, sol2);
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/VehicleRoutingProblem.cs

    r8086 r8319  
    518518      }
    519519
    520       foreach (var op in Operators.OfType<IVRPMultiNeighborhoodShakingOperator>()) {
     520      foreach (IVRPMultiNeighborhoodShakingOperator op in Operators.OfType<IVRPMultiNeighborhoodShakingOperator>()) {
    521521        op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
    522522      }
    523       foreach (IImprovementOperator op in Operators.OfType<IImprovementOperator>()) {
    524         op.TargetParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
    525         op.TargetParameter.Hidden = true;
    526       }
    527       foreach (IPathRelinker op in Operators.OfType<IPathRelinker>()) {
     523      foreach (ISingleObjectiveImprovementOperator op in Operators.OfType<ISingleObjectiveImprovementOperator>()) {
     524        op.SolutionParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
     525        op.SolutionParameter.Hidden = true;
     526      }
     527      foreach (ISingleObjectivePathRelinker op in Operators.OfType<ISingleObjectivePathRelinker>()) {
    528528        op.ParentsParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
    529529        op.ParentsParameter.Hidden = true;
    530530      }
    531       foreach (ISimilarityCalculator op in Operators.OfType<ISimilarityCalculator>()) {
    532         op.Target = SolutionCreator.VRPToursParameter.ActualName;
     531      foreach (VRPSimilarityCalculator op in Operators.OfType<VRPSimilarityCalculator>()) {
     532        op.SolutionVariableName = SolutionCreator.VRPToursParameter.ActualName;
    533533      }
    534534    }
Note: See TracChangeset for help on using the changeset viewer.