Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6838


Ignore:
Timestamp:
09/27/11 13:29:56 (13 years ago)
Author:
svonolfe
Message:

Updated interface of evaluator - added individual (#1177)

Location:
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4
Files:
1 added
1 deleted
17 edited

Legend:

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

    r6788 r6838  
    101101
    102102      Tour currentTour = new Tour();
     103      result.Tours.Add(currentTour);
    103104
    104105      int j = random.Next(customers.Count);
     
    114115        }
    115116
    116         CVRPEvaluation evaluation = instance.Evaluate(currentTour) as CVRPEvaluation;
     117        CVRPEvaluation evaluation = instance.EvaluateTour(currentTour, result) as CVRPEvaluation;
    117118        if (result.Tours.Count < instance.Vehicles.Value &&
    118119          ((adhereTimeWindows && !instance.Feasible(evaluation)) || ((!adhereTimeWindows) && evaluation.Overload > double.Epsilon))) {
     
    132133      }
    133134
    134       if (currentTour.Stops.Count > 0)
    135         result.Tours.Add(currentTour);
     135      if (currentTour.Stops.Count == 0)
     136        result.Tours.Remove(currentTour);
    136137
    137138      return result;
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinInsertionBasedCrossover.cs

    r6752 r6838  
    149149
    150150    private bool FindRouteInsertionPlace(
     151      PotvinEncoding individual,
    151152      Tour tour,
    152153      int city, bool allowInfeasible, out int place) {
     
    162163
    163164      double minDetour = 0;
    164       VRPEvaluation eval = ProblemInstance.Evaluate(tour);
     165      VRPEvaluation eval = ProblemInstance.EvaluateTour(tour, individual);
    165166      bool originalFeasible = ProblemInstance.Feasible(eval);
    166167
     
    220221
    221222        Tour childTour = new Tour();
     223        child.Tours.Add(childTour);
    222224        childTour.Stops.AddRange(r1.Stops);
    223225
     
    233235
    234236        while (count < maxCount && R2.Count != 0) {
    235           PotvinEncoding newChild = child.Clone() as PotvinEncoding;
    236           newChild.Tours.Add(childTour);
    237 
    238237          int index = random.Next(R2.Count);
    239238          int city = R2[index];
     
    241240
    242241          int place = -1;
    243           bool found = FindRouteInsertionPlace(childTour, city, allowInfeasible, out place);
     242          bool found = FindRouteInsertionPlace(child, childTour, city, allowInfeasible, out place);
    244243          if (found) {
    245244            childTour.Stops.Insert(place, city);
     
    253252        }
    254253
    255         child.Tours.Add(childTour);
    256254        Repair(random, child, childTour, ProblemInstance, allowInfeasible);
    257255      }
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinLocalSearchManipulator.cs

    r4752 r6838  
    6969          distance = individual.GetTourLength(individual.Tours[currentTour]);
    7070          individual.Tours[currentTour].Stops.InsertRange(currentCity, toBeDeleted);
    71           if (ProblemInstance.Feasible(individual.Tours[currentTour])) {
     71          if (ProblemInstance.TourFeasible(individual.Tours[currentTour], individual)) {
    7272            double lengthIncrease =
    7373              individual.GetTourLength(individual.Tours[currentTour]) - distance;
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinTwoLevelExchangeManipulator.cs

    r6796 r6838  
    6666              route1.Stops.RemoveAt(customer1Position);
    6767
    68               if (ProblemInstance.Feasible(tour)) {
     68              if (ProblemInstance.TourFeasible(tour, individual)) {
    6969                int routeIdx, place;
    7070                if (FindInsertionPlace(individual,
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDRearrange/PotvinPDRearrangeMoveMaker.cs

    r6806 r6838  
    6161    public static void InsertPair(PotvinEncoding solution, Tour tour, int source, int target, IVRPProblemInstance problemInstance, int positionToAvoid = -1, int positionToAvoid2 = -1) {
    6262      int stops = tour.Stops.Count;
    63       VRPEvaluation eval = problemInstance.Evaluate(tour);
     63      VRPEvaluation eval = problemInstance.EvaluateTour(tour, solution);
    6464      double minCosts = double.MaxValue;
    6565      int sourceLocation = -1;
     
    6868      for (int i = 0; i <= stops; i++) {
    6969        tour.Stops.Insert(i, source);
    70         VRPEvaluation tourEval = problemInstance.Evaluate(tour);
     70        VRPEvaluation tourEval = problemInstance.EvaluateTour(tour, solution);
    7171        double sourceCosts = tourEval.Quality - eval.Quality;
    7272
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncoding.cs

    r6771 r6838  
    8282      double minQuality = -1;
    8383
    84       VRPEvaluation eval = ProblemInstance.Evaluate(tour);
     84      VRPEvaluation eval = ProblemInstance.EvaluateTour(tour, this);
    8585
    8686      for (int i = 0; i <= tour.Stops.Count; i++) {
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/PrinsEncoding.cs

    r6758 r6838  
    6161
    6262          VRPEvaluation eval =
    63             ProblemInstance.Evaluate(tour);
     63            ProblemInstance.EvaluateTour(tour, this);
    6464
    6565          double cost = eval.Quality;
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Zhu/ZhuEncoding.cs

    r4752 r6838  
    4343        int city = this[i] + 1;
    4444        newTour.Stops.Add(city);
    45         if (!ProblemInstance.Feasible(newTour)) {
     45        if (!ProblemInstance.TourFeasible(newTour, this)) {
    4646          newTour.Stops.Remove(city);
    4747          if (newTour.Stops.Count > 0)
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/HeuristicLab.Problems.VehicleRouting-3.4.csproj

    r6773 r6838  
    129129    <Compile Include="Encodings\Alba\AlbaEncoding.cs" />
    130130    <Compile Include="Encodings\Alba\Creators\DefaultRepresentationCreator.cs" />
    131     <Compile Include="Encodings\Alba\Creators\PushForwardInsertionCreator.cs" />
    132131    <Compile Include="Encodings\Alba\Creators\RandomCreator.cs" />
    133132    <Compile Include="Encodings\Alba\Creators\AlbaCreator.cs" />
     
    203202    <Compile Include="Encodings\GVR\Manipulators\GVRManipulator.cs" />
    204203    <Compile Include="Encodings\GVR\Manipulators\GVRSwapManipulator.cs" />
     204    <Compile Include="Encodings\Potvin\Creators\PushForwardInsertionCreator.cs" />
    205205    <Compile Include="Encodings\Potvin\Creators\PotvinCreator.cs" />
    206206    <Compile Include="Encodings\Potvin\Creators\IterativeInsertionCreator.cs" />
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Interfaces/IVRPEvaluator.cs

    r6752 r6838  
    3333   
    3434    VRPEvaluation Evaluate(IVRPProblemInstance instance, IVRPEncoding solution);
    35     VRPEvaluation Evaluate(IVRPProblemInstance instance, Tour tour);
     35    VRPEvaluation EvaluateTour(IVRPProblemInstance instance, Tour tour, IVRPEncoding solution);
    3636    bool Feasible(VRPEvaluation evaluation);
    3737    double GetInsertionCosts(IVRPProblemInstance instance, VRPEvaluation eval, int customer, int tour, int index, out bool feasible);
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Interfaces/IVRPProblemInstance.cs

    r6752 r6838  
    5050    double GetDistance(int start, int end);
    5151    bool Feasible(IVRPEncoding solution);
    52     bool Feasible(Tour tour);
     52    bool TourFeasible(Tour tour, IVRPEncoding solution);
    5353    VRPEvaluation Evaluate(IVRPEncoding solution);
    54     VRPEvaluation Evaluate(Tour tour);
     54    VRPEvaluation EvaluateTour(Tour tour, IVRPEncoding solution);
    5555    bool Feasible(VRPEvaluation eval);
    5656    double GetInsertionCosts(VRPEvaluation eval, int customer, int tour, int index, out bool feasible);
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPEvaluator.cs

    r6752 r6838  
    4747    }
    4848
    49     protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) {
     49    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
    5050      TourInsertionInfo tourInfo = new TourInsertionInfo();
    5151      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWEvaluator.cs

    r6752 r6838  
    4747    }
    4848
    49     protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) {
     49    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
    5050      TourInsertionInfo tourInfo = new TourInsertionInfo();
    5151      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWEvaluator.cs

    r6752 r6838  
    5151    }
    5252
    53     protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) {
     53    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
    5454      TourInsertionInfo tourInfo = new TourInsertionInfo();
    5555      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/SingleDepotVRPEvaluator.cs

    r6752 r6838  
    4040  [StorableClass]
    4141  public class SingleDepotVRPEvaluator: VRPEvaluator {
    42     protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) {
     42    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
    4343      TourInsertionInfo tourInfo = new TourInsertionInfo();
    4444      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPEvaluator.cs

    r6752 r6838  
    8181    }
    8282
    83     protected abstract void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour);
     83    protected abstract void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution);
    8484
    8585    protected virtual void InitResultParameters() {
     
    9595      DistanceParameter.ActualValue.Value = tourEvaluation.Distance;
    9696      PenaltyParameter.ActualValue.Value = tourEvaluation.Penalty;
    97     }
    98 
    99     private VRPEvaluation EvaluateTour(IVRPProblemInstance instance, Tour tour) {
    100       VRPEvaluation evaluation = CreateTourEvaluation();
    101       EvaluateTour(evaluation, instance, tour);
    102       return evaluation;
    10397    }
    10498
     
    123117    }
    124118
     119    public VRPEvaluation EvaluateTour(IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
     120      VRPEvaluation evaluation = CreateTourEvaluation();
     121      EvaluateTour(evaluation, instance, tour, solution);
     122      return evaluation;
     123    }
     124
    125125    public VRPEvaluation Evaluate(IVRPProblemInstance instance, IVRPEncoding solution) {
    126126      VRPEvaluation evaluation = CreateTourEvaluation();
    127127
    128128      foreach (Tour tour in solution.GetTours()) {
    129         EvaluateTour(evaluation, instance, tour);
     129        EvaluateTour(evaluation, instance, tour, solution);
    130130      }
    131131
    132132      return evaluation;
    133     }
    134 
    135     public VRPEvaluation Evaluate(IVRPProblemInstance instance, Tour tour) {
    136       return EvaluateTour(instance, tour);
    137133    }
    138134
     
    141137
    142138      VRPEvaluation evaluation = CreateTourEvaluation();
    143       foreach (Tour tour in VRPToursParameter.ActualValue.GetTours()) {
    144         EvaluateTour(evaluation, ProblemInstance, tour);
     139      IVRPEncoding solution = VRPToursParameter.ActualValue;
     140      foreach (Tour tour in solution.GetTours()) {
     141        EvaluateTour(evaluation, ProblemInstance, tour, solution);
    145142      }
    146143      SetResultParameters(evaluation);
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs

    r6752 r6838  
    212212    }
    213213
    214     public bool Feasible(Tour tour) {
     214    public bool TourFeasible(Tour tour, IVRPEncoding solution) {
    215215      return evaluator.Feasible(
    216         evaluator.Evaluate(
    217         this, tour));
     216        evaluator.EvaluateTour(
     217        this, tour, solution));
    218218    }
    219219
     
    222222    }
    223223
    224     public VRPEvaluation Evaluate(Tour tour) {
    225       return evaluator.Evaluate(this, tour);
     224    public VRPEvaluation EvaluateTour(Tour tour, IVRPEncoding solution) {
     225      return evaluator.EvaluateTour(this, tour, solution);
    226226    }
    227227
Note: See TracChangeset for help on using the changeset viewer.