Changeset 11245
- Timestamp:
- 07/30/14 16:37:39 (10 years ago)
- Location:
- branches/HeuristicLab.Problems.Orienteering
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering.Views/3.3/HeuristicLab.Problems.Orienteering.Views-3.3.csproj
r11235 r11245 102 102 <Name>HeuristicLab.Optimization-3.3</Name> 103 103 </ProjectReference> 104 <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj"> 105 <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project> 106 <Name>HeuristicLab.Parameters-3.3</Name> 107 </ProjectReference> 104 108 <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj"> 105 109 <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project> -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringProblemView.Designer.cs
r11189 r11245 44 44 this.parametersTabPage = new System.Windows.Forms.TabPage(); 45 45 this.visualizationTabPage = new System.Windows.Forms.TabPage(); 46 //this.pathTourView = new HeuristicLab.Problems.Orienteering.Views.PathTourView();46 this.orienteeringSolutionView = new HeuristicLab.Problems.Orienteering.Views.OrienteeringSolutionView(); 47 47 ((System.ComponentModel.ISupportInitialize)(this.problemInstanceSplitContainer)).BeginInit(); 48 48 this.problemInstanceSplitContainer.Panel1.SuspendLayout(); … … 101 101 // visualizationTabPage 102 102 // 103 //this.visualizationTabPage.Controls.Add(this.pathTourView);103 this.visualizationTabPage.Controls.Add(this.orienteeringSolutionView); 104 104 this.visualizationTabPage.Location = new System.Drawing.Point(4, 22); 105 105 this.visualizationTabPage.Name = "visualizationTabPage"; … … 110 110 this.visualizationTabPage.UseVisualStyleBackColor = true; 111 111 // 112 // pathTourView112 // orienteeringSolutionView 113 113 // 114 //this.pathTourView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)115 //| System.Windows.Forms.AnchorStyles.Left)116 //| System.Windows.Forms.AnchorStyles.Right)));117 //this.pathTourView.Caption = "PathTourView";118 //this.pathTourView.Content = null;119 //this.pathTourView.Location = new System.Drawing.Point(6, 6);120 //this.pathTourView.Name = "pathTourView";121 //this.pathTourView.ReadOnly = false;122 //this.pathTourView.Size = new System.Drawing.Size(491, 268);123 //this.pathTourView.TabIndex = 0;114 this.orienteeringSolutionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 115 | System.Windows.Forms.AnchorStyles.Left) 116 | System.Windows.Forms.AnchorStyles.Right))); 117 this.orienteeringSolutionView.Caption = "OrienteeringSolution View"; 118 this.orienteeringSolutionView.Content = null; 119 this.orienteeringSolutionView.Location = new System.Drawing.Point(6, 6); 120 this.orienteeringSolutionView.Name = "orienteeringSolutionView"; 121 this.orienteeringSolutionView.ReadOnly = false; 122 this.orienteeringSolutionView.Size = new System.Drawing.Size(491, 268); 123 this.orienteeringSolutionView.TabIndex = 0; 124 124 // 125 125 // TravelingSalesmanProblemView … … 147 147 private System.Windows.Forms.TabPage parametersTabPage; 148 148 private System.Windows.Forms.TabPage visualizationTabPage; 149 //private PathTourView pathTourView;149 private OrienteeringSolutionView orienteeringSolutionView; 150 150 } 151 151 } -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringProblemView.cs
r11189 r11245 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.MainForm; 23 24 using HeuristicLab.Optimization.Views; … … 36 37 InitializeComponent(); 37 38 } 39 40 protected override void DeregisterContentEvents() { 41 Content.CoordinatesParameter.ValueChanged -= new EventHandler(CoordinatesParameter_ValueChanged); 42 Content.ScoresParameter.ValueChanged -= new EventHandler(ScoresParameter_ValueChanged); 43 Content.BestKnownQualityParameter.ValueChanged -= new EventHandler(BestKnownQualityParameter_ValueChanged); 44 Content.BestKnownSolutionParameter.ValueChanged -= new EventHandler(BestKnownSolutionParameter_ValueChanged); 45 base.DeregisterContentEvents(); 46 } 47 protected override void RegisterContentEvents() { 48 base.RegisterContentEvents(); 49 Content.CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged); 50 Content.ScoresParameter.ValueChanged += new EventHandler(ScoresParameter_ValueChanged); 51 Content.BestKnownQualityParameter.ValueChanged += new EventHandler(BestKnownQualityParameter_ValueChanged); 52 Content.BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged); 53 } 54 55 protected override void OnContentChanged() { 56 base.OnContentChanged(); 57 if (Content == null) { 58 orienteeringSolutionView.Content = null; 59 } else { 60 orienteeringSolutionView.Content = new OrienteeringSolution(Content.BestKnownSolution, Content.Coordinates, Content.Scores, Content.BestKnownQuality); 61 } 62 } 63 64 protected override void SetEnabledStateOfControls() { 65 base.SetEnabledStateOfControls(); 66 orienteeringSolutionView.Enabled = Content != null; 67 } 68 69 private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) { 70 orienteeringSolutionView.Content.Coordinates = Content.Coordinates; 71 } 72 private void ScoresParameter_ValueChanged(object sender, EventArgs e) { 73 orienteeringSolutionView.Content.Scores = Content.Scores; 74 } 75 private void BestKnownQualityParameter_ValueChanged(object sender, EventArgs e) { 76 orienteeringSolutionView.Content.Quality = Content.BestKnownQuality; 77 } 78 private void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) { 79 orienteeringSolutionView.Content.IntegerVector = Content.BestKnownSolution; 80 } 38 81 } 39 82 } -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringSolutionView.cs
r11240 r11245 84 84 var bitmap = new Bitmap(pictureBox.Width, pictureBox.Height); 85 85 86 if ((coordinates != null) && (coordinates.Rows > 0) && (coordinates.Columns == 2)) { 86 if ((coordinates != null) && (coordinates.Rows > 0) && (coordinates.Columns == 2) 87 && (scores != null) && (coordinates.Rows == scores.Length)) { 87 88 double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue; 88 89 for (int i = 0; i < coordinates.Rows; i++) { … … 116 117 for (int i = 0; i < points.Length; i++) { 117 118 double score = scores[i]; 118 int size = (int)Math.Round(((score - scoreMin) / scoreRange) * 9 + 1);119 int size = (int)Math.Round(((score - scoreMin) / scoreRange) * 8 + 2); 119 120 graphics.FillRectangle(Brushes.Red, points[i].X - size / 2, points[i].Y - size / 2, size, size); 120 121 } -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/Improvers/OrienteeringLocalImprovementOperator.cs
r11242 r11245 130 130 131 131 Parameters.Add(new ValueParameter<IntValue>("MaximumBlockLength", "The maximum length of the 2-opt shortening.", new IntValue(30))); 132 Parameters.Add(new ValueParameter<BoolValue>("UseMaximumBlockLength", "Use a limitation of the length for the 2-opt shortening.", new BoolValue( true)));132 Parameters.Add(new ValueParameter<BoolValue>("UseMaximumBlockLength", "Use a limitation of the length for the 2-opt shortening.", new BoolValue(false))); 133 133 } 134 134 -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs
r11226 r11245 21 21 22 22 using System; 23 using System.IO; 23 24 using System.Linq; 24 25 using HeuristicLab.Common; … … 43 44 44 45 #region Parameter Properties 45 public OptionalValueParameter<DoubleMatrix> CoordinatesParameter {46 get { return ( OptionalValueParameter<DoubleMatrix>)Parameters["Coordinates"]; }46 public ValueParameter<DoubleMatrix> CoordinatesParameter { 47 get { return (ValueParameter<DoubleMatrix>)Parameters["Coordinates"]; } 47 48 } 48 49 public ValueParameter<DistanceMatrix> DistanceMatrixParameter { … … 122 123 public OrienteeringProblem() 123 124 : base(new OrienteeringEvaluator(), new GreedyOrienteeringTourCreator()) { 124 Parameters.Add(new OptionalValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the points."));125 Parameters.Add(new ValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the points.")); 125 126 Parameters.Add(new ValueParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the points.")); 126 127 Parameters.Add(new ValueParameter<IntValue>("StartingPoint", "Index of the starting point.", new IntValue(0))); 127 128 Parameters.Add(new ValueParameter<IntValue>("TerminusPoint", "Index of the ending point.", new IntValue(0))); 128 129 Parameters.Add(new ValueParameter<DoubleValue>("MaximumDistance", "The maximum distance constraint for a Orienteering solution.")); 129 Parameters.Add(new ValueParameter<DoubleArray>("Scores", "The scores of the points." , new DoubleArray()));130 Parameters.Add(new ValueParameter<DoubleArray>("Scores", "The scores of the points.")); 130 131 Parameters.Add(new ValueParameter<DoubleValue>("FixedPenalty", "The penalty for each visited vertex.")); 131 132 Parameters.Add(new OptionalValueParameter<IntegerVector>("BestKnownSolution", "The best known solution of this Orienteering instance.")); … … 323 324 324 325 public void Load(CVRPData data) { 325 if (data.Coordinates == null && data.Distances == null) 326 throw new System.IO.InvalidDataException("The given instance specifies neither coordinates nor distances!"); 327 if (data.Coordinates != null && data.Coordinates.GetLength(1) != 2) 328 throw new System.IO.InvalidDataException("The coordinates of the given instance are not in the right format, there need to be one row for each customer and two columns for the x and y coordinates."); 326 327 if (data.Coordinates == null) 328 throw new InvalidDataException("The given instance specifies no coordinates!"); 329 if (data.Coordinates.GetLength(1) != 2) 330 throw new InvalidDataException("The coordinates of the given instance are not in the right format, there need to be one row for each customer and two columns for the x and y coordinates."); 331 332 // Clear old solutions 333 BestKnownQuality = null; 334 BestKnownSolution = null; 329 335 330 336 Name = data.Name; 331 337 Description = data.Description; 332 338 333 Coordinates = data.Coordinates != null ? new DoubleMatrix(data.Coordinates) : null;334 if ( Coordinates == null)339 Coordinates = new DoubleMatrix(data.Coordinates); 340 if (data.Distances != null) 335 341 DistanceMatrix = new DistanceMatrix(data.Distances); 342 else 343 CalculateDistanceMatrix(); 344 336 345 StartingPoint = new IntValue(0);// Depot is interpreted as start and endpoint (default) 337 346 TerminusPoint = new IntValue(0); 338 347 339 MaximumDistance = new DoubleValue(data.Capacity ); // capacity is interpreted as max distance348 MaximumDistance = new DoubleValue(data.Capacity * 2); // capacity is interpreted as max distance 340 349 Scores = new DoubleArray(data.Demands); // demands are interpreted as scores 341 350 342 BestKnownQuality = null; 343 BestKnownSolution = null; 351 352 353 OnReset(); 344 354 } 345 355 } -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/Shakers/OrienteeringShakingOperator.cs
r11235 r11245 126 126 var random = RandomParameter.ActualValue; 127 127 128 // Limit the neighborhood to the tour length 129 int maxNeighborhood = CurrentNeighborhoodIndexParameter.ActualValue.Value + 1; 130 int limit = initialTour.Length - 3; 131 int neighborhood = random.Next((limit > maxNeighborhood) ? maxNeighborhood : limit) + 1; 132 133 // Find all points that are not yet included in the tour and are 134 // within the maximum distance allowed (ellipse) 135 // and sort them with regard to their utility 136 var visitablePoints = ( 137 from point in Enumerable.Range(0, numPoints) 138 // Calculate the distance when going from the starting point to this point and then to the end point 139 let distance = distances[startingPoint, point] + distances[point, terminusPoint] + fixedPenalty 140 // If this distance is feasible and the point is neither starting nor ending point, check the point 141 where distance < maxDistance && point != startingPoint && point != terminusPoint 142 // The point was not yet visited, so add it to the candidate list 143 where !initialTour.Contains(point) 144 // Calculate the utility of the point at this position 145 let utility = scores[point] 146 orderby utility 147 select point 148 ).ToList(); 149 150 // Initialize the new tour 151 var actualTour = new List<int> { startingPoint }; 152 153 // Perform the insertions according to the utility sorting 154 InsertPoints(actualTour, initialTour, neighborhood, visitablePoints, random); 155 156 // Bring the tour back to be feasible 157 CleanupTour(actualTour, distances, maxDistance, fixedPenalty); 158 159 // Set new Tour 160 IntegerVectorParameter.ActualValue = new IntegerVector(actualTour.ToArray()); 128 if (initialTour.Length > 2) { 129 // Limit the neighborhood to the tour length 130 int maxNeighborhood = CurrentNeighborhoodIndexParameter.ActualValue.Value + 1; 131 int limit = initialTour.Length - 3; // neighborhood limit within [0, length-1) 132 int neighborhood = random.Next((limit > maxNeighborhood) ? maxNeighborhood : limit) + 1; 133 134 // Find all points that are not yet included in the tour and are 135 // within the maximum distance allowed (ellipse) 136 // and sort them with regard to their utility 137 var visitablePoints = ( 138 from point in Enumerable.Range(0, numPoints) 139 // Calculate the distance when going from the starting point to this point and then to the end point 140 let distance = distances[startingPoint, point] + distances[point, terminusPoint] + fixedPenalty 141 // If this distance is feasible and the point is neither starting nor ending point, check the point 142 where distance < maxDistance && point != startingPoint && point != terminusPoint 143 // The point was not yet visited, so add it to the candidate list 144 where !initialTour.Contains(point) 145 // Calculate the utility of the point at this position 146 let utility = scores[point] 147 orderby utility 148 select point 149 ).ToList(); 150 151 // Initialize the new tour 152 var actualTour = new List<int> { startingPoint }; 153 154 // Perform the insertions according to the utility sorting 155 InsertPoints(actualTour, initialTour, neighborhood, visitablePoints, random); 156 157 // Bring the tour back to be feasible 158 CleanupTour(actualTour, distances, maxDistance, fixedPenalty); 159 160 // Set new Tour 161 IntegerVectorParameter.ActualValue = new IntegerVector(actualTour.ToArray()); 162 } 161 163 162 164 return base.Apply(); … … 198 200 } 199 201 200 int randomIndex = random.Next(visitablePoints.Count - 1);202 int randomIndex = random.Next(visitablePoints.Count); 201 203 actualTour.Add(visitablePoints[randomIndex]); 202 204 visitablePoints.Clear();
Note: See TracChangeset
for help on using the changeset viewer.