- Timestamp:
- 07/28/11 14:16:21 (13 years ago)
- Location:
- branches/VRP
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting.Views/3.4/HeuristicLab.Problems.VehicleRouting.Views-3.4.csproj
r5867 r6607 197 197 <Name>HeuristicLab.MainForm-3.3</Name> 198 198 </ProjectReference> 199 <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj"> 200 <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project> 201 <Name>HeuristicLab.Operators-3.3</Name> 202 </ProjectReference> 199 203 <ProjectReference Include="..\..\HeuristicLab.Optimization.Views\3.3\HeuristicLab.Optimization.Views-3.3.csproj"> 200 204 <Project>{662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}</Project> -
branches/VRP/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPSolutionView.Designer.cs
r5867 r6607 29 29 this.tabPage2 = new System.Windows.Forms.TabPage(); 30 30 this.tourGroupBox = new System.Windows.Forms.GroupBox(); 31 this. tourGridView = new System.Windows.Forms.DataGridView();31 this.valueTextBox = new System.Windows.Forms.TextBox(); 32 32 this.tabControl1.SuspendLayout(); 33 33 this.tabPage1.SuspendLayout(); 34 34 this.tabPage2.SuspendLayout(); 35 35 this.tourGroupBox.SuspendLayout(); 36 ((System.ComponentModel.ISupportInitialize)(this.tourGridView)).BeginInit();37 36 this.SuspendLayout(); 38 37 // … … 84 83 // tourGroupBox 85 84 // 86 this.tourGroupBox.Controls.Add(this. tourGridView);85 this.tourGroupBox.Controls.Add(this.valueTextBox); 87 86 this.tourGroupBox.Dock = System.Windows.Forms.DockStyle.Fill; 88 87 this.tourGroupBox.Location = new System.Drawing.Point(3, 3); … … 93 92 this.tourGroupBox.Text = "Tour"; 94 93 // 95 // tourGridView94 // valueTextBox 96 95 // 97 this. tourGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;98 this. tourGridView.Dock = System.Windows.Forms.DockStyle.Fill;99 this. tourGridView.Location = new System.Drawing.Point(3, 16);100 this. tourGridView.Name = "tourGridView";101 this. tourGridView.Size = new System.Drawing.Size(448, 364);102 this. tourGridView.TabIndex = 0;96 this.valueTextBox.Dock = System.Windows.Forms.DockStyle.Fill; 97 this.valueTextBox.Location = new System.Drawing.Point(3, 16); 98 this.valueTextBox.Multiline = true; 99 this.valueTextBox.Name = "valueTextBox"; 100 this.valueTextBox.Size = new System.Drawing.Size(403, 507); 101 this.valueTextBox.TabIndex = 0; 103 102 // 104 103 // VRPSolutionView … … 112 111 this.tabPage2.ResumeLayout(false); 113 112 this.tourGroupBox.ResumeLayout(false); 114 ((System.ComponentModel.ISupportInitialize)(this.tourGridView)).EndInit();115 113 this.ResumeLayout(false); 116 114 … … 124 122 private System.Windows.Forms.TabPage tabPage2; 125 123 private System.Windows.Forms.GroupBox tourGroupBox; 126 private System.Windows.Forms. DataGridView tourGridView;124 private System.Windows.Forms.TextBox valueTextBox; 127 125 } 128 126 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPSolutionView.cs
r4374 r6607 32 32 namespace HeuristicLab.Problems.VehicleRouting.Views { 33 33 [View("VRPSolution View")] 34 [Content(typeof(VRPSolution), true)] 35 public partial class VRPSolutionView 34 [Content(typeof(VRPSolution), true)] 35 public partial class VRPSolutionView: HeuristicLab.Core.Views.ItemView { 36 36 public new VRPSolution Content { 37 37 get { return (VRPSolution)base.Content; } 38 38 set { base.Content = value; } 39 } 39 } 40 40 41 41 public VRPSolutionView() { … … 91 91 92 92 private void UpdateTourView() { 93 tourGridView.Rows.Clear(); 94 tourGridView.ColumnCount = Content.ProblemInstance.Coordinates.Rows - 1; 93 StringBuilder sb = new StringBuilder(); 95 94 96 95 if (Content != null && Content.Solution != null) { 97 96 foreach (Tour tour in Content.Solution.GetTours()) { 98 int row = tourGridView.Rows.Add();99 int cell = 0;100 97 foreach (int city in tour.Stops) { 101 tourGridView.Rows[row].Cells[cell].Value = city;102 cell++;98 sb.Append(city); 99 sb.Append(" "); 103 100 } 101 sb.AppendLine(); 104 102 } 105 103 } 104 105 valueTextBox.Text = sb.ToString(); 106 106 } 107 107 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestSolution/BestVRPSolutionAnalyzer.cs
r5867 r6607 153 153 else 154 154 results.Add(new Result("Best valid VRP Solution", validSolution)); 155 156 results.Add(new Result("Best valid VRP Solution Distance", new DoubleValue(distances[i].Value))); 157 results.Add(new Result("Best valid VRP Solution VehicleUtilization", new DoubleValue(vehiclesUtilizations[i].Value))); 155 158 } 156 159 } else { … … 160 163 validSolution.Solution = best.Clone() as IVRPEncoding; 161 164 validSolution.Quality.Value = qualities[i].Value; 165 (results["Best valid VRP Solution Distance"].Value as DoubleValue).Value = distances[i].Value; 166 (results["Best valid VRP Solution VehicleUtilization"].Value as DoubleValue).Value = vehiclesUtilizations[i].Value; 162 167 } 163 168 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Moves/LambdaInterchange/AlbaStochasticLambdaInterchangeMutliMoveGenerator.cs
r5867 r6607 62 62 } 63 63 64 protected override AlbaLambdaInterchangeMove[] GenerateMoves(AlbaEncoding individual, IVRPProblemInstance problemInstance, int lambda) { 65 int sampleSize = SampleSizeParameter.ActualValue.Value; 66 64 public static AlbaLambdaInterchangeMove[] GenerateAllMoves(AlbaEncoding individual, IVRPProblemInstance problemInstance, int lambda, int sampleSize, IRandom rand) { 67 65 AlbaLambdaInterchangeMove[] moves = new AlbaLambdaInterchangeMove[sampleSize]; 68 66 for (int i = 0; i < sampleSize; i++) { 69 67 moves[i] = AlbaStochasticLambdaInterchangeSingleMoveGenerator.Apply( 70 individual, problemInstance.Cities.Value, lambda, RandomParameter.ActualValue);68 individual, problemInstance.Cities.Value, lambda, rand); 71 69 } 72 70 73 71 return moves; 74 72 } 73 74 protected override AlbaLambdaInterchangeMove[] GenerateMoves(AlbaEncoding individual, IVRPProblemInstance problemInstance, int lambda) { 75 return GenerateAllMoves(individual, problemInstance, lambda, SampleSizeParameter.Value.Value, RandomParameter.ActualValue); 76 } 75 77 } 76 78 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Moves/VRPMoveMaker.cs
r5127 r6607 74 74 75 75 string resultName = evaluatorParameter.ActualName; 76 if (!this.Parameters. Exists(p => p.Name ==resultName)) {76 if (!this.Parameters.ContainsKey(resultName)) { 77 77 ILookupParameter resultParameter = new LookupParameter<IItem>(resultName); 78 78 resultParameter.ExecutionContext = ExecutionContext; … … 82 82 83 83 string moveResultName = VRPMoveEvaluator.MovePrefix + resultName; 84 if (!this.Parameters. Exists(p => p.Name ==moveResultName)) {84 if (!this.Parameters.ContainsKey(moveResultName)) { 85 85 ILookupParameter moveResultParameter = new LookupParameter<IItem>(moveResultName); 86 86 moveResultParameter.ExecutionContext = ExecutionContext; … … 91 91 ILookupParameter result = Parameters[resultName] as ILookupParameter; 92 92 ILookupParameter moveResult = Parameters[moveResultName] as ILookupParameter; 93 result.ActualValue = moveResult.ActualValue .Clone() as IItem;93 result.ActualValue = moveResult.ActualValue; 94 94 } 95 95 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Creators/IterativeInsertionCreator.cs
r5127 r6607 83 83 private static PotvinEncoding CreateSolution(IVRPProblemInstance instance, IRandom random, bool adhereTimeWindows) { 84 84 PotvinEncoding result = new PotvinEncoding(instance); 85 IVRPEvaluator eval = instance.EvaluatorParameter.Value;86 85 87 86 List<int> customers = new List<int>(); … … 105 104 currentTour.Stops.Insert(stopIdx, customers[index]); 106 105 107 CVRPEvaluation evaluation = eval.Evaluate(instance,currentTour) as CVRPEvaluation;106 CVRPEvaluation evaluation = instance.Evaluate(currentTour) as CVRPEvaluation; 108 107 if (result.Tours.Count < instance.Vehicles.Value && 109 ((adhereTimeWindows && ! eval.Feasible(evaluation)) || ((!adhereTimeWindows) && evaluation.Overload > double.Epsilon))) {108 ((adhereTimeWindows && !instance.Feasible(evaluation)) || ((!adhereTimeWindows) && evaluation.Overload > double.Epsilon))) { 110 109 currentTour.Stops.RemoveAt(stopIdx); 111 110 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinCrossover.cs
r4752 r6607 39 39 } 40 40 41 public IValueParameter<BoolValue> AllowInfeasibleSolutions { 42 get { return (IValueParameter<BoolValue>)Parameters["AllowInfeasibleSolutions"]; } 43 } 44 41 45 [StorableConstructor] 42 46 protected PotvinCrossover(bool deserializing) : base(deserializing) { } … … 44 48 public PotvinCrossover() { 45 49 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators.")); 50 Parameters.Add(new ValueParameter<BoolValue>("AllowInfeasibleSolutions", "Indicates if infeasible solutions should be allowed.", new BoolValue(false))); 46 51 } 47 52 … … 52 57 protected abstract PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2); 53 58 54 protected bool FindInsertionPlace(PotvinEncoding individual, int city, out int route, out int place) { 59 protected static bool FindInsertionPlace(PotvinEncoding individual, int city, bool allowInfeasible, 60 out int route, out int place) { 55 61 return individual.FindInsertionPlace( 56 city, -1, out route, out place); 62 city, -1, allowInfeasible, 63 out route, out place); 57 64 } 58 65 … … 70 77 } 71 78 72 protected bool Repair(IRandom random, PotvinEncoding solution, Tour newTour) {79 protected static bool RouteUnrouted(PotvinEncoding solution, bool allowInfeasible) { 73 80 bool success = true; 74 81 int index = 0; 82 while (index < solution.Unrouted.Count && success) { 83 int unrouted = solution.Unrouted[index]; 84 85 int route, place; 86 if (FindInsertionPlace(solution, unrouted, allowInfeasible, 87 out route, out place)) { 88 solution.Tours[route].Stops.Insert(place, unrouted); 89 } else { 90 success = false; 91 } 92 93 index++; 94 } 95 96 for (int i = 0; i < index; i++) 97 solution.Unrouted.RemoveAt(0); 98 99 return success; 100 } 101 102 protected static bool Repair(IRandom random, PotvinEncoding solution, Tour newTour, IVRPProblemInstance instance, bool allowInfeasible) { 103 bool success = true; 104 75 105 //remove duplicates from new tour 76 106 for (int i = 0; i < newTour.Stops.Count; i++) { … … 106 136 } 107 137 138 if (!allowInfeasible && !instance.Feasible(newTour)) 139 return false; 140 108 141 //route unrouted vehicles 109 int index = 0; 110 while (index < solution.Unrouted.Count && success) { 111 int unrouted = solution.Unrouted[index]; 112 113 int route, place; 114 if(FindInsertionPlace(solution, unrouted, out route, out place)) { 115 solution.Tours[route].Stops.Insert(place, unrouted); 116 } else { 117 success = false; 118 } 119 120 index++; 121 } 122 123 for (int i = 0; i < index; i++) 124 solution.Unrouted.RemoveAt(0); 142 success = RouteUnrouted(solution, allowInfeasible); 125 143 126 144 return success; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinRouteBasedCrossover.cs
r4752 r6607 46 46 47 47 protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) { 48 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 49 48 50 PotvinEncoding child = parent2.Clone() as PotvinEncoding; 49 51 … … 61 63 child.Unrouted.Add(city); 62 64 63 if (Repair(random, child, replacing ))65 if (Repair(random, child, replacing, ProblemInstance, allowInfeasible) || allowInfeasible) 64 66 return child; 65 67 else { -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinSequenceBasedCrossover.cs
r4752 r6607 46 46 47 47 protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) { 48 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 49 48 50 PotvinEncoding child = parent1.Clone() as PotvinEncoding; 49 51 Tour newTour = new Tour(); … … 76 78 child.Unrouted.Add(city); 77 79 78 if (ProblemInstance.Feasible(newTour) && 79 Repair(random, child, newTour)) { 80 if (Repair(random, child, newTour, ProblemInstance, allowInfeasible) || allowInfeasible) { 80 81 return child; 81 82 } else { -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinManipulator.cs
r4752 r6607 38 38 } 39 39 40 public IValueParameter<BoolValue> AllowInfeasibleSolutions { 41 get { return (IValueParameter<BoolValue>)Parameters["AllowInfeasibleSolutions"]; } 42 } 43 40 44 [StorableConstructor] 41 45 protected PotvinManipulator(bool deserializing) : base(deserializing) { } … … 43 47 public PotvinManipulator() { 44 48 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators.")); 49 Parameters.Add(new ValueParameter<BoolValue>("AllowInfeasibleSolutions", "Indicates if infeasible solutions should be allowed.", new BoolValue(false))); 45 50 } 46 51 … … 78 83 } 79 84 80 protected bool FindInsertionPlace(PotvinEncoding individual, int city, int routeToAvoid, out int route, out int place) {85 protected bool FindInsertionPlace(PotvinEncoding individual, int city, int routeToAvoid, bool allowInfeasible, out int route, out int place) { 81 86 return individual.FindInsertionPlace( 82 city, routeToAvoid, out route, out place);87 city, routeToAvoid, allowInfeasible, out route, out place); 83 88 } 84 89 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinOneLevelExchangeManipulator.cs
r4752 r6607 46 46 47 47 protected override void Manipulate(IRandom random, PotvinEncoding individual) { 48 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 49 48 50 int selectedIndex = SelectRandomTourBiasedByLength(random, individual); 49 51 Tour route1 = … … 54 56 int insertedRoute, insertedPlace; 55 57 56 if (FindInsertionPlace(individual, route1.Stops[i], selectedIndex, out insertedRoute, out insertedPlace)) {58 if (FindInsertionPlace(individual, route1.Stops[i], selectedIndex, allowInfeasible, out insertedRoute, out insertedPlace)) { 57 59 individual.Tours[insertedRoute].Stops.Insert(insertedPlace, route1.Stops[i]); 58 60 replaced.Add(route1.Stops[i]); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinTwoLevelExchangeManipulator.cs
r5867 r6607 46 46 47 47 protected override void Manipulate(IRandom random, PotvinEncoding individual) { 48 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 49 48 50 int selectedIndex = SelectRandomTourBiasedByLength(random, individual); 49 51 Tour route1 = individual.Tours[selectedIndex]; … … 65 67 int routeIdx, place; 66 68 if (FindInsertionPlace(individual, 67 customer2, selectedIndex, out routeIdx, out place)) {69 customer2, selectedIndex, allowInfeasible, out routeIdx, out place)) { 68 70 individual.Tours[routeIdx].Stops.Insert(place, customer2); 69 71 route1.Stops.RemoveAt(customer1Position); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/CustomerRelocation/PotvinCustomerRelocationMoveMaker.cs
r5867 r6607 106 106 107 107 //reset move quality 108 VRPEvaluation eval = ProblemInstance.Evaluat orParameter.Value.Evaluate(ProblemInstance,newSolution);108 VRPEvaluation eval = ProblemInstance.Evaluate(newSolution); 109 109 MoveQualityParameter.ActualValue.Value = eval.Quality; 110 110 111 111 //update penalty factor 112 112 double sigma = SigmaParameter.Value.Value; 113 if (ProblemInstance. EvaluatorParameter.Value.Feasible(eval)) {113 if (ProblemInstance.Feasible(eval)) { 114 114 newSolution.PenaltyFactor /= (1 + sigma); 115 115 if (newSolution.PenaltyFactor < MinPenaltyFactorParameter.Value.Value) -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncoding.cs
r5202 r6607 80 80 81 81 public double GetTourLength(Tour tour) { 82 double length = 0; 83 84 if (tour.Stops.Count > 0) { 85 List<int> cities = new List<int>(); 86 cities.Add(0); 87 foreach (int city in tour.Stops) { 88 cities.Add(city); 89 } 90 cities.Add(0); 91 92 for (int i = 1; i < cities.Count; i++) { 93 length += ProblemInstance.GetDistance(cities[i - 1], cities[i]); 94 } 95 } 96 97 return length; 82 return tour.GetTourLength(ProblemInstance); 98 83 } 99 84 … … 105 90 tour.Stops.Insert(i, city); 106 91 107 VRPEvaluation eval = ProblemInstance.Evaluat orParameter.Value.Evaluate(ProblemInstance,tour);92 VRPEvaluation eval = ProblemInstance.Evaluate(tour); 108 93 double quality = eval.Quality + eval.Penalty * (PenaltyFactor - 1.0); 109 94 … … 122 107 } 123 108 124 public bool FindInsertionPlace(int city, int routeToAvoid, out int route, out int place) {109 public bool FindInsertionPlace(int city, int routeToAvoid, bool allowInfeasible, out int route, out int place) { 125 110 route = -1; 126 111 place = -1; 127 double minDetour = 0; 112 bool bestFeasible = false; 113 double minDetour = double.MaxValue; 128 114 129 115 for (int tour = 0; tour < Tours.Count; tour++) { 130 116 if (tour != routeToAvoid) { 131 double length = GetTourLength(Tours[tour]); 117 for (int i = 0; i <= Tours[tour].Stops.Count; i++) { 118 double length = GetTourLength(Tours[tour]); 132 119 133 for (int i = 0; i <= Tours[tour].Stops.Count; i++) {134 120 Tours[tour].Stops.Insert(i, city); 135 121 136 VRPEvaluation eval = ProblemInstance.EvaluatorParameter.Value.Evaluate( 137 ProblemInstance, Tours[tour]); 138 if (ProblemInstance.EvaluatorParameter.Value.Feasible(eval)) { 139 double newLength = eval.Distance; 122 bool feasible = ProblemInstance.Feasible(Tours[tour]); 140 123 124 if (feasible || allowInfeasible && !bestFeasible) { 125 double newLength = GetTourLength(Tours[tour]); 141 126 double detour = newLength - length; 142 127 143 if (route < = 0 || detour < minDetour) {128 if (route < 0 || detour < minDetour || feasible && !bestFeasible) { 144 129 route = tour; 145 130 place = i; 146 131 minDetour = detour; 132 133 if (feasible) 134 bestFeasible = true; 147 135 } 148 136 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/Manipulators/PrinsLSManipulator.cs
r4752 r6607 49 49 50 50 protected double GetQuality(PrinsEncoding individual) { 51 return ProblemInstance.Evaluate(individual) ;51 return ProblemInstance.Evaluate(individual).Quality; 52 52 } 53 53 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/PrinsEncoding.cs
r4752 r6607 61 61 62 62 VRPEvaluation eval = 63 ProblemInstance.EvaluatorParameter.Value.Evaluate(ProblemInstance, 64 tour); 63 ProblemInstance.Evaluate(tour); 65 64 66 65 double cost = eval.Quality; 67 feasible = ProblemInstance. EvaluatorParameter.Value.Feasible(eval);66 feasible = ProblemInstance.Feasible(eval); 68 67 69 68 if (feasible) { -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Tour.cs
r4752 r6607 27 27 using HeuristicLab.Common; 28 28 using HeuristicLab.Core; 29 using HeuristicLab.Problems.VehicleRouting.Interfaces; 29 30 30 31 namespace HeuristicLab.Problems.VehicleRouting { … … 46 47 this.Stops = new List<int>(original.Stops); 47 48 } 49 50 public double GetTourLength(IVRPProblemInstance instance) { 51 double length = 0; 52 53 if (Stops.Count > 0) { 54 List<int> cities = new List<int>(); 55 cities.Add(0); 56 foreach (int city in Stops) { 57 cities.Add(city); 58 } 59 cities.Add(0); 60 61 for (int i = 1; i < cities.Count; i++) { 62 length += instance.GetDistance(cities[i - 1], cities[i]); 63 } 64 } 65 66 return length; 67 } 48 68 } 49 69 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/HeuristicLab.Problems.VehicleRouting-3.4.csproj
r6093 r6607 128 128 <Compile Include="Encodings\Alba\Crossovers\AlbaCrossover.cs" /> 129 129 <Compile Include="Encodings\Alba\Crossovers\AlbaPermutationCrossover.cs" /> 130 <Compile Include="Encodings\Alba\LocalImprovement\AlbaLambdaInterchangeLocalImprovementOperator.cs" /> 130 131 <Compile Include="Encodings\Alba\Manipulators\AlbaCustomerInsertionManipulator.cs" /> 131 132 <Compile Include="Encodings\Alba\Manipulators\AlbaCustomerInversionManipulator.cs" /> … … 194 195 <Compile Include="Encodings\Potvin\Creators\IterativeInsertionCreator.cs" /> 195 196 <Compile Include="Encodings\Potvin\Crossovers\PotvinCrossover.cs" /> 197 <Compile Include="Encodings\Potvin\Crossovers\PotvinInsertionBasedCrossover.cs" /> 196 198 <Compile Include="Encodings\Potvin\Crossovers\PotvinRouteBasedCrossover.cs" /> 197 199 <Compile Include="Encodings\Potvin\Crossovers\PotvinSequenceBasedCrossover.cs" /> -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Interfaces/IVRPProblemInstance.cs
r5867 r6607 27 27 using HeuristicLab.Core; 28 28 using HeuristicLab.Data; 29 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 29 30 30 31 namespace HeuristicLab.Problems.VehicleRouting.Interfaces { … … 50 51 bool Feasible(IVRPEncoding solution); 51 52 bool Feasible(Tour tour); 52 double Evaluate(IVRPEncoding solution); 53 double Evaluate(Tour tour); 53 VRPEvaluation Evaluate(IVRPEncoding solution); 54 VRPEvaluation Evaluate(Tour tour); 55 bool Feasible(VRPEvaluation eval); 54 56 } 55 57 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs
r5867 r6607 187 187 return distanceMatrix; 188 188 } 189 189 190 //cache for performance improvement 191 private DoubleMatrix distanceMatrix = null; 192 private IVRPEvaluator evaluator = null; 193 190 194 public double GetDistance(int start, int end) { 191 195 double distance = 0.0; 192 DoubleMatrix distanceMatrix = DistanceMatrix;193 194 196 if (distanceMatrix == null && UseDistanceMatrix.Value) { 195 197 distanceMatrix = DistanceMatrix = CreateDistanceMatrix(); … … 205 207 206 208 public bool Feasible(IVRPEncoding solution) { 207 return EvaluatorParameter.Value.Feasible(208 EvaluatorParameter.Value.Evaluate(209 return evaluator.Feasible( 210 evaluator.Evaluate( 209 211 this, solution)); 210 212 } 211 213 212 214 public bool Feasible(Tour tour) { 213 return EvaluatorParameter.Value.Feasible(214 EvaluatorParameter.Value.Evaluate(215 return evaluator.Feasible( 216 evaluator.Evaluate( 215 217 this, tour)); 216 218 } 217 219 218 public double Evaluate(IVRPEncoding solution) { 219 return EvaluatorParameter.Value.Evaluate(this, solution).Quality; 220 } 221 222 public double Evaluate(Tour tour) { 223 return EvaluatorParameter.Value.Evaluate(this, tour).Quality; 220 public VRPEvaluation Evaluate(IVRPEncoding solution) { 221 return evaluator.Evaluate(this, solution); 222 } 223 224 public VRPEvaluation Evaluate(Tour tour) { 225 return evaluator.Evaluate(this, tour); 226 } 227 228 public bool Feasible(VRPEvaluation eval) { 229 return evaluator.Feasible(eval); 224 230 } 225 231 … … 227 233 if (BestKnownSolution != null) { 228 234 //call evaluator 229 BestKnownQuality = new DoubleValue(Evaluate(BestKnownSolution.Solution) );235 BestKnownQuality = new DoubleValue(Evaluate(BestKnownSolution.Solution).Quality); 230 236 BestKnownSolution.Quality = BestKnownQuality; 231 237 } else { … … 275 281 } 276 282 #endregion 277 283 278 284 AttachEventHandlers(); 279 285 } 280 286 281 287 private void AttachEventHandlers() { 288 evaluator = EvaluatorParameter.Value; 282 289 EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged); 283 290 BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged); … … 298 305 void EvaluatorParameter_ValueChanged(object sender, EventArgs e) { 299 306 moveEvaluator = null; 307 evaluator = EvaluatorParameter.Value; 300 308 } 301 309 … … 322 330 DistanceMatrix.Reset += new EventHandler(DistanceMatrix_Reset); 323 331 } 332 distanceMatrix = DistanceMatrix; 324 333 EvalBestKnownSolution(); 325 334 } … … 328 337 } 329 338 void DistanceMatrix_ItemChanged(object sender, EventArgs<int, int> e) { 339 distanceMatrix = DistanceMatrix; 330 340 EvalBestKnownSolution(); 331 341 } 332 342 void UseDistanceMatrixParameter_ValueChanged(object sender, EventArgs e) { 333 343 UseDistanceMatrix.ValueChanged += new EventHandler(UseDistanceMatrix_ValueChanged); 344 if (!UseDistanceMatrix.Value) 345 distanceMatrix = null; 334 346 EvalBestKnownSolution(); 335 347 } 336 348 void UseDistanceMatrix_ValueChanged(object sender, EventArgs e) { 349 if (!UseDistanceMatrix.Value) 350 distanceMatrix = null; 337 351 EvalBestKnownSolution(); 338 352 }
Note: See TracChangeset
for help on using the changeset viewer.