Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11245


Ignore:
Timestamp:
07/30/14 16:37:39 (10 years ago)
Author:
pfleck
Message:

#2208

  • Added visualization in the visualization tab of the problem
  • Fixed bug in shaking operator when tour only consists of start and end point
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  
    102102      <Name>HeuristicLab.Optimization-3.3</Name>
    103103    </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>
    104108    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj">
    105109      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
  • branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringProblemView.Designer.cs

    r11189 r11245  
    4444      this.parametersTabPage = new System.Windows.Forms.TabPage();
    4545      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();
    4747      ((System.ComponentModel.ISupportInitialize)(this.problemInstanceSplitContainer)).BeginInit();
    4848      this.problemInstanceSplitContainer.Panel1.SuspendLayout();
     
    101101      // visualizationTabPage
    102102      //
    103       //this.visualizationTabPage.Controls.Add(this.pathTourView);
     103      this.visualizationTabPage.Controls.Add(this.orienteeringSolutionView);
    104104      this.visualizationTabPage.Location = new System.Drawing.Point(4, 22);
    105105      this.visualizationTabPage.Name = "visualizationTabPage";
     
    110110      this.visualizationTabPage.UseVisualStyleBackColor = true;
    111111      //
    112       // pathTourView
     112      // orienteeringSolutionView
    113113      //
    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 = "PathTour View";
    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;
    124124      //
    125125      // TravelingSalesmanProblemView
     
    147147    private System.Windows.Forms.TabPage parametersTabPage;
    148148    private System.Windows.Forms.TabPage visualizationTabPage;
    149     //private PathTourView pathTourView;
     149    private OrienteeringSolutionView orienteeringSolutionView;
    150150  }
    151151}
  • branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringProblemView.cs

    r11189 r11245  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.MainForm;
    2324using HeuristicLab.Optimization.Views;
     
    3637      InitializeComponent();
    3738    }
     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    }
    3881  }
    3982}
  • branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringSolutionView.cs

    r11240 r11245  
    8484          var bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
    8585
    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)) {
    8788            double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
    8889            for (int i = 0; i < coordinates.Rows; i++) {
     
    116117              for (int i = 0; i < points.Length; i++) {
    117118                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);
    119120                graphics.FillRectangle(Brushes.Red, points[i].X - size / 2, points[i].Y - size / 2, size, size);
    120121              }
  • branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/Improvers/OrienteeringLocalImprovementOperator.cs

    r11242 r11245  
    130130
    131131      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)));
    133133    }
    134134
  • branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs

    r11226 r11245  
    2121
    2222using System;
     23using System.IO;
    2324using System.Linq;
    2425using HeuristicLab.Common;
     
    4344
    4445    #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"]; }
    4748    }
    4849    public ValueParameter<DistanceMatrix> DistanceMatrixParameter {
     
    122123    public OrienteeringProblem()
    123124      : 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."));
    125126      Parameters.Add(new ValueParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the points."));
    126127      Parameters.Add(new ValueParameter<IntValue>("StartingPoint", "Index of the starting point.", new IntValue(0)));
    127128      Parameters.Add(new ValueParameter<IntValue>("TerminusPoint", "Index of the ending point.", new IntValue(0)));
    128129      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."));
    130131      Parameters.Add(new ValueParameter<DoubleValue>("FixedPenalty", "The penalty for each visited vertex."));
    131132      Parameters.Add(new OptionalValueParameter<IntegerVector>("BestKnownSolution", "The best known solution of this Orienteering instance."));
     
    323324
    324325    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;
    329335
    330336      Name = data.Name;
    331337      Description = data.Description;
    332338
    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)
    335341        DistanceMatrix = new DistanceMatrix(data.Distances);
     342      else
     343        CalculateDistanceMatrix();
     344
    336345      StartingPoint = new IntValue(0);// Depot is interpreted as start and endpoint (default)
    337346      TerminusPoint = new IntValue(0);
    338347
    339       MaximumDistance = new DoubleValue(data.Capacity); // capacity is interpreted as max distance
     348      MaximumDistance = new DoubleValue(data.Capacity * 2); // capacity is interpreted as max distance
    340349      Scores = new DoubleArray(data.Demands); // demands are interpreted as scores
    341350
    342       BestKnownQuality = null;
    343       BestKnownSolution = null;
     351
     352
     353      OnReset();
    344354    }
    345355  }
  • branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/Shakers/OrienteeringShakingOperator.cs

    r11235 r11245  
    126126      var random = RandomParameter.ActualValue;
    127127
    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      }
    161163
    162164      return base.Apply();
     
    198200            }
    199201
    200             int randomIndex = random.Next(visitablePoints.Count - 1);
     202            int randomIndex = random.Next(visitablePoints.Count);
    201203            actualTour.Add(visitablePoints[randomIndex]);
    202204            visitablePoints.Clear();
Note: See TracChangeset for help on using the changeset viewer.