[8649] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12012] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8649] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[11428] | 22 | using System.IO;
|
---|
[8649] | 23 | using HeuristicLab.Data;
|
---|
| 24 | using HeuristicLab.Problems.Instances;
|
---|
| 25 | using HeuristicLab.Problems.VehicleRouting.Encodings.Potvin;
|
---|
| 26 | using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
|
---|
| 27 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
| 28 | using System;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.VehicleRouting.Interpreters {
|
---|
| 31 | public abstract class VRPInterpreter : IVRPDataInterpreter<IVRPData> {
|
---|
| 32 | protected abstract void Interpret(IVRPData data, IVRPProblemInstance problemInstance);
|
---|
| 33 |
|
---|
| 34 | protected virtual IVRPEncoding GetBestKnowTour(IVRPData data, IVRPProblemInstance problemInstance) {
|
---|
| 35 | if (data.BestKnownTour != null) {
|
---|
| 36 | PotvinEncoding solution = new PotvinEncoding(problemInstance);
|
---|
| 37 |
|
---|
| 38 | for (int i = 0; i < data.BestKnownTour.GetLength(0); i++) {
|
---|
| 39 | Tour tour = new Tour();
|
---|
| 40 | solution.Tours.Add(tour);
|
---|
| 41 |
|
---|
| 42 | foreach (int stop in data.BestKnownTour[i]) {
|
---|
| 43 | tour.Stops.Add(stop + 1);
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[11428] | 47 | if (data.BestKnownTourVehicleAssignment != null) {
|
---|
| 48 | if (data.BestKnownTourVehicleAssignment.Length != solution.VehicleAssignment.Length)
|
---|
| 49 | throw new InvalidDataException("Number of vehicles of the best known tour does not match the number vehicles of the instance.");
|
---|
| 50 | for (int i = 0; i < data.BestKnownTourVehicleAssignment.Length; i++)
|
---|
| 51 | solution.VehicleAssignment[i] = data.BestKnownTourVehicleAssignment[i];
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[8649] | 54 | return solution;
|
---|
| 55 | } else {
|
---|
| 56 | return null;
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | protected abstract IVRPProblemInstance CreateProblemInstance();
|
---|
[11428] | 61 |
|
---|
[8649] | 62 | public VRPInstanceDescription Interpret(IVRPData data) {
|
---|
| 63 | VRPInstanceDescription result = new VRPInstanceDescription();
|
---|
| 64 | result.Name = data.Name;
|
---|
| 65 | result.Description = data.Description;
|
---|
| 66 |
|
---|
| 67 | IVRPProblemInstance problem = CreateProblemInstance();
|
---|
| 68 | Interpret(data, problem);
|
---|
| 69 | result.ProblemInstance = problem;
|
---|
| 70 |
|
---|
| 71 | result.BestKnownQuality = data.BestKnownQuality;
|
---|
| 72 | result.BestKnownSolution = GetBestKnowTour(data, problem);
|
---|
| 73 |
|
---|
| 74 | return result;
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | }
|
---|