Changeset 17712
- Timestamp:
- 08/04/20 07:06:39 (4 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Moves/VRPMoveEvaluator.cs
r17698 r17712 20 20 #endregion 21 21 22 using HEAL.Attic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 25 26 using HeuristicLab.Optimization; 26 27 using HeuristicLab.Parameters; 27 using HEAL.Attic;28 28 using HeuristicLab.Problems.VehicleRouting.Interfaces; 29 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 29 30 30 31 namespace HeuristicLab.Problems.VehicleRouting.Encodings.General { … … 43 44 get { return (ILookupParameter<DoubleValue>)Parameters["MovePenalty"]; } 44 45 } 46 public ILookupParameter<VRPEvaluation> MoveEvaluationResultParameter { 47 get { return (ILookupParameter<VRPEvaluation>)Parameters["MoveEvaluationResult"]; } 48 } 45 49 46 50 [StorableConstructor] … … 52 56 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move.")); 53 57 Parameters.Add(new LookupParameter<DoubleValue>("MovePenalty", "The penalty applied to the move.")); 58 Parameters.Add(new LookupParameter<VRPEvaluation>("MoveEvaluationResult", "The evaluation result of the move.")); 54 59 } 55 60 … … 60 65 //helper method to evaluate an updated individual 61 66 protected void UpdateEvaluation(IVRPEncodedSolution updatedTours) { 62 IVRPEvaluator evaluator = ProblemInstance.MoveEvaluator; 63 64 try { 65 this.ExecutionContext.Scope.Variables.Add(new Variable(evaluator.VRPToursParameter.ActualName, 66 updatedTours)); 67 68 IAtomicOperation op = this.ExecutionContext.CreateChildOperation(evaluator); 69 op.Operator.Execute((IExecutionContext)op, CancellationToken); 70 } 71 finally { 72 this.ExecutionContext.Scope.Variables.Remove(evaluator.VRPToursParameter.ActualName); 73 } 67 var evaluation = ProblemInstance.Evaluate(updatedTours); 68 MoveEvaluationResultParameter.ActualValue = evaluation; 69 MoveQualityParameter.ActualValue = new DoubleValue(evaluation.Quality); 70 MovePenaltyParameter.ActualValue = new DoubleValue(evaluation.Penalty); 74 71 } 75 72 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Moves/VRPMoveMaker.cs
r17226 r17712 20 20 #endregion 21 21 22 using System.Collections.Generic;22 using HEAL.Attic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; … … 26 26 using HeuristicLab.Optimization; 27 27 using HeuristicLab.Parameters; 28 using HEAL.Attic; 29 using HeuristicLab.Problems.VehicleRouting.Interfaces; 28 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 30 29 31 30 namespace HeuristicLab.Problems.VehicleRouting.Encodings.General { … … 36 35 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 37 36 } 37 public ILookupParameter<VRPEvaluation> EvaluationResultParameter { 38 get { return (ILookupParameter<VRPEvaluation>)Parameters["EvaluationResult"]; } 39 } 38 40 public ILookupParameter<DoubleValue> MoveQualityParameter { 39 41 get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; } … … 41 43 public ILookupParameter<DoubleValue> MovePenaltyParameter { 42 44 get { return (ILookupParameter<DoubleValue>)Parameters["MovePenalty"]; } 45 } 46 public ILookupParameter<VRPEvaluation> MoveEvaluationResultParameter { 47 get { return (ILookupParameter<VRPEvaluation>)Parameters["MoveEvaluationResult"]; } 43 48 } 44 49 … … 49 54 : base() { 50 55 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the solution.")); 56 Parameters.Add(new LookupParameter<VRPEvaluation>("EvaluationResult", "The evaluation of the solution.")); 51 57 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move.")); 52 58 Parameters.Add(new LookupParameter<DoubleValue>("MovePenalty", "The penalty applied to the move.")); 59 Parameters.Add(new LookupParameter<VRPEvaluation>("MoveEvaluationResult", "The move evaluation.")); 53 60 } 54 61 … … 60 67 61 68 private void UpdateMoveEvaluation() { 62 IVRPEvaluator evaluator = ProblemInstance.SolutionEvaluator; 63 ICollection<IParameter> addedParameters = new List<IParameter>(); 64 65 try { 66 foreach (IParameter parameter in evaluator.Parameters) { 67 if (parameter is ILookupParameter 68 && parameter != evaluator.VRPToursParameter 69 && parameter != evaluator.ProblemInstanceParameter) { 70 ILookupParameter evaluatorParameter = parameter as ILookupParameter; 71 72 string resultName = evaluatorParameter.ActualName; 73 if (!this.Parameters.ContainsKey(resultName)) { 74 ILookupParameter resultParameter = new LookupParameter<IItem>(resultName); 75 resultParameter.ExecutionContext = ExecutionContext; 76 this.Parameters.Add(resultParameter); 77 addedParameters.Add(resultParameter); 78 } 79 80 string moveResultName = VRPMoveEvaluator.MovePrefix + resultName; 81 if (!this.Parameters.ContainsKey(moveResultName)) { 82 ILookupParameter moveResultParameter = new LookupParameter<IItem>(moveResultName); 83 moveResultParameter.ExecutionContext = ExecutionContext; 84 this.Parameters.Add(moveResultParameter); 85 addedParameters.Add(moveResultParameter); 86 } 87 88 ILookupParameter result = Parameters[resultName] as ILookupParameter; 89 ILookupParameter moveResult = Parameters[moveResultName] as ILookupParameter; 90 result.ActualValue = moveResult.ActualValue; 91 } 92 } 93 } finally { 94 foreach (IParameter parameter in addedParameters) { 95 this.Parameters.Remove(parameter); 96 } 97 } 69 EvaluationResultParameter.ActualValue = MoveEvaluationResultParameter.ActualValue; 70 QualityParameter.ActualValue = MoveQualityParameter.ActualValue; 98 71 } 99 72 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Creators/PushForwardInsertionCreator.cs
r17698 r17712 22 22 using System; 23 23 using System.Collections.Generic; 24 using HEAL.Attic; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 27 28 using HeuristicLab.Optimization; 28 29 using HeuristicLab.Parameters; 29 using HEAL.Attic;30 30 using HeuristicLab.Problems.VehicleRouting.Interfaces; 31 31 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; … … 299 299 } else { 300 300 double cost = tourCost; 301 bool feasible = problemInstance.Feasible(eval); 302 if (cost < minimumCost && feasible) { 301 if (cost < minimumCost && eval.IsFeasible) { 303 302 customer = unrouted; 304 303 minimumCost = cost; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinCrossover.cs
r17698 r17712 21 21 22 22 using System.Collections.Generic; 23 using HEAL.Attic; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 26 27 using HeuristicLab.Optimization; 27 28 using HeuristicLab.Parameters; 28 using HEAL.Attic;29 29 using HeuristicLab.Problems.VehicleRouting.Encodings.General; 30 30 using HeuristicLab.Problems.VehicleRouting.Interfaces; … … 134 134 solution.Tours.Remove(tour); 135 135 } 136 137 if (newTour.Stops.Count > 0 && !allowInfeasible && ! instance.TourFeasible(newTour, solution))136 var tourEval = instance.EvaluateTour(newTour, solution); 137 if (newTour.Stops.Count > 0 && !allowInfeasible && !tourEval.IsFeasible) 138 138 return false; 139 139 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinInsertionBasedCrossover.cs
r17698 r17712 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using HEAL.Attic; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Core; 24 using HEAL.Attic;25 using System.Collections.Generic;26 27 using HeuristicLab.Data; 27 using System;28 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Problems.VehicleRouting.Interfaces; 29 30 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 30 using HeuristicLab.Problems.VehicleRouting.Interfaces;31 31 32 32 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin { … … 165 165 double minDetour = 0; 166 166 VRPEvaluation eval = ProblemInstance.EvaluateTour(tour, individual); 167 bool originalFeasible = ProblemInstance.Feasible(eval);168 167 169 168 for (int i = 0; i <= tour.Stops.Count; i++) { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinLocalSearchManipulator.cs
r17698 r17712 21 21 22 22 using System.Collections.Generic; 23 using HEAL.Attic; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Data; 26 27 using HeuristicLab.Parameters; 27 using HEAL.Attic;28 28 using HeuristicLab.Problems.VehicleRouting.Interfaces; 29 29 … … 70 70 distance = individual.GetTourLength(individual.Tours[currentTour]); 71 71 individual.Tours[currentTour].Stops.InsertRange(currentCity, toBeDeleted); 72 if (instance.TourFeasible(individual.Tours[currentTour], individual)) { 72 var tourEval = instance.EvaluateTour(individual.Tours[currentTour], individual); 73 if (tourEval.IsFeasible) { 73 74 double lengthIncrease = 74 75 individual.GetTourLength(individual.Tours[currentTour]) - distance; … … 94 95 public static void ApplyManipulation(IRandom random, PotvinEncodedSolution individual, IVRPProblemInstance instance, int maxIterations) { 95 96 //only apply to feasible individuals 96 if (instance.Feasible(individual)) { 97 var eval = instance.Evaluate(individual); 98 if (eval.IsFeasible) { 97 99 bool insertionFound; 98 100 int iterations = 0; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinPairwiseOneLevelExchangeManipulator.cs
r17698 r17712 20 20 #endregion 21 21 22 using HEAL.Attic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 using H EAL.Attic;25 using HeuristicLab.Problems.VehicleRouting.Interfaces; 25 26 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 26 27 using HeuristicLab.Problems.VehicleRouting.Variants; 27 using HeuristicLab.Problems.VehicleRouting.Interfaces;28 28 29 29 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin { … … 88 88 89 89 if (delta < bestQuality && 90 ( instance.Feasible(evalNew)|| allowInfeasible)) {90 (evalNew.IsFeasible || allowInfeasible)) { 91 91 bestQuality = delta; 92 92 bestTour = tourIdx; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinPairwiseTwoLevelExchangeManipulator.cs
r17698 r17712 20 20 #endregion 21 21 22 using HEAL.Attic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Encodings.PermutationEncoding; 25 using H EAL.Attic;26 using HeuristicLab.Problems.VehicleRouting.Interfaces; 26 27 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 27 28 using HeuristicLab.Problems.VehicleRouting.Variants; 28 using HeuristicLab.Problems.VehicleRouting.Interfaces;29 29 30 30 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin { … … 77 77 78 78 replacedSourceTour.Stops[replacedSourceTour.Stops.IndexOf(replacedSource)] = replacingSource; 79 if (!allowInfeasible && !instance.TourFeasible(replacedSourceTour, individual)) 79 var evalSourceTour = instance.EvaluateTour(replacedSourceTour, individual); 80 if (!allowInfeasible && !evalSourceTour.IsFeasible) 80 81 return null; 81 82 83 var evalTargetTour = instance.EvaluateTour(replacedTargetTour, individual); 82 84 replacedTargetTour.Stops[replacedTargetTour.Stops.IndexOf(replacedTarget)] = replacingTarget; 83 if (!allowInfeasible && ! instance.TourFeasible(replacedTargetTour, individual))85 if (!allowInfeasible && !evalTargetTour.IsFeasible) 84 86 return null; 85 87 … … 101 103 102 104 if (delta < bestQuality && 103 ( instance.Feasible(evalNew)|| allowInfeasible)) {105 (evalNew.IsFeasible || allowInfeasible)) { 104 106 bestQuality = delta; 105 107 bestTour = tourIdx; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinTwoLevelExchangeManipulator.cs
r17698 r17712 20 20 #endregion 21 21 22 using HEAL.Attic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 using HEAL.Attic;25 25 using HeuristicLab.Problems.VehicleRouting.Interfaces; 26 26 … … 62 62 route1.Stops.RemoveAt(customer1Position); 63 63 64 if (instance.TourFeasible(tour, individual)) { 64 var tourEval = instance.EvaluateTour(tour, individual); 65 if (tourEval.IsFeasible) { 65 66 int routeIdx, place; 66 67 if (FindInsertionPlace(individual, -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncodedSolution.cs
r17698 r17712 219 219 220 220 VRPEvaluation eval = ProblemInstance.Evaluate(this); 221 bool originalFeasible = ProblemInstance.Feasible(eval);222 221 223 222 for (int tour = 0; tour < Tours.Count; tour++) { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/PrinsEncodedSolution.cs
r17698 r17712 66 66 67 67 double cost = eval.Quality; 68 feasible = ProblemInstance.Feasible(eval);68 feasible = eval.IsFeasible; 69 69 70 70 if (feasible || j == i) { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Zhu/ZhuEncodedSolution.cs
r17698 r17712 45 45 int city = this[i] + 1; 46 46 newTour.Stops.Add(city); 47 if (!ProblemInstance.TourFeasible(newTour, this)) { 47 var evalNewTour = ProblemInstance.EvaluateTour(newTour, this); 48 if (!evalNewTour.IsFeasible) { 48 49 newTour.Stops.Remove(city); 49 50 if (newTour.Stops.Count > 0) -
branches/2521_ProblemRefactoring/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GAVrpSampleTest.cs
r17226 r17712 79 79 instance.TardinessPenalty.Value = 100; 80 80 instance.TimeFactor.Value = 0; 81 vrpProblem.MaximizationParameter.Value.Value = false;82 81 instance.UseDistanceMatrix.Value = true; 83 82 instance.Vehicles.Value = 25;
Note: See TracChangeset
for help on using the changeset viewer.