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)/HeuristicLab.Problems.Knapsack/3.3
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.