Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/28/11 14:16:21 (13 years ago)
Author:
svonolfe
Message:

Merged changes from trunk (#1561) into branch (#1177)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncoding.cs

    r5202 r6607  
    8080
    8181    public double GetTourLength(Tour tour) {
    82       double length = 0;
    83 
    84       if (tour.Stops.Count > 0) {
    85         List<int> cities = new List<int>();
    86         cities.Add(0);
    87         foreach (int city in tour.Stops) {
    88           cities.Add(city);
    89         }
    90         cities.Add(0);
    91 
    92         for (int i = 1; i < cities.Count; i++) {
    93           length += ProblemInstance.GetDistance(cities[i - 1], cities[i]);
    94         }
    95       } 
    96 
    97       return length;
     82      return tour.GetTourLength(ProblemInstance);
    9883    }
    9984
     
    10590        tour.Stops.Insert(i, city);
    10691
    107         VRPEvaluation eval = ProblemInstance.EvaluatorParameter.Value.Evaluate(ProblemInstance, tour);
     92        VRPEvaluation eval = ProblemInstance.Evaluate(tour);
    10893        double quality = eval.Quality + eval.Penalty * (PenaltyFactor - 1.0);
    10994
     
    122107    }
    123108
    124     public bool FindInsertionPlace(int city, int routeToAvoid, out int route, out int place) {
     109    public bool FindInsertionPlace(int city, int routeToAvoid, bool allowInfeasible, out int route, out int place) {
    125110      route = -1;
    126111      place = -1;
    127       double minDetour = 0;
     112      bool bestFeasible = false;
     113      double minDetour = double.MaxValue;
    128114
    129115      for (int tour = 0; tour < Tours.Count; tour++) {
    130116        if (tour != routeToAvoid) {
    131           double length = GetTourLength(Tours[tour]);
     117          for (int i = 0; i <= Tours[tour].Stops.Count; i++) {
     118            double length = GetTourLength(Tours[tour]);
    132119
    133           for (int i = 0; i <= Tours[tour].Stops.Count; i++) {
    134120            Tours[tour].Stops.Insert(i, city);
    135121
    136             VRPEvaluation eval = ProblemInstance.EvaluatorParameter.Value.Evaluate(
    137               ProblemInstance, Tours[tour]);
    138             if (ProblemInstance.EvaluatorParameter.Value.Feasible(eval)) {
    139               double newLength = eval.Distance;
     122            bool feasible = ProblemInstance.Feasible(Tours[tour]);
    140123
     124            if (feasible || allowInfeasible && !bestFeasible) {
     125              double newLength = GetTourLength(Tours[tour]);
    141126              double detour = newLength - length;
    142127
    143               if (route <= 0 || detour < minDetour) {
     128              if (route < 0 || detour < minDetour || feasible && !bestFeasible) {
    144129                route = tour;
    145130                place = i;
    146131                minDetour = detour;
     132
     133                if (feasible)
     134                  bestFeasible = true;
    147135              }
    148136            }
Note: See TracChangeset for help on using the changeset viewer.