Changeset 8319 for branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/Improvers/KnapsackImprovementOperator.cs
- Timestamp:
- 07/24/12 15:04:37 (12 years ago)
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.