Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/08/20 16:55:51 (4 years ago)
Author:
abeham
Message:

#2521: Unified architecture

Location:
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/Creators/GreedyOrienteeringTourCreator.cs

    r17525 r17533  
    6666      // Find all points within the maximum distance allowed (ellipse)
    6767      var feasiblePoints = (
    68         from point in Enumerable.Range(0, data.RoutingData.Cities)
    69         let travelCosts = data.RoutingData.GetDistance(data.StartingPoint, point)
    70         + data.RoutingData.GetDistance(point, data.TerminalPoint) + data.PointVisitingCosts
     68        from point in Enumerable.Range(0, data.Cities)
     69        let travelCosts = data.GetDistance(data.StartingPoint, point)
     70        + data.GetDistance(point, data.TerminalPoint) + data.PointVisitingCosts
    7171        let score = data.GetScore(point)
    7272        where travelCosts <= data.MaximumTravelCosts
     
    8181        data.TerminalPoint
    8282      };
    83       double tourLength = data.RoutingData.GetDistance(data.StartingPoint, data.TerminalPoint);
     83      double tourLength = data.GetDistance(data.StartingPoint, data.TerminalPoint);
    8484
    8585      // Add points in a greedy way
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/Improvers/OrienteeringLocalImprovementOperator.cs

    r17525 r17533  
    126126
    127127        // Determine all points that have not yet been visited by this tour
    128         var visitablePoints = Enumerable.Range(0, data.RoutingData.Cities).Except(tour).ToList();
     128        var visitablePoints = Enumerable.Range(0, data.Cities).Except(tour).ToList();
    129129
    130130        // Determine if any of the visitable points can be included at any position within the tour
     
    168168            double newLength = tourLength;
    169169            // Recalculate length of whole swapped part, in case distances are not symmetric
    170             for (int index = position - 1; index < position + blockLength; index++) newLength -= data.RoutingData.GetDistance(tour[index], tour[index + 1]);
    171             for (int index = position + blockLength - 1; index > position; index--) newLength += data.RoutingData.GetDistance(tour[index], tour[index - 1]);
    172             newLength += data.RoutingData.GetDistance(tour[position - 1], tour[position + blockLength - 1]);
    173             newLength += data.RoutingData.GetDistance(tour[position], tour[position + blockLength]);
     170            for (int index = position - 1; index < position + blockLength; index++) newLength -= data.GetDistance(tour[index], tour[index + 1]);
     171            for (int index = position + blockLength - 1; index > position; index--) newLength += data.GetDistance(tour[index], tour[index - 1]);
     172            newLength += data.GetDistance(tour[position - 1], tour[position + blockLength - 1]);
     173            newLength += data.GetDistance(tour[position], tour[position + blockLength]);
    174174
    175175            if (newLength < tourLength - 0.00001) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs

    r17529 r17533  
    9696    }
    9797    public static double CalculateTravelCosts(IOrienteeringProblemData data, IntegerVector solution) {
    98       var distance = data.RoutingData.GetPathDistance(solution, closed: false);
     98      var distance = data.GetPathDistance(solution, closed: false);
    9999      distance += (solution.Length - 2) * data.PointVisitingCosts;
    100100      return distance;
    101101    }
    102102    public static double CalculateTravelCosts(IOrienteeringProblemData data, IList<int> solution) {
    103       var distance = data.RoutingData.GetPathDistance(solution, closed: false);
     103      var distance = data.GetPathDistance(solution, closed: false);
    104104      distance += (solution.Count - 2) * data.PointVisitingCosts;
    105105      return distance;
     
    127127    }
    128128    public static double CalculateInsertionCosts(IOrienteeringProblemData data, IList<int> path, int insertPosition, int point) {
    129       double detour = data.RoutingData.GetDistance(path[insertPosition - 1], point) + data.RoutingData.GetDistance(point, path[insertPosition]);
     129      double detour = data.GetDistance(path[insertPosition - 1], point) + data.GetDistance(point, path[insertPosition]);
    130130      detour += data.PointVisitingCosts;
    131       detour -= data.RoutingData.GetDistance(path[insertPosition - 1], path[insertPosition]);
     131      detour -= data.GetDistance(path[insertPosition - 1], path[insertPosition]);
    132132      return detour;
    133133    }
    134134    public static double CalculateReplacementCosts(IOrienteeringProblemData data, IList<int> path, int replacePosition, int point) {
    135       double detour = data.RoutingData.GetDistance(path[replacePosition - 1], point) + data.RoutingData.GetDistance(point, path[replacePosition + 1]);
    136       detour -= data.RoutingData.GetDistance(path[replacePosition - 1], path[replacePosition]) + data.RoutingData.GetDistance(path[replacePosition], path[replacePosition + 1]);
     135      double detour = data.GetDistance(path[replacePosition - 1], point) + data.GetDistance(point, path[replacePosition + 1]);
     136      detour -= data.GetDistance(path[replacePosition - 1], path[replacePosition]) + data.GetDistance(path[replacePosition], path[replacePosition + 1]);
    137137      return detour;
    138138    }
    139139    public static double CalculateRemovementSaving(IOrienteeringProblemData data, IList<int> path, int removePosition) {
    140       double saving = data.RoutingData.GetDistance(path[removePosition - 1], path[removePosition]);
    141       saving += data.RoutingData.GetDistance(path[removePosition], path[removePosition + 1]);
    142       saving -= data.RoutingData.GetDistance(path[removePosition - 1], path[removePosition + 1]);
     140      double saving = data.GetDistance(path[removePosition - 1], path[removePosition]);
     141      saving += data.GetDistance(path[removePosition], path[removePosition + 1]);
     142      saving -= data.GetDistance(path[removePosition - 1], path[removePosition + 1]);
    143143      saving += data.PointVisitingCosts;
    144144      return saving;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblemdata.cs

    r17531 r17533  
    11using System;
     2using System.Collections.Generic;
    23using HEAL.Attic;
    34using HeuristicLab.Common;
     
    56using HeuristicLab.Data;
    67using HeuristicLab.Encodings.IntegerVectorEncoding;
     8using HeuristicLab.Encodings.PermutationEncoding;
     9using HeuristicLab.Problems.Instances;
    710using HeuristicLab.Problems.Instances.Types;
    811using HeuristicLab.Problems.TravelingSalesman;
     
    1013namespace HeuristicLab.Problems.Orienteering {
    1114  [StorableType("c33063a6-a2ee-4054-9dd8-46a738003139")]
    12   public interface IOrienteeringProblemData : INamedItem {
    13     ITSPData RoutingData { get; }
     15  public interface IOrienteeringProblemData : ITSPData {
    1416    int StartingPoint { get; }
    1517    int TerminalPoint { get; }
     
    1921    double GetScore(int city);
    2022    OrienteeringSolution GetSolution(IntegerVector route, double quality, double score, double travelCosts);
    21     OPData Export();
     23    new OPData Export();
    2224  }
    2325
     
    9395    }
    9496
     97    #region ITSPData members
     98    int ITSPData.Cities => RoutingData.Cities;
     99    double ITSPData.GetDistance(int fromCity, int toCity) => RoutingData.GetDistance(fromCity, toCity);
     100    double ITSPData.GetPathDistance(IEnumerable<int> path, bool closed) => RoutingData.GetPathDistance(path, closed);
     101    ITSPSolution ITSPData.GetSolution(Permutation tspTour, double tourLength) => RoutingData.GetSolution(tspTour, tourLength);
     102    TSPData ITSPData.Export() => RoutingData.Export();
     103    DoubleMatrix ITSPData.GetCoordinatesOrDefault() => RoutingData.GetCoordinatesOrDefault();
     104    #endregion
     105
    95106    private static double[,] defaultCoordinates = new double[21, 2] {
    96107      {  4.60,  7.10 }, {  5.70, 11.40 }, {  4.40, 12.30 }, {  2.80, 14.30 }, {  3.20, 10.30 },
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringSolution.cs

    r17526 r17533  
    3131
    3232namespace HeuristicLab.Problems.Orienteering {
     33  public interface IOrienteeringSolution : ITSPSolution {
     34    new IOrienteeringProblemData Data { get; }
     35    new IntegerVector Tour { get; }
     36    DoubleValue Quality { get; }
     37    DoubleValue Score { get; }
     38    DoubleValue TravelCosts { get; }
     39  }
     40
    3341  [Item("OrienteeringSolution", "Represents a Orienteering solution which can be visualized in the GUI.")]
    3442  [StorableType("BC58ED08-B9A7-40F3-B8E0-A6B33AA993F4")]
    35   public sealed class OrienteeringSolution : Item, ITSPSolution {
     43  public sealed class OrienteeringSolution : Item, IOrienteeringSolution {
    3644    public static new Image StaticItemImage {
    3745      get { return HeuristicLab.Common.Resources.VSImageLibrary.Image; }
     
    4048    [Storable] private Permutation routeAsPermutation;
    4149    [Storable] private IntegerVector route;
    42     public IntegerVector Route {
     50    public IntegerVector Tour {
    4351      get { return route; }
    4452      set {
     
    4654        route = value;
    4755        routeAsPermutation = new Permutation(PermutationTypes.RelativeDirected, value);
    48         OnPropertyChanged(nameof(Route));
    49         OnPropertyChanged(nameof(ITSPSolution.Tour));
     56        OnPropertyChanged(nameof(Tour));
    5057      }
    5158    }
    52     [Storable] private IOrienteeringProblemData opData;
    53     public IOrienteeringProblemData OPData {
    54       get { return opData; }
     59    [Storable] private IOrienteeringProblemData data;
     60    public IOrienteeringProblemData Data {
     61      get { return data; }
    5562      set {
    56         if (opData == value) return;
    57         opData = value;
    58         OnPropertyChanged(nameof(OPData));
    59         OnPropertyChanged(nameof(ITSPSolution.TSPData));
     63        if (data == value) return;
     64        data = value;
     65        OnPropertyChanged(nameof(Data));
    6066      }
    6167    }
     
    9298    }
    9399
    94     ITSPData ITSPSolution.TSPData => OPData.RoutingData;
     100    ITSPData ITSPSolution.Data => Data;
    95101    Permutation ITSPSolution.Tour => routeAsPermutation;
    96102    DoubleValue ITSPSolution.TourLength => TravelCosts;
     
    102108      this.route = cloner.Clone(original.route);
    103109      this.routeAsPermutation = cloner.Clone(original.routeAsPermutation);
    104       this.opData = cloner.Clone(original.opData);
     110      this.data = cloner.Clone(original.data);
    105111      this.quality = cloner.Clone(original.quality);
    106112      this.score = cloner.Clone(original.score);
     
    112118      this.route = route;
    113119      this.routeAsPermutation = new Permutation(PermutationTypes.RelativeDirected, route);
    114       this.opData = opData;
     120      this.data = opData;
    115121      this.quality = quality;
    116122      this.score = score;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/Shakers/OrienteeringShakingOperator.cs

    r17525 r17533  
    9696      var initialTour = IntegerVectorParameter.ActualValue;
    9797      var data = OrienteeringProblemDataParameter.ActualValue;
    98       int numPoints = data.RoutingData.Cities;
     98      int numPoints = data.Cities;
    9999
    100100      if (NeighborhoodCountParameter.ActualValue == null)
     
    117117          from point in Enumerable.Range(0, numPoints)
    118118          // Calculate the distance when going from the starting point to this point and then to the end point
    119           let distance = data.RoutingData.GetDistance(data.StartingPoint, point) + data.RoutingData.GetDistance(point, data.TerminalPoint) + data.PointVisitingCosts
     119          let distance = data.GetDistance(data.StartingPoint, point) + data.GetDistance(point, data.TerminalPoint) + data.PointVisitingCosts
    120120          // If this distance is feasible and the point is neither starting nor ending point, check the point
    121121          where distance < data.MaximumTravelCosts && point != data.StartingPoint && point != data.TerminalPoint
Note: See TracChangeset for help on using the changeset viewer.