Changeset 17529


Ignore:
Timestamp:
05/08/20 11:21:57 (2 months ago)
Author:
abeham
Message:

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

Location:
branches/2521_ProblemRefactoring
Files:
6 edited

Legend:

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

    r17226 r17529  
    2525  /// Describes instances of the Vehicle Routing Problem (VRP).
    2626  /// </summary>
    27   public class VRPData : IVRPData {
    28     /// <summary>
    29     /// The name of the instance
    30     /// </summary>
    31     public string Name { get; set; }
    32     /// <summary>
    33     /// Optional! The description of the instance
    34     /// </summary>
    35     public string Description { get; set; }
    36 
    37     /// <summary>
    38     /// The number of customers and the depot
    39     /// </summary>
    40     public int Dimension { get; set; }
    41     /// <summary>
    42     /// The distance measure that is used to calculate the distance between
    43     ///the coordinates if no <see cref="Distances"/> is given.
    44     /// </summary>
    45     public DistanceMeasure DistanceMeasure { get; set; }
     27  public class VRPData : TSPData, IVRPData {
    4628    /// <summary>
    4729    /// Optional! The maximum number of vehicles that can be used.
     
    5335    /// </remarks>
    5436    public double? MaximumVehicles { get; set; }
    55     /// <remarks>
    56     /// Either Distances or the <see cref="Coordinates"/> need to be specified along
    57     /// with a distance measure.
    58     /// </remarks>
    59     public double[,] Distances { get; set; }
    60     /// <summary>
    61     /// Optional! A a matrix of dimension [N, 2] where each row is either the customer
    62     /// or the depot and the columns represent x and y coordinates respectively.
    63     /// </summary>
    64     /// <remarks>
    65     /// Either <see cref="Distances"/> or the Coordinates need to be specified along
    66     /// with a distance measure.
    67     /// </remarks>
    68     public double[,] Coordinates { get; set; }
    6937    /// <summary>
    7038    /// The demand vector that specifies how many goods need to be delivered.
     
    7644    /// Optional! The best-known solution as a list of tours in path-encoding.
    7745    /// </summary>
    78     public int[][] BestKnownTour { get; set; }
     46    public new int[][] BestKnownTour { get; set; }
    7947    /// <summary>
    8048    /// Optional! Specifies the used vehicle for a given tour.
    8149    /// </summary>
    8250    public int[] BestKnownTourVehicleAssignment { get; set; }
    83     /// <summary>
    84     /// Optional! The quality of the best-known solution.
    85     /// </summary>
    86     public double? BestKnownQuality { get; set; }
    87 
    88     /// <summary>
    89     /// If only the coordinates are given, can calculate the distance matrix.
    90     /// </summary>
    91     /// <returns>A full distance matrix between all cities.</returns>
    92     public double[,] GetDistanceMatrix() {
    93       return DistanceHelper.GetDistanceMatrix(DistanceMeasure, Coordinates, Distances, Dimension);
    94     }
    9551  }
    9652}
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringProblemDataView.Designer.cs

    r17526 r17529  
    6060      this.startingPointTextBox = new System.Windows.Forms.TextBox();
    6161      this.startingPointLabel = new System.Windows.Forms.Label();
    62       ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    6362      this.tabControl.SuspendLayout();
    6463      this.routingDataTabPage.SuspendLayout();
     
    7069      this.SuspendLayout();
    7170      //
    72       // nameTextBox
    73       //
    74       this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    75       this.errorProvider.SetIconPadding(this.nameTextBox, 2);
    76       this.nameTextBox.Size = new System.Drawing.Size(454, 20);
    77       //
    78       // infoLabel
    79       //
    80       this.infoLabel.Location = new System.Drawing.Point(518, 3);
    81       //
    8271      // tabControl
    8372      //
    84       this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    85             | System.Windows.Forms.AnchorStyles.Left)
    86             | System.Windows.Forms.AnchorStyles.Right)));
    8773      this.tabControl.Controls.Add(this.routingDataTabPage);
    8874      this.tabControl.Controls.Add(this.OrienteeringDataTabPage);
    89       this.tabControl.Location = new System.Drawing.Point(0, 26);
     75      this.tabControl.Dock = System.Windows.Forms.DockStyle.Fill;
     76      this.tabControl.Location = new System.Drawing.Point(0, 0);
    9077      this.tabControl.Name = "tabControl";
    9178      this.tabControl.SelectedIndex = 0;
    92       this.tabControl.Size = new System.Drawing.Size(541, 401);
     79      this.tabControl.Size = new System.Drawing.Size(541, 427);
    9380      this.tabControl.TabIndex = 0;
    9481      //
     
    9986      this.routingDataTabPage.Name = "routingDataTabPage";
    10087      this.routingDataTabPage.Padding = new System.Windows.Forms.Padding(3);
    101       this.routingDataTabPage.Size = new System.Drawing.Size(533, 375);
     88      this.routingDataTabPage.Size = new System.Drawing.Size(533, 401);
    10289      this.routingDataTabPage.TabIndex = 0;
    10390      this.routingDataTabPage.Text = "Routing Data";
     
    113100      this.routingDataViewHost.Name = "routingDataViewHost";
    114101      this.routingDataViewHost.ReadOnly = false;
    115       this.routingDataViewHost.Size = new System.Drawing.Size(527, 369);
     102      this.routingDataViewHost.Size = new System.Drawing.Size(527, 395);
    116103      this.routingDataViewHost.TabIndex = 0;
    117104      this.routingDataViewHost.ViewsLabelVisible = true;
     
    124111      this.OrienteeringDataTabPage.Name = "OrienteeringDataTabPage";
    125112      this.OrienteeringDataTabPage.Padding = new System.Windows.Forms.Padding(3);
    126       this.OrienteeringDataTabPage.Size = new System.Drawing.Size(533, 375);
     113      this.OrienteeringDataTabPage.Size = new System.Drawing.Size(533, 401);
    127114      this.OrienteeringDataTabPage.TabIndex = 1;
    128       this.OrienteeringDataTabPage.Text = "Orienteering";
     115      this.OrienteeringDataTabPage.Text = "Orienteering Data";
    129116      this.OrienteeringDataTabPage.UseVisualStyleBackColor = true;
    130117      //
     
    150137      this.splitContainer1.Panel2.Controls.Add(this.startingPointTextBox);
    151138      this.splitContainer1.Panel2.Controls.Add(this.startingPointLabel);
    152       this.splitContainer1.Size = new System.Drawing.Size(527, 369);
     139      this.splitContainer1.Size = new System.Drawing.Size(527, 395);
    153140      this.splitContainer1.SplitterDistance = 175;
    154141      this.splitContainer1.TabIndex = 0;
     
    164151      this.scoresArrayView.Name = "scoresArrayView";
    165152      this.scoresArrayView.ReadOnly = false;
    166       this.scoresArrayView.Size = new System.Drawing.Size(169, 341);
     153      this.scoresArrayView.Size = new System.Drawing.Size(169, 367);
    167154      this.scoresArrayView.TabIndex = 1;
    168155      //
     
    259246      this.Name = "OrienteeringProblemDataView";
    260247      this.Size = new System.Drawing.Size(541, 427);
    261       this.Controls.SetChildIndex(this.tabControl, 0);
    262       this.Controls.SetChildIndex(this.nameLabel, 0);
    263       this.Controls.SetChildIndex(this.nameTextBox, 0);
    264       this.Controls.SetChildIndex(this.infoLabel, 0);
    265       ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    266248      this.tabControl.ResumeLayout(false);
    267249      this.routingDataTabPage.ResumeLayout(false);
     
    274256      this.splitContainer1.ResumeLayout(false);
    275257      this.ResumeLayout(false);
    276       this.PerformLayout();
    277258
    278259    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringProblemDataView.cs

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

    r17526 r17529  
    119119        BestKnownSolutionParameter.ActualValue = data.GetSolution((IntegerVector)best.Clone(), quality, score, travelCosts);
    120120      }
    121 
    122121      var bestSoFar = BestOrienteeringSolutionParameter.ActualValue;
    123122     
     
    200199      Description = data.Description;
    201200
    202       var tsp = data.Coordinates != null ? (ITSPData)new EuclideanTSPData(Name, data.Coordinates) : new MatrixTSPData(Name, data.Distances ?? data.GetDistanceMatrix(), data.Coordinates);
     201      var tsp = TSP.GetDataFromInstance(data);
    203202      OrienteeringProblemData = new OrienteeringProblemData(tsp, data.StartingPoint, data.TerminalPoint, data.Scores, data.MaximumDistance, data.PointVisitingCosts);
    204203    }
     
    217216
    218217
    219       var tsp = data.Coordinates != null ? (ITSPData)new EuclideanTSPData(Name, data.Coordinates) : new MatrixTSPData(Name, data.Distances ?? data.GetDistanceMatrix(), data.Coordinates);
     218      var tsp = TSP.GetDataFromInstance(data);
    220219      var avgDist = 0.0;
    221220      for (var i = 0; i < data.Dimension - 1; i++)
     
    240239      Description = data.Description;
    241240
    242       var tsp = data.Coordinates != null ? (ITSPData)new EuclideanTSPData(Name, data.Coordinates) : new MatrixTSPData(Name, data.Distances ?? data.GetDistanceMatrix(), data.Coordinates);
    243 
    244       OrienteeringProblemData = new OrienteeringProblemData(tsp, 0, 0,
    245         data.Demands, data.Capacity * 2, 0);
     241      var tsp = TSP.GetDataFromInstance(data);
     242      OrienteeringProblemData = new OrienteeringProblemData(tsp, 0, 0, data.Demands, data.Capacity * 2, 0);
    246243    }
    247244    #endregion
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblemdata.cs

    r17525 r17529  
    11using System;
    2 using System.Linq;
    32using HEAL.Attic;
    43using HeuristicLab.Common;
     
    4443    }
    4544    public OrienteeringProblemData() {
    46       RoutingData = new EuclideanTSPData("HL OP Default", defaultCoordinates);
     45      RoutingData = new MatrixTSPData("HL OP Default", defaultMatrix, defaultCoordinates);
    4746      Name = RoutingData.Name;
    4847      StartingPoint = 0;
    4948      TerminalPoint = 20;
    50       Scores = new DoubleArray(Enumerable.Repeat(1.0, RoutingData.Cities).ToArray(), @readonly: true);
     49      Scores = new DoubleArray(defaultScores, @readonly: true);
    5150      MaximumTravelCosts = 30;
    5251      PointVisitingCosts = 0;
     
    5857      if (tspData.Cities != scores.Length) throw new ArgumentException("Unequal number of cities and scores.");
    5958      if (startingPoint < 0 || startingPoint >= tspData.Cities) throw new ArgumentException("Starting point is not in the range of cities.", "startingPoint");
    60       if (terminalPoint < 0 || terminalPoint >= tspData.Cities) throw new ArgumentException("Starting point is not in the range of cities.", "startingPoint");
     59      if (terminalPoint < 0 || terminalPoint >= tspData.Cities) throw new ArgumentException("Terminal point is not in the range of cities.", "terminalPoint");
    6160      RoutingData = tspData;
    6261      StartingPoint = startingPoint;
     
    102101    };
    103102    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 };
     103    private static double[,] defaultMatrix = new double[21, 21] {
     104      { 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 },
     105      { 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 },
     106      { 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 },
     107      { 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 },
     108      { 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 },
     109      { 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 },
     110      { 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 },
     111      { 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 },
     112      { 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 },
     113      { 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 },
     114      { 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 },
     115      { 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 },
     116      { 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 },
     117      { 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 },
     118      { 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 },
     119      { 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 },
     120      { 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 },
     121      { 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 },
     122      { 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 },
     123      { 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 },
     124      { 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 }
     125    };
    104126  }
    105127}
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/TSPData.cs

    r17525 r17529  
    161161      if (closed) distance += GetDistance(prev, start);
    162162      return distance;
     163    }
     164
     165    public double[,] CalculateDistanceMatrix() {
     166      var matrix = new double[Cities, Cities];
     167      for (var i = 0; i < Cities; i++) {
     168        for (var j = 0; j < Cities; j++) {
     169          matrix[i, j] = GetDistance(i, j);
     170        }
     171      }
     172      return matrix;
    163173    }
    164174
Note: See TracChangeset for help on using the changeset viewer.