Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17712


Ignore:
Timestamp:
08/04/20 07:06:39 (4 years ago)
Author:
abeham
Message:

#2521: working on VRP

Location:
branches/2521_ProblemRefactoring
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Moves/VRPMoveEvaluator.cs

    r17698 r17712  
    2020#endregion
    2121
     22using HEAL.Attic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    2526using HeuristicLab.Optimization;
    2627using HeuristicLab.Parameters;
    27 using HEAL.Attic;
    2828using HeuristicLab.Problems.VehicleRouting.Interfaces;
     29using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
    2930
    3031namespace HeuristicLab.Problems.VehicleRouting.Encodings.General {
     
    4344      get { return (ILookupParameter<DoubleValue>)Parameters["MovePenalty"]; }
    4445    }
     46    public ILookupParameter<VRPEvaluation> MoveEvaluationResultParameter {
     47      get { return (ILookupParameter<VRPEvaluation>)Parameters["MoveEvaluationResult"]; }
     48    }
    4549
    4650    [StorableConstructor]
     
    5256      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move."));
    5357      Parameters.Add(new LookupParameter<DoubleValue>("MovePenalty", "The penalty applied to the move."));
     58      Parameters.Add(new LookupParameter<VRPEvaluation>("MoveEvaluationResult", "The evaluation result of the move."));
    5459    }
    5560
     
    6065    //helper method to evaluate an updated individual
    6166    protected void UpdateEvaluation(IVRPEncodedSolution updatedTours) {
    62       IVRPEvaluator evaluator = ProblemInstance.MoveEvaluator;
    63 
    64       try {
    65         this.ExecutionContext.Scope.Variables.Add(new Variable(evaluator.VRPToursParameter.ActualName,
    66           updatedTours));
    67 
    68         IAtomicOperation op = this.ExecutionContext.CreateChildOperation(evaluator);
    69         op.Operator.Execute((IExecutionContext)op, CancellationToken);
    70       }
    71       finally {
    72         this.ExecutionContext.Scope.Variables.Remove(evaluator.VRPToursParameter.ActualName);
    73       }
     67      var evaluation = ProblemInstance.Evaluate(updatedTours);
     68      MoveEvaluationResultParameter.ActualValue = evaluation;
     69      MoveQualityParameter.ActualValue = new DoubleValue(evaluation.Quality);
     70      MovePenaltyParameter.ActualValue = new DoubleValue(evaluation.Penalty);
    7471    }
    7572
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Moves/VRPMoveMaker.cs

    r17226 r17712  
    2020#endregion
    2121
    22 using System.Collections.Generic;
     22using HEAL.Attic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     
    2626using HeuristicLab.Optimization;
    2727using HeuristicLab.Parameters;
    28 using HEAL.Attic;
    29 using HeuristicLab.Problems.VehicleRouting.Interfaces;
     28using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
    3029
    3130namespace HeuristicLab.Problems.VehicleRouting.Encodings.General {
     
    3635      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
    3736    }
     37    public ILookupParameter<VRPEvaluation> EvaluationResultParameter {
     38      get { return (ILookupParameter<VRPEvaluation>)Parameters["EvaluationResult"]; }
     39    }
    3840    public ILookupParameter<DoubleValue> MoveQualityParameter {
    3941      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
     
    4143    public ILookupParameter<DoubleValue> MovePenaltyParameter {
    4244      get { return (ILookupParameter<DoubleValue>)Parameters["MovePenalty"]; }
     45    }
     46    public ILookupParameter<VRPEvaluation> MoveEvaluationResultParameter {
     47      get { return (ILookupParameter<VRPEvaluation>)Parameters["MoveEvaluationResult"]; }
    4348    }
    4449
     
    4954      : base() {
    5055      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the solution."));
     56      Parameters.Add(new LookupParameter<VRPEvaluation>("EvaluationResult", "The evaluation of the solution."));
    5157      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move."));
    5258      Parameters.Add(new LookupParameter<DoubleValue>("MovePenalty", "The penalty applied to the move."));
     59      Parameters.Add(new LookupParameter<VRPEvaluation>("MoveEvaluationResult", "The move evaluation."));
    5360    }
    5461
     
    6067
    6168    private void UpdateMoveEvaluation() {
    62       IVRPEvaluator evaluator = ProblemInstance.SolutionEvaluator;
    63       ICollection<IParameter> addedParameters = new List<IParameter>();
    64 
    65       try {
    66         foreach (IParameter parameter in evaluator.Parameters) {
    67           if (parameter is ILookupParameter
    68             && parameter != evaluator.VRPToursParameter
    69             && parameter != evaluator.ProblemInstanceParameter) {
    70             ILookupParameter evaluatorParameter = parameter as ILookupParameter;
    71 
    72             string resultName = evaluatorParameter.ActualName;
    73             if (!this.Parameters.ContainsKey(resultName)) {
    74               ILookupParameter resultParameter = new LookupParameter<IItem>(resultName);
    75               resultParameter.ExecutionContext = ExecutionContext;
    76               this.Parameters.Add(resultParameter);
    77               addedParameters.Add(resultParameter);
    78             }
    79 
    80             string moveResultName = VRPMoveEvaluator.MovePrefix + resultName;
    81             if (!this.Parameters.ContainsKey(moveResultName)) {
    82               ILookupParameter moveResultParameter = new LookupParameter<IItem>(moveResultName);
    83               moveResultParameter.ExecutionContext = ExecutionContext;
    84               this.Parameters.Add(moveResultParameter);
    85               addedParameters.Add(moveResultParameter);
    86             }
    87 
    88             ILookupParameter result = Parameters[resultName] as ILookupParameter;
    89             ILookupParameter moveResult = Parameters[moveResultName] as ILookupParameter;
    90             result.ActualValue = moveResult.ActualValue;
    91           }
    92         }
    93       } finally {
    94         foreach (IParameter parameter in addedParameters) {
    95           this.Parameters.Remove(parameter);
    96         }
    97       }
     69      EvaluationResultParameter.ActualValue = MoveEvaluationResultParameter.ActualValue;
     70      QualityParameter.ActualValue = MoveQualityParameter.ActualValue;
    9871    }
    9972
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Creators/PushForwardInsertionCreator.cs

    r17698 r17712  
    2222using System;
    2323using System.Collections.Generic;
     24using HEAL.Attic;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    2728using HeuristicLab.Optimization;
    2829using HeuristicLab.Parameters;
    29 using HEAL.Attic;
    3030using HeuristicLab.Problems.VehicleRouting.Interfaces;
    3131using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
     
    299299            } else {
    300300              double cost = tourCost;
    301               bool feasible = problemInstance.Feasible(eval);
    302               if (cost < minimumCost && feasible) {
     301              if (cost < minimumCost && eval.IsFeasible) {
    303302                customer = unrouted;
    304303                minimumCost = cost;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinCrossover.cs

    r17698 r17712  
    2121
    2222using System.Collections.Generic;
     23using HEAL.Attic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    2627using HeuristicLab.Optimization;
    2728using HeuristicLab.Parameters;
    28 using HEAL.Attic;
    2929using HeuristicLab.Problems.VehicleRouting.Encodings.General;
    3030using HeuristicLab.Problems.VehicleRouting.Interfaces;
     
    134134        solution.Tours.Remove(tour);
    135135      }
    136 
    137       if (newTour.Stops.Count > 0 && !allowInfeasible && !instance.TourFeasible(newTour, solution))
     136      var tourEval = instance.EvaluateTour(newTour, solution);
     137      if (newTour.Stops.Count > 0 && !allowInfeasible && !tourEval.IsFeasible)
    138138        return false;
    139139
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinInsertionBasedCrossover.cs

    r17698 r17712  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using HEAL.Attic;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Core;
    24 using HEAL.Attic;
    25 using System.Collections.Generic;
    2627using HeuristicLab.Data;
    27 using System;
    2828using HeuristicLab.Parameters;
     29using HeuristicLab.Problems.VehicleRouting.Interfaces;
    2930using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
    30 using HeuristicLab.Problems.VehicleRouting.Interfaces;
    3131
    3232namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    165165      double minDetour = 0;
    166166      VRPEvaluation eval = ProblemInstance.EvaluateTour(tour, individual);
    167       bool originalFeasible = ProblemInstance.Feasible(eval);
    168167
    169168      for (int i = 0; i <= tour.Stops.Count; i++) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinLocalSearchManipulator.cs

    r17698 r17712  
    2121
    2222using System.Collections.Generic;
     23using HEAL.Attic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Data;
    2627using HeuristicLab.Parameters;
    27 using HEAL.Attic;
    2828using HeuristicLab.Problems.VehicleRouting.Interfaces;
    2929
     
    7070          distance = individual.GetTourLength(individual.Tours[currentTour]);
    7171          individual.Tours[currentTour].Stops.InsertRange(currentCity, toBeDeleted);
    72           if (instance.TourFeasible(individual.Tours[currentTour], individual)) {
     72          var tourEval = instance.EvaluateTour(individual.Tours[currentTour], individual);
     73          if (tourEval.IsFeasible) {
    7374            double lengthIncrease =
    7475              individual.GetTourLength(individual.Tours[currentTour]) - distance;
     
    9495    public static void ApplyManipulation(IRandom random, PotvinEncodedSolution individual, IVRPProblemInstance instance, int maxIterations) {
    9596      //only apply to feasible individuals
    96       if (instance.Feasible(individual)) {
     97      var eval = instance.Evaluate(individual);
     98      if (eval.IsFeasible) {
    9799        bool insertionFound;
    98100        int iterations = 0;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinPairwiseOneLevelExchangeManipulator.cs

    r17698 r17712  
    2020#endregion
    2121
     22using HEAL.Attic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    24 using HEAL.Attic;
     25using HeuristicLab.Problems.VehicleRouting.Interfaces;
    2526using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
    2627using HeuristicLab.Problems.VehicleRouting.Variants;
    27 using HeuristicLab.Problems.VehicleRouting.Interfaces;
    2828
    2929namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    8888
    8989            if (delta < bestQuality &&
    90                (instance.Feasible(evalNew) || allowInfeasible)) {
     90               (evalNew.IsFeasible || allowInfeasible)) {
    9191              bestQuality = delta;
    9292              bestTour = tourIdx;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinPairwiseTwoLevelExchangeManipulator.cs

    r17698 r17712  
    2020#endregion
    2121
     22using HEAL.Attic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Encodings.PermutationEncoding;
    25 using HEAL.Attic;
     26using HeuristicLab.Problems.VehicleRouting.Interfaces;
    2627using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
    2728using HeuristicLab.Problems.VehicleRouting.Variants;
    28 using HeuristicLab.Problems.VehicleRouting.Interfaces;
    2929
    3030namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    7777
    7878      replacedSourceTour.Stops[replacedSourceTour.Stops.IndexOf(replacedSource)] = replacingSource;
    79       if (!allowInfeasible && !instance.TourFeasible(replacedSourceTour, individual))
     79      var evalSourceTour = instance.EvaluateTour(replacedSourceTour, individual);
     80      if (!allowInfeasible && !evalSourceTour.IsFeasible)
    8081        return null;
    8182
     83      var evalTargetTour = instance.EvaluateTour(replacedTargetTour, individual);
    8284      replacedTargetTour.Stops[replacedTargetTour.Stops.IndexOf(replacedTarget)] = replacingTarget;
    83       if (!allowInfeasible && !instance.TourFeasible(replacedTargetTour, individual))
     85      if (!allowInfeasible && !evalTargetTour.IsFeasible)
    8486        return null;
    8587
     
    101103
    102104          if (delta < bestQuality &&
    103               (instance.Feasible(evalNew) || allowInfeasible)) {
     105              (evalNew.IsFeasible || allowInfeasible)) {
    104106            bestQuality = delta;
    105107            bestTour = tourIdx;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinTwoLevelExchangeManipulator.cs

    r17698 r17712  
    2020#endregion
    2121
     22using HEAL.Attic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    24 using HEAL.Attic;
    2525using HeuristicLab.Problems.VehicleRouting.Interfaces;
    2626
     
    6262                route1.Stops.RemoveAt(customer1Position);
    6363
    64                 if (instance.TourFeasible(tour, individual)) {
     64                var tourEval = instance.EvaluateTour(tour, individual);
     65                if (tourEval.IsFeasible) {
    6566                  int routeIdx, place;
    6667                  if (FindInsertionPlace(individual,
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncodedSolution.cs

    r17698 r17712  
    219219
    220220      VRPEvaluation eval = ProblemInstance.Evaluate(this);
    221       bool originalFeasible = ProblemInstance.Feasible(eval);
    222221
    223222      for (int tour = 0; tour < Tours.Count; tour++) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/PrinsEncodedSolution.cs

    r17698 r17712  
    6666
    6767          double cost = eval.Quality;
    68           feasible = ProblemInstance.Feasible(eval);
     68          feasible = eval.IsFeasible;
    6969
    7070          if (feasible || j == i) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Zhu/ZhuEncodedSolution.cs

    r17698 r17712  
    4545        int city = this[i] + 1;
    4646        newTour.Stops.Add(city);
    47         if (!ProblemInstance.TourFeasible(newTour, this)) {
     47        var evalNewTour = ProblemInstance.EvaluateTour(newTour, this);
     48        if (!evalNewTour.IsFeasible) {
    4849          newTour.Stops.Remove(city);
    4950          if (newTour.Stops.Count > 0)
  • branches/2521_ProblemRefactoring/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GAVrpSampleTest.cs

    r17226 r17712  
    7979      instance.TardinessPenalty.Value = 100;
    8080      instance.TimeFactor.Value = 0;
    81       vrpProblem.MaximizationParameter.Value.Value = false;
    8281      instance.UseDistanceMatrix.Value = true;
    8382      instance.Vehicles.Value = 25;
Note: See TracChangeset for help on using the changeset viewer.