Changeset 8894 for trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Improver/VRPImprovementOperator.cs
- Timestamp:
- 11/12/12 13:32:46 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Improver/VRPImprovementOperator.cs
r8346 r8894 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 29 using HeuristicLab.Problems.VehicleRouting.Encodings; 30 using HeuristicLab.Problems.VehicleRouting.Encodings.Alba;31 30 using HeuristicLab.Problems.VehicleRouting.Encodings.Potvin; 32 31 using HeuristicLab.Problems.VehicleRouting.Interfaces; … … 35 34 namespace HeuristicLab.Problems.VehicleRouting { 36 35 /// <summary> 37 /// A n operator that improves vehicle routingsolutions.36 /// A base class for operators which improve VRP solutions. 38 37 /// </summary> 39 [Item("VRPImprovementOperator", "A n operator that improves vehicle routingsolutions.")]38 [Item("VRPImprovementOperator", "A base class for operators which improve VRP solutions.")] 40 39 [StorableClass] 41 public sealedclass VRPImprovementOperator : VRPOperator, IGeneralVRPOperator, ISingleObjectiveImprovementOperator {40 public abstract class VRPImprovementOperator : VRPOperator, IGeneralVRPOperator, ISingleObjectiveImprovementOperator { 42 41 #region Parameter properties 43 42 public ScopeParameter CurrentScopeParameter { … … 47 46 get { return (IValueParameter<IntValue>)Parameters["ImprovementAttempts"]; } 48 47 } 49 public IValue Parameter<IntValue> LambdaParameter{50 get { return (IValue Parameter<IntValue>)Parameters["Lambda"]; }48 public IValueLookupParameter<IntValue> LocalEvaluatedSolutions { 49 get { return (IValueLookupParameter<IntValue>)Parameters["LocalEvaluatedSolutions"]; } 51 50 } 52 51 public ILookupParameter<IRandom> RandomParameter { … … 62 61 63 62 [StorableConstructor] 64 pr ivateVRPImprovementOperator(bool deserializing) : base(deserializing) { }65 pr ivateVRPImprovementOperator(VRPImprovementOperator original, Cloner cloner) : base(original, cloner) { }66 p ublicVRPImprovementOperator()63 protected VRPImprovementOperator(bool deserializing) : base(deserializing) { } 64 protected VRPImprovementOperator(VRPImprovementOperator original, Cloner cloner) : base(original, cloner) { } 65 protected VRPImprovementOperator() 67 66 : base() { 68 67 #region Create parameters 69 68 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the solution to be improved.")); 70 69 Parameters.Add(new ValueParameter<IntValue>("ImprovementAttempts", "The number of improvement attempts the operator should perform.", new IntValue(100))); 71 Parameters.Add(new Value Parameter<IntValue>("Lambda", "The number of neighbors that should be exchanged.", new IntValue(1)));70 Parameters.Add(new ValueLookupParameter<IntValue>("LocalEvaluatedSolutions", "The number of evaluated solutions.")); 72 71 Parameters.Add(new LookupParameter<IRandom>("Random", "A pseudo random number generator.")); 73 Parameters.Add(new ValueParameter<IntValue>("SampleSize", "The number of moves that should be executed.", new IntValue( 100)));72 Parameters.Add(new ValueParameter<IntValue>("SampleSize", "The number of moves that should be executed.", new IntValue(25))); 74 73 Parameters.Add(new ValueLookupParameter<IItem>("Solution", "The solution to be improved. This parameter is used for name translation only.")); 75 74 #endregion 76 75 } 77 76 78 public override IDeepCloneable Clone(Cloner cloner) {79 return new VRPImprovementOperator(this, cloner);80 }81 82 77 public override IOperation Apply() { 83 AlbaEncoding solution = SolutionParameter.ActualValue is AlbaEncoding 84 ? SolutionParameter.ActualValue as AlbaEncoding 85 : AlbaEncoding.ConvertFrom(SolutionParameter.ActualValue as IVRPEncoding, ProblemInstance); 78 var solution = SolutionParameter.ActualValue as IVRPEncoding; 79 var potvinSolution = solution is PotvinEncoding ? solution as PotvinEncoding : PotvinEncoding.ConvertFrom(solution, ProblemInstance); 86 80 87 81 if (solution == null) 88 82 throw new ArgumentException("Cannot improve solution because it has the wrong type."); 89 83 90 double quality = -1; 91 int evaluatedSolutions; 84 int evaluatedSolutions = Improve(potvinSolution); 92 85 93 AlbaLambdaInterchangeLocalImprovementOperator.Apply(solution, ImprovementAttemptsParameter.Value.Value, 94 LambdaParameter.Value.Value, SampleSizeParameter.Value.Value, 95 RandomParameter.ActualValue, ProblemInstance, ref quality, 96 out evaluatedSolutions); 97 98 SolutionParameter.ActualValue = PotvinEncoding.ConvertFrom(solution, ProblemInstance); 99 CurrentScopeParameter.ActualValue.Variables.Add(new Variable("LocalEvaluatedSolutions", new IntValue(evaluatedSolutions))); 86 SolutionParameter.ActualValue = solution; 87 LocalEvaluatedSolutions.ActualValue = new IntValue(evaluatedSolutions); 100 88 101 89 return base.Apply(); 102 90 } 91 92 protected abstract int Improve(PotvinEncoding solution); 103 93 } 104 94 }
Note: See TracChangeset
for help on using the changeset viewer.