1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
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 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using System.Linq;
|
---|
24 | using HEAL.Attic;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
29 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
|
---|
32 | [Item("SingleDepotVRPProblemInstance", "Represents a single depot VRP instance.")]
|
---|
33 | [StorableType("A45435DD-F615-45C6-8456-5A49EE5D3C8E")]
|
---|
34 | public class SingleDepotVRPProblemInstance : VRPProblemInstance, ISingleDepotProblemInstance {
|
---|
35 |
|
---|
36 | public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) {
|
---|
37 | return base.FilterOperators(operators).Where(x => x is ISingleDepotOperator);
|
---|
38 | }
|
---|
39 |
|
---|
40 | public override IntValue Cities {
|
---|
41 | get {
|
---|
42 | return new IntValue(Demand.Length - 1);
|
---|
43 | }
|
---|
44 | }
|
---|
45 | protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) {
|
---|
46 | TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
|
---|
47 | eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
|
---|
48 |
|
---|
49 | double distance = 0.0;
|
---|
50 | double quality = 0.0;
|
---|
51 |
|
---|
52 | //simulate a tour, start and end at depot
|
---|
53 | for (int i = 0; i <= tour.Stops.Count; i++) {
|
---|
54 | int start = 0;
|
---|
55 | if (i > 0)
|
---|
56 | start = tour.Stops[i - 1];
|
---|
57 | int end = 0;
|
---|
58 | if (i < tour.Stops.Count)
|
---|
59 | end = tour.Stops[i];
|
---|
60 |
|
---|
61 | //drive there
|
---|
62 | double currentDistace = GetDistance(start, end, solution);
|
---|
63 | distance += currentDistace;
|
---|
64 |
|
---|
65 | StopInsertionInfo stopInfo = new StopInsertionInfo(start, end);
|
---|
66 | tourInfo.AddStopInsertionInfo(stopInfo);
|
---|
67 | }
|
---|
68 |
|
---|
69 | //Fleet usage
|
---|
70 | quality += FleetUsageFactor.Value;
|
---|
71 | //Distance
|
---|
72 | quality += DistanceFactor.Value * distance;
|
---|
73 |
|
---|
74 | eval.Distance += distance;
|
---|
75 | eval.VehicleUtilization += 1;
|
---|
76 |
|
---|
77 | tourInfo.Quality = quality;
|
---|
78 | eval.Quality += quality;
|
---|
79 | }
|
---|
80 |
|
---|
81 | protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
|
---|
82 | out bool feasible) {
|
---|
83 | StopInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index);
|
---|
84 |
|
---|
85 | double costs = 0;
|
---|
86 | feasible = true;
|
---|
87 |
|
---|
88 | double distance = GetDistance(insertionInfo.Start, insertionInfo.End, solution);
|
---|
89 | double newDistance =
|
---|
90 | GetDistance(insertionInfo.Start, customer, solution) +
|
---|
91 | GetDistance(customer, insertionInfo.End, solution);
|
---|
92 |
|
---|
93 | costs += DistanceFactor.Value * (newDistance - distance);
|
---|
94 |
|
---|
95 | return costs;
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | [StorableConstructor]
|
---|
100 | protected SingleDepotVRPProblemInstance(StorableConstructorFlag _) : base(_) { }
|
---|
101 |
|
---|
102 | public SingleDepotVRPProblemInstance() {
|
---|
103 | }
|
---|
104 |
|
---|
105 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
106 | return new SingleDepotVRPProblemInstance(this, cloner);
|
---|
107 | }
|
---|
108 |
|
---|
109 | protected SingleDepotVRPProblemInstance(SingleDepotVRPProblemInstance original, Cloner cloner)
|
---|
110 | : base(original, cloner) {
|
---|
111 | }
|
---|
112 | }
|
---|
113 | } |
---|