Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7854


Ignore:
Timestamp:
05/21/12 14:12:32 (13 years ago)
Author:
svonolfe
Message:

Adapted BestSolutionAnalyzer to dynamic constraint relaxation (#1177)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestSolution/BestVRPSolutionAnalyzer.cs

    r7175 r7854  
    3030using HeuristicLab.Problems.VehicleRouting.Variants;
    3131using HeuristicLab.Common;
     32using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
    3233
    3334namespace HeuristicLab.Problems.VehicleRouting {
     
    126127
    127128      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
    128 
    129       DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
    130 
    131129      IVRPEncoding best = solutions[i].Clone() as IVRPEncoding;
    132130      VRPSolution solution = BestSolutionParameter.ActualValue;
     
    139137        results.Add(new Result("Best VRP Solution VehicleUtilization", new DoubleValue(vehiclesUtilizations[i].Value)));
    140138      } else {
    141         if (qualities[i].Value <= solution.Quality.Value) {
     139        VRPEvaluation eval = problemInstance.Evaluate(solution.Solution);
     140        if (qualities[i].Value <= eval.Quality) {
    142141          solution.ProblemInstance = problemInstance;
    143142          solution.Solution = best.Clone() as IVRPEncoding;
     
    148147      }
    149148
    150       VRPSolution validSolution = BestValidSolutionParameter.ActualValue;
    151       if (validSolution == null) {
    152         if (ProblemInstanceParameter.ActualValue.Feasible(best)) {
    153           validSolution = new VRPSolution(problemInstance, best.Clone() as IVRPEncoding, new DoubleValue(qualities[i].Value));
    154           BestValidSolutionParameter.ActualValue = validSolution;
    155           if (results.ContainsKey("Best valid VRP Solution"))
    156             results["Best valid VRP Solution"].Value = validSolution;
    157           else
    158             results.Add(new Result("Best valid VRP Solution", validSolution));
     149      var idx = qualities.Select((x, index) => new { index, x.Value }).Where(index => problemInstance.Feasible(solutions[index.index])).OrderBy(x => x.Value).FirstOrDefault();
     150      if (idx != null) {
     151        int j = idx.index;
     152        IVRPEncoding bestFeasible = solutions[j].Clone() as IVRPEncoding;
     153        VRPSolution validSolution = BestValidSolutionParameter.ActualValue;
     154        if (validSolution == null) {
     155          if (ProblemInstanceParameter.ActualValue.Feasible(best)) {
     156            validSolution = new VRPSolution(problemInstance, best.Clone() as IVRPEncoding, new DoubleValue(qualities[j].Value));
     157            BestValidSolutionParameter.ActualValue = validSolution;
     158            if (results.ContainsKey("Best valid VRP Solution"))
     159              results["Best valid VRP Solution"].Value = validSolution;
     160            else
     161              results.Add(new Result("Best valid VRP Solution", validSolution));
    159162
    160           results.Add(new Result("Best valid VRP Solution Distance", new DoubleValue(distances[i].Value)));
    161           results.Add(new Result("Best valid VRP Solution VehicleUtilization", new DoubleValue(vehiclesUtilizations[i].Value)));
    162         }
    163       } else {
    164         if (qualities[i].Value <= validSolution.Quality.Value) {
    165           if (ProblemInstanceParameter.ActualValue.Feasible(best)) {
    166             validSolution.ProblemInstance = problemInstance;
    167             validSolution.Solution = best.Clone() as IVRPEncoding;
    168             validSolution.Quality.Value = qualities[i].Value;
    169             (results["Best valid VRP Solution Distance"].Value as DoubleValue).Value = distances[i].Value;
    170             (results["Best valid VRP Solution VehicleUtilization"].Value as DoubleValue).Value = vehiclesUtilizations[i].Value;
     163            results.Add(new Result("Best valid VRP Solution Distance", new DoubleValue(distances[j].Value)));
     164            results.Add(new Result("Best valid VRP Solution VehicleUtilization", new DoubleValue(vehiclesUtilizations[j].Value)));
     165          }
     166        } else {
     167          if (qualities[j].Value <= validSolution.Quality.Value) {
     168            if (ProblemInstanceParameter.ActualValue.Feasible(best)) {
     169              validSolution.ProblemInstance = problemInstance;
     170              validSolution.Solution = best.Clone() as IVRPEncoding;
     171              validSolution.Quality.Value = qualities[j].Value;
     172              (results["Best valid VRP Solution Distance"].Value as DoubleValue).Value = distances[j].Value;
     173              (results["Best valid VRP Solution VehicleUtilization"].Value as DoubleValue).Value = vehiclesUtilizations[j].Value;
     174            }
    171175          }
    172176        }
    173       }
    174177
    175       if (bestKnownQuality == null ||
    176           qualities[i].Value < bestKnownQuality.Value) {
    177         BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
    178         BestKnownSolutionParameter.ActualValue = (VRPSolution)solution.Clone();
     178        DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
     179        if (bestKnownQuality == null || qualities[j].Value < bestKnownQuality.Value) {
     180          BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[j].Value);
     181          BestKnownSolutionParameter.ActualValue = (VRPSolution)validSolution.Clone();
     182        }
    179183      }
    180184
Note: See TracChangeset for help on using the changeset viewer.