Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/VRPOperator.cs @ 4174

Last change on this file since 4174 was 4174, checked in by svonolfe, 14 years ago

Refactored VRP, added some Potvin operators (WIP) (#1039)

File size: 4.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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
22using HeuristicLab.Core;
23using HeuristicLab.Operators;
24using HeuristicLab.Parameters;
25using HeuristicLab.Data;
26using HeuristicLab.Problems.VehicleRouting.Encodings;
27
28namespace HeuristicLab.Problems.VehicleRouting {
29  public abstract class VRPOperator : SingleSuccessorOperator, IVRPOperator {
30    public int Cities {
31      get { return CoordinatesParameter.ActualValue.Rows - 1; }
32    }
33    public ILookupParameter<DoubleMatrix> CoordinatesParameter {
34      get { return (ILookupParameter<DoubleMatrix>)Parameters["Coordinates"]; }
35    }
36    public ILookupParameter<DoubleMatrix> DistanceMatrixParameter {
37      get { return (ILookupParameter<DoubleMatrix>)Parameters["DistanceMatrix"]; }
38    }
39    public ILookupParameter<BoolValue> UseDistanceMatrixParameter {
40      get { return (ILookupParameter<BoolValue>)Parameters["UseDistanceMatrix"]; }
41    }
42    public ILookupParameter<IntValue> VehiclesParameter {
43      get { return (ILookupParameter<IntValue>)Parameters["Vehicles"]; }
44    }
45    public ILookupParameter<DoubleValue> CapacityParameter {
46      get { return (ILookupParameter<DoubleValue>)Parameters["Capacity"]; }
47    }
48    public ILookupParameter<DoubleArray> DemandParameter {
49      get { return (ILookupParameter<DoubleArray>)Parameters["Demand"]; }
50    }
51    public ILookupParameter<DoubleArray> ReadyTimeParameter {
52      get { return (ILookupParameter<DoubleArray>)Parameters["ReadyTime"]; }
53    }
54    public ILookupParameter<DoubleArray> DueTimeParameter {
55      get { return (ILookupParameter<DoubleArray>)Parameters["DueTime"]; }
56    }
57    public ILookupParameter<DoubleArray> ServiceTimeParameter {
58      get { return (ILookupParameter<DoubleArray>)Parameters["ServiceTime"]; }
59    }
60
61    public VRPOperator()
62      : base() {
63      Parameters.Add(new ValueLookupParameter<IntValue>("Cities", "The city count."));
64      Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The coordinates of the cities."));
65      Parameters.Add(new LookupParameter<DoubleMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities."));
66      Parameters.Add(new LookupParameter<BoolValue>("UseDistanceMatrix", "True if a distance matrix should be calculated and used for evaluation, otherwise false."));
67      Parameters.Add(new LookupParameter<IntValue>("Vehicles", "The number of vehicles."));
68      Parameters.Add(new LookupParameter<DoubleValue>("Capacity", "The capacity of each vehicle."));
69      Parameters.Add(new LookupParameter<DoubleArray>("Demand", "The demand of each customer."));
70      Parameters.Add(new LookupParameter<DoubleArray>("ReadyTime", "The ready time of each customer."));
71      Parameters.Add(new LookupParameter<DoubleArray>("DueTime", "The due time of each customer."));
72      Parameters.Add(new LookupParameter<DoubleArray>("ServiceTime", "The service time of each customer."));
73    }
74
75    protected bool Feasible(Tour tour) {
76      return tour.Feasible(
77                  DueTimeParameter.ActualValue,
78                  ServiceTimeParameter.ActualValue,
79                  ReadyTimeParameter.ActualValue,
80                  DemandParameter.ActualValue,
81                  CapacityParameter.ActualValue,
82                  CoordinatesParameter.ActualValue,
83                  DistanceMatrixParameter,
84                  UseDistanceMatrixParameter.ActualValue);
85    }
86
87    protected double GetLength(Tour tour) {
88      return tour.GetLength(
89                CoordinatesParameter.ActualValue,
90                DistanceMatrixParameter,
91                UseDistanceMatrixParameter.ActualValue);
92    }
93  }
94}
Note: See TracBrowser for help on using the repository browser.