- Timestamp:
- 07/24/12 15:04:37 (12 years ago)
- 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 35 35 /// An operator that improves knapsack solutions. 36 36 /// </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> 37 41 [Item("KnapsackImprovementOperator", "An operator that improves knapsack solutions.")] 38 42 [StorableClass] 39 public sealed class KnapsackImprovementOperator : SingleSuccessorOperator, I ImprovementOperator {43 public sealed class KnapsackImprovementOperator : SingleSuccessorOperator, ISingleObjectiveImprovementOperator { 40 44 #region Parameter properties 41 45 public ScopeParameter CurrentScopeParameter { … … 48 52 get { return (ILookupParameter<DoubleValue>)Parameters["Penalty"]; } 49 53 } 50 public IValueLookupParameter<IItem> TargetParameter {51 get { return (IValueLookupParameter<IItem>)Parameters[" Target"]; }54 public IValueLookupParameter<IItem> SolutionParameter { 55 get { return (IValueLookupParameter<IItem>)Parameters["Solution"]; } 52 56 } 53 57 public ILookupParameter<IntArray> ValuesParameter { … … 90 94 Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity", "Capacity of the Knapsack.")); 91 95 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.")); 93 97 Parameters.Add(new LookupParameter<IntArray>("Values", "The values of the items.")); 94 98 Parameters.Add(new LookupParameter<IntArray>("Weights", "The weights of the items.")); … … 101 105 102 106 public override IOperation Apply() { 103 BinaryVector sol = CurrentScope.Variables[ TargetParameter.ActualName].Value as BinaryVector;107 BinaryVector sol = CurrentScope.Variables[SolutionParameter.ActualName].Value as BinaryVector; 104 108 if (sol == null) 105 109 throw new ArgumentException("Cannot improve solution because it has the wrong type."); … … 143 147 } 144 148 145 CurrentScope.Variables[ TargetParameter.ActualName].Value = sol;149 CurrentScope.Variables[SolutionParameter.ActualName].Value = sol; 146 150 CurrentScope.Variables.Add(new Variable("LocalEvaluatedSolutions", new IntValue(evaluatedSolutions))); 147 151 -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r8086 r8319 291 291 op.ValuesParameter.Hidden = true; 292 292 } 293 foreach ( var op in Operators.OfType<IBinaryVectorMultiNeighborhoodShakingOperator>()) {293 foreach (IBinaryVectorMultiNeighborhoodShakingOperator op in Operators.OfType<IBinaryVectorMultiNeighborhoodShakingOperator>()) { 294 294 op.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName; 295 295 op.BinaryVectorParameter.Hidden = true; 296 296 } 297 foreach (I ImprovementOperator op in Operators.OfType<IImprovementOperator>()) {298 op. TargetParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName;299 op. TargetParameter.Hidden = true;300 } 301 foreach (I PathRelinker 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>()) { 302 302 op.ParentsParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName; 303 303 op.ParentsParameter.Hidden = true; 304 304 } 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; 307 307 } 308 308 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/PathRelinkers/KnapsackPathRelinker.cs
r7789 r8319 34 34 /// An operator that relinks paths between knapsack solutions. 35 35 /// </summary> 36 /// <remarks> 37 /// The operator incrementally assimilates the initiating solution into the guiding solution by adding and removing elements as needed. 38 /// </remarks> 36 39 [Item("KnapsackPathRelinker", "An operator that relinks paths between knapsack solutions.")] 37 40 [StorableClass] 38 public sealed class KnapsackPathRelinker : PathRelinker {41 public sealed class KnapsackPathRelinker : SingleObjectivePathRelinker { 39 42 [StorableConstructor] 40 43 private KnapsackPathRelinker(bool deserializing) : base(deserializing) { } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/PathRelinkers/KnapsackSimultaneousPathRelinker.cs
r7789 r8319 34 34 /// An operator that relinks paths between knapsack solutions starting from both ends. 35 35 /// </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> 36 39 [Item("KnapsackSimultaneousPathRelinker", "An operator that relinks paths between knapsack solutions starting from both ends.")] 37 40 [StorableClass] 38 public sealed class KnapsackSimultaneousPathRelinker : PathRelinker {41 public sealed class KnapsackSimultaneousPathRelinker : SingleObjectivePathRelinker { 39 42 [StorableConstructor] 40 43 private KnapsackSimultaneousPathRelinker(bool deserializing) : base(deserializing) { } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/SimilarityCalculators/KnapsackSimilarityCalculator.cs
r8304 r8319 30 30 /// An operator that performs similarity calculation between two knapsack solutions. 31 31 /// </summary> 32 /// <remarks> 33 /// The operator calculates the similarity based on the number of elements the two solutions have in common. 34 /// </remarks> 32 35 [Item("KnapsackSimilarityCalculator", "An operator that performs similarity calculation between two knapsack solutions.")] 33 public sealed class KnapsackSimilarityCalculator : Si milarityCalculator {36 public sealed class KnapsackSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 34 37 private KnapsackSimilarityCalculator(bool deserializing) : base(deserializing) { } 35 38 private KnapsackSimilarityCalculator(KnapsackSimilarityCalculator original, Cloner cloner) : base(original, cloner) { } … … 43 46 if (left == null || right == null) 44 47 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."); 45 50 if (left == right) return 1.0; 46 51 … … 51 56 } 52 57 53 public override double Calculate IndividualSimilarity(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; 56 61 57 62 return CalculateSimilarity(sol1, sol2);
Note: See TracChangeset
for help on using the changeset viewer.