Free cookie consent management tool by TermsFeed Policy Generator

# Changeset 17529

Ignore:
Timestamp:
05/08/20 11:21:57 (4 years ago)
Message:

#2521: some fixes and reusing handling of distance measure as defined in TSP

Location:
branches/2521_ProblemRefactoring
Files:
6 edited

Unmodified
Removed
• ## branches/2521_ProblemRefactoring/HeuristicLab.Problems.Instances/3.3/Types/VRP/VRPData.cs

 r17226 /// Describes instances of the Vehicle Routing Problem (VRP). /// public class VRPData : IVRPData { /// /// The name of the instance /// public string Name { get; set; } /// /// Optional! The description of the instance /// public string Description { get; set; } /// /// The number of customers and the depot /// public int Dimension { get; set; } /// /// The distance measure that is used to calculate the distance between ///the coordinates if no is given. /// public DistanceMeasure DistanceMeasure { get; set; } public class VRPData : TSPData, IVRPData { /// /// Optional! The maximum number of vehicles that can be used. /// public double? MaximumVehicles { get; set; } /// /// Either Distances or the need to be specified along /// with a distance measure. /// public double[,] Distances { get; set; } /// /// Optional! A a matrix of dimension [N, 2] where each row is either the customer /// or the depot and the columns represent x and y coordinates respectively. /// /// /// Either or the Coordinates need to be specified along /// with a distance measure. /// public double[,] Coordinates { get; set; } /// /// The demand vector that specifies how many goods need to be delivered. /// Optional! The best-known solution as a list of tours in path-encoding. /// public int[][] BestKnownTour { get; set; } public new int[][] BestKnownTour { get; set; } /// /// Optional! Specifies the used vehicle for a given tour. /// public int[] BestKnownTourVehicleAssignment { get; set; } /// /// Optional! The quality of the best-known solution. /// public double? BestKnownQuality { get; set; } /// /// If only the coordinates are given, can calculate the distance matrix. /// /// A full distance matrix between all cities. public double[,] GetDistanceMatrix() { return DistanceHelper.GetDistanceMatrix(DistanceMeasure, Coordinates, Distances, Dimension); } } }
• ## branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringProblemDataView.Designer.cs

 r17526 this.startingPointTextBox = new System.Windows.Forms.TextBox(); this.startingPointLabel = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); this.tabControl.SuspendLayout(); this.routingDataTabPage.SuspendLayout(); this.SuspendLayout(); // // nameTextBox // this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft); this.errorProvider.SetIconPadding(this.nameTextBox, 2); this.nameTextBox.Size = new System.Drawing.Size(454, 20); // // infoLabel // this.infoLabel.Location = new System.Drawing.Point(518, 3); // // tabControl // this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tabControl.Controls.Add(this.routingDataTabPage); this.tabControl.Controls.Add(this.OrienteeringDataTabPage); this.tabControl.Location = new System.Drawing.Point(0, 26); this.tabControl.Dock = System.Windows.Forms.DockStyle.Fill; this.tabControl.Location = new System.Drawing.Point(0, 0); this.tabControl.Name = "tabControl"; this.tabControl.SelectedIndex = 0; this.tabControl.Size = new System.Drawing.Size(541, 401); this.tabControl.Size = new System.Drawing.Size(541, 427); this.tabControl.TabIndex = 0; // this.routingDataTabPage.Name = "routingDataTabPage"; this.routingDataTabPage.Padding = new System.Windows.Forms.Padding(3); this.routingDataTabPage.Size = new System.Drawing.Size(533, 375); this.routingDataTabPage.Size = new System.Drawing.Size(533, 401); this.routingDataTabPage.TabIndex = 0; this.routingDataTabPage.Text = "Routing Data"; this.routingDataViewHost.Name = "routingDataViewHost"; this.routingDataViewHost.ReadOnly = false; this.routingDataViewHost.Size = new System.Drawing.Size(527, 369); this.routingDataViewHost.Size = new System.Drawing.Size(527, 395); this.routingDataViewHost.TabIndex = 0; this.routingDataViewHost.ViewsLabelVisible = true; this.OrienteeringDataTabPage.Name = "OrienteeringDataTabPage"; this.OrienteeringDataTabPage.Padding = new System.Windows.Forms.Padding(3); this.OrienteeringDataTabPage.Size = new System.Drawing.Size(533, 375); this.OrienteeringDataTabPage.Size = new System.Drawing.Size(533, 401); this.OrienteeringDataTabPage.TabIndex = 1; this.OrienteeringDataTabPage.Text = "Orienteering"; this.OrienteeringDataTabPage.Text = "Orienteering Data"; this.OrienteeringDataTabPage.UseVisualStyleBackColor = true; // this.splitContainer1.Panel2.Controls.Add(this.startingPointTextBox); this.splitContainer1.Panel2.Controls.Add(this.startingPointLabel); this.splitContainer1.Size = new System.Drawing.Size(527, 369); this.splitContainer1.Size = new System.Drawing.Size(527, 395); this.splitContainer1.SplitterDistance = 175; this.splitContainer1.TabIndex = 0; this.scoresArrayView.Name = "scoresArrayView"; this.scoresArrayView.ReadOnly = false; this.scoresArrayView.Size = new System.Drawing.Size(169, 341); this.scoresArrayView.Size = new System.Drawing.Size(169, 367); this.scoresArrayView.TabIndex = 1; // this.Name = "OrienteeringProblemDataView"; this.Size = new System.Drawing.Size(541, 427); this.Controls.SetChildIndex(this.tabControl, 0); this.Controls.SetChildIndex(this.nameLabel, 0); this.Controls.SetChildIndex(this.nameTextBox, 0); this.Controls.SetChildIndex(this.infoLabel, 0); ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); this.tabControl.ResumeLayout(false); this.routingDataTabPage.ResumeLayout(false); this.splitContainer1.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); }
• ## branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringProblemDataView.cs

 r17526 [View("Orienteering Problem Data View")] [Content(typeof(OrienteeringProblemData), IsDefaultView = true)] public partial class OrienteeringProblemDataView : NamedItemView { public partial class OrienteeringProblemDataView : ItemView { public new OrienteeringProblemData Content {
• ## branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs

 r17526 BestKnownSolutionParameter.ActualValue = data.GetSolution((IntegerVector)best.Clone(), quality, score, travelCosts); } var bestSoFar = BestOrienteeringSolutionParameter.ActualValue; Description = data.Description; var tsp = data.Coordinates != null ? (ITSPData)new EuclideanTSPData(Name, data.Coordinates) : new MatrixTSPData(Name, data.Distances ?? data.GetDistanceMatrix(), data.Coordinates); var tsp = TSP.GetDataFromInstance(data); OrienteeringProblemData = new OrienteeringProblemData(tsp, data.StartingPoint, data.TerminalPoint, data.Scores, data.MaximumDistance, data.PointVisitingCosts); } var tsp = data.Coordinates != null ? (ITSPData)new EuclideanTSPData(Name, data.Coordinates) : new MatrixTSPData(Name, data.Distances ?? data.GetDistanceMatrix(), data.Coordinates); var tsp = TSP.GetDataFromInstance(data); var avgDist = 0.0; for (var i = 0; i < data.Dimension - 1; i++) Description = data.Description; var tsp = data.Coordinates != null ? (ITSPData)new EuclideanTSPData(Name, data.Coordinates) : new MatrixTSPData(Name, data.Distances ?? data.GetDistanceMatrix(), data.Coordinates); OrienteeringProblemData = new OrienteeringProblemData(tsp, 0, 0, data.Demands, data.Capacity * 2, 0); var tsp = TSP.GetDataFromInstance(data); OrienteeringProblemData = new OrienteeringProblemData(tsp, 0, 0, data.Demands, data.Capacity * 2, 0); } #endregion
• ## branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblemdata.cs

 r17525 ﻿using System; using System.Linq; using HEAL.Attic; using HeuristicLab.Common; } public OrienteeringProblemData() { RoutingData = new EuclideanTSPData("HL OP Default", defaultCoordinates); RoutingData = new MatrixTSPData("HL OP Default", defaultMatrix, defaultCoordinates); Name = RoutingData.Name; StartingPoint = 0; TerminalPoint = 20; Scores = new DoubleArray(Enumerable.Repeat(1.0, RoutingData.Cities).ToArray(), @readonly: true); Scores = new DoubleArray(defaultScores, @readonly: true); MaximumTravelCosts = 30; PointVisitingCosts = 0; if (tspData.Cities != scores.Length) throw new ArgumentException("Unequal number of cities and scores."); if (startingPoint < 0 || startingPoint >= tspData.Cities) throw new ArgumentException("Starting point is not in the range of cities.", "startingPoint"); if (terminalPoint < 0 || terminalPoint >= tspData.Cities) throw new ArgumentException("Starting point is not in the range of cities.", "startingPoint"); if (terminalPoint < 0 || terminalPoint >= tspData.Cities) throw new ArgumentException("Terminal point is not in the range of cities.", "terminalPoint"); RoutingData = tspData; StartingPoint = startingPoint; }; private static double[] defaultScores = new double[21] { 0, 20, 20, 30, 15, 15, 10, 20, 20, 20, 15, 10, 10, 25, 40, 40, 30, 30, 50, 30, 0 }; private static double[,] defaultMatrix = new double[21, 21] { { 0, 4.43846820423443, 5.2038447325030761, 7.4215901261117905, 3.492849839314597, 2.9154759474226513, 1.3152946437965911, 5.0447993022517759, 4.9929950931279725, 3.2893768406797057, 1.878829422805594, 1.3601470508735445, 1.2369316876852983, 2.4698178070456942, 10.983624174196786, 11.860016863394419, 9.2633687176966024, 10.606601717798211, 12.684636376341263, 9.7005154502222215, 1.5524174696260025 }, { 4.43846820423443, 0, 1.5811388300841898, 4.1012193308819764, 2.7313000567495322, 2.7202941017470885, 3.2695565448543631, 2.1377558326431947, 3.4885527085024819, 3.7735924528226423, 3.5510561809129406, 3.2140317359976405, 4.6010868281309367, 5.6885850613311577, 8.2764726786234259, 8.85437744847146, 5.9236812878479537, 6.4031242374328468, 8.3186537372341682, 5.4918120870983929, 5.8420886675914128 }, { 5.2038447325030761, 1.5811388300841898, 0, 2.56124969497314, 2.3323807579381204, 2.6570660511172846, 3.9000000000000004, 3.640054944640259, 5.0606323715519981, 5.2630789467763082, 4.7927027865287037, 4.22018956920184, 5.6753854494650851, 6.89492567037528, 9.4339811320566049, 9.8843310345212529, 6.92314957226839, 6.700746227100379, 8.2619610262939389, 4.5099889135118723, 6.7268120235368558 }, { 7.4215901261117905, 4.1012193308819764, 2.56124969497314, 0, 4.0199502484483558, 4.5541190146942805, 6.11310068623117, 5.990826320300064, 7.5000000000000009, 7.8243210568074222, 7.2945184899347542, 6.6309878600401628, 8.0777472107017569, 9.35200513259055, 11.065260954898443, 11.300442469213319, 8.4291162051546049, 7.2124891681027838, 8.0709355095924291, 3.1400636936215167, 8.9738509013689338 }, { 3.492849839314597, 2.7313000567495322, 2.3323807579381204, 4.0199502484483558, 0, 0.58309518948453, 2.2472205054244236, 4.6529560496527358, 5.6222771187482392, 4.9658836071740557, 3.9204591567825315, 3.041381265149111, 4.360045871318329, 5.7008771254956905, 10.963576058932597, 11.576700738984314, 8.6539008545279739, 8.9140338792266185, 10.580170130957253, 6.6708320320631671, 5.0328918128646487 }, { 2.9154759474226513, 2.7202941017470885, 2.6570660511172846, 4.5541190146942805, 0.58309518948453, 0, 1.6643316977093243, 4.4643028571099421, 5.3000000000000007, 4.4944410108488473, 3.3837848631377261, 2.4839484696748451, 3.7802116342871606, 5.12249938994628, 10.815729286552989, 11.476933388322857, 8.5866174946832228, 9.0553851381374155, 10.816653826391969, 7.1021123618258812, 4.4598206241955527 }, { 1.3152946437965911, 3.2695565448543631, 3.9000000000000004, 6.11310068623117, 2.2472205054244236, 1.6643316977093243, 0, 4.2801869118065383, 4.6173585522460785, 3.306055050963308, 1.9646882704388495, 1.0198039027185573, 2.12602916254693, 3.4713109915419564, 10.509519494249012, 11.301769772916098, 8.5603738236130766, 9.5963534741067118, 11.583177456984764, 8.40535543567314, 2.8635642126552714 }, { 5.0447993022517759, 2.1377558326431947, 3.640054944640259, 5.990826320300064, 4.6529560496527358, 4.4643028571099421, 4.2801869118065383, 0, 1.5620499351813311, 2.8017851452243807, 3.4438350715445125, 3.687817782917155, 4.651881339845203, 5.315072906367325, 6.3568860301251284, 7.0661163307718047, 4.2801869118065383, 5.724508712544683, 7.983107164506813, 6.5764732189829536, 6.0827625302982193 }, { 4.9929950931279725, 3.4885527085024819, 5.0606323715519981, 7.5000000000000009, 5.6222771187482392, 5.3000000000000007, 4.6173585522460785, 1.5620499351813311, 0, 1.9416487838947614, 3.1400636936215172, 3.7576588456111879, 4.2426406871192865, 4.5177427992306081, 5.9908263203000631, 6.8883960397178079, 4.4944410108488446, 6.6610809933523534, 9.0271811768680035, 8.1123362849428275, 5.6639209034025191 }, { 3.2893768406797057, 3.7735924528226423, 5.2630789467763082, 7.8243210568074222, 4.9658836071740557, 4.4944410108488473, 3.306055050963308, 2.8017851452243807, 1.9416487838947614, 0, 1.4317821063276355, 2.3, 2.3600847442411892, 2.5999999999999996, 7.8243210568074222, 8.7726848797845225, 6.4350602172784672, 8.4403791384036762, 10.75174404457249, 9.108238029388561, 3.7483329627982624 }, { 1.878829422805594, 3.5510561809129406, 4.7927027865287037, 7.2945184899347542, 3.9204591567825315, 3.3837848631377261, 1.9646882704388495, 3.4438350715445125, 3.1400636936215172, 1.4317821063276355, 0, 0.94868329805051288, 1.2083045973594577, 2.1377558326431956, 9.12633551870629, 10.026464980241041, 7.5166481891864532, 9.154780172128655, 11.360017605620161, 9.0426765949026411, 2.6419689627245817 }, { 1.3601470508735445, 3.2140317359976405, 4.22018956920184, 6.6309878600401628, 3.041381265149111, 2.4839484696748451, 1.0198039027185573, 3.687817782917155, 3.7576588456111879, 2.3, 0.94868329805051288, 0, 1.456021977856103, 2.7294688127912354, 9.7247107926148644, 10.568348972285122, 7.9246451024635789, 9.2590496272565677, 11.365298060323804, 8.6284413424441855, 2.6305892875931809 }, { 1.2369316876852983, 4.6010868281309367, 5.6753854494650851, 8.0777472107017569, 4.360045871318329, 3.7802116342871606, 2.12602916254693, 4.651881339845203, 4.2426406871192865, 2.3600847442411892, 1.2083045973594577, 1.456021977856103, 0, 1.3453624047073711, 10.182828683622247, 11.119802156513398, 8.6833173384369626, 10.361949623502325, 12.557467897629682, 10.060318086422516, 1.4422205101855958 }, { 2.4698178070456942, 5.6885850613311577, 6.89492567037528, 9.35200513259055, 5.7008771254956905, 5.12249938994628, 3.4713109915419564, 5.315072906367325, 4.5177427992306081, 2.5999999999999996, 2.1377558326431956, 2.7294688127912354, 1.3453624047073711, 0, 10.183319694480774, 11.194641575325221, 9.00499861188218, 11.016351483136328, 13.298120167903432, 11.180339887498949, 1.7117242768623691 }, { 10.983624174196786, 8.2764726786234259, 9.4339811320566049, 11.065260954898443, 10.963576058932597, 10.815729286552989, 10.509519494249012, 6.3568860301251284, 5.9908263203000631, 7.8243210568074222, 9.12633551870629, 9.7247107926148644, 10.182828683622247, 10.183319694480774, 0, 1.1401754250991374, 2.6476404589747466, 5.2630789467763073, 7.1400280111495373, 9.8234413521942532, 11.562439189029277 }, { 11.860016863394419, 8.85437744847146, 9.8843310345212529, 11.300442469213319, 11.576700738984314, 11.476933388322857, 11.301769772916098, 7.0661163307718047, 6.8883960397178079, 8.7726848797845225, 10.026464980241041, 10.568348972285122, 11.119802156513398, 11.194641575325221, 1.1401754250991374, 0, 2.96141857899217, 4.919349550499537, 6.5053823869162377, 9.7529482721892862, 12.52078272313676 }, { 9.2633687176966024, 5.9236812878479537, 6.92314957226839, 8.4291162051546049, 8.6539008545279739, 8.5866174946832228, 8.5603738236130766, 4.2801869118065383, 4.4944410108488446, 6.4350602172784672, 7.5166481891864532, 7.9246451024635789, 8.6833173384369626, 9.00499861188218, 2.6476404589747466, 2.96141857899217, 0, 3.1764760348537169, 5.470831746635973, 7.2449982746719819, 10.121264743103996 }, { 10.606601717798211, 6.4031242374328468, 6.700746227100379, 7.2124891681027838, 8.9140338792266185, 9.0553851381374155, 9.5963534741067118, 5.724508712544683, 6.6610809933523534, 8.4403791384036762, 9.154780172128655, 9.2590496272565677, 10.361949623502325, 11.016351483136328, 5.2630789467763073, 4.919349550499537, 3.1764760348537169, 0, 2.4083189157584615, 5.01597448159378, 11.778370006074693 }, { 12.684636376341263, 8.3186537372341682, 8.2619610262939389, 8.0709355095924291, 10.580170130957253, 10.816653826391969, 11.583177456984764, 7.983107164506813, 9.0271811768680035, 10.75174404457249, 11.360017605620161, 11.365298060323804, 12.557467897629682, 13.298120167903432, 7.1400280111495373, 6.5053823869162377, 5.470831746635973, 2.4083189157584615, 0, 5.2, 13.945967159003352 }, { 9.7005154502222215, 5.4918120870983929, 4.5099889135118723, 3.1400636936215167, 6.6708320320631671, 7.1021123618258812, 8.40535543567314, 6.5764732189829536, 8.1123362849428275, 9.108238029388561, 9.0426765949026411, 8.6284413424441855, 10.060318086422516, 11.180339887498949, 9.8234413521942532, 9.7529482721892862, 7.2449982746719819, 5.01597448159378, 5.2, 0, 11.204017136723776 }, { 1.5524174696260025, 5.8420886675914128, 6.7268120235368558, 8.9738509013689338, 5.0328918128646487, 4.4598206241955527, 2.8635642126552714, 6.0827625302982193, 5.6639209034025191, 3.7483329627982624, 2.6419689627245817, 2.6305892875931809, 1.4422205101855958, 1.7117242768623691, 11.562439189029277, 12.52078272313676, 10.121264743103996, 11.778370006074693, 13.945967159003352, 11.204017136723776, 0 } }; } }
• ## branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/TSPData.cs

 r17525 if (closed) distance += GetDistance(prev, start); return distance; } public double[,] CalculateDistanceMatrix() { var matrix = new double[Cities, Cities]; for (var i = 0; i < Cities; i++) { for (var j = 0; j < Cities; j++) { matrix[i, j] = GetDistance(i, j); } } return matrix; }
Note: See TracChangeset for help on using the changeset viewer.