Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Tour.cs @ 6593

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

Improved performance of many VRP operators by optimizing the parameter lookup (#1561)

File size: 2.7 KB
RevLine 
[3938]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3938]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
[4722]22using System.Collections.Generic;
23using HeuristicLab.Common;
[4068]24using HeuristicLab.Core;
[3938]25using HeuristicLab.Data;
[4174]26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[3938]27
28namespace HeuristicLab.Problems.VehicleRouting.Encodings {
[4174]29  [StorableClass]
30  public class Tour : Item {
31    [Storable]
32    public List<int> Cities { get; private set; }
33
[4722]34    [StorableConstructor]
35    protected Tour(bool deserializing) : base(deserializing) { }
36    protected Tour(Tour original, Cloner cloner)
37      : base(original, cloner) {
38      Cities = new List<int>(original.Cities);
39    }
[4174]40    public Tour() {
41      Cities = new List<int>();
42    }
43
44    public override IDeepCloneable Clone(Cloner cloner) {
[4722]45      return new Tour(this, cloner);
[4174]46    }
47
48    public bool Feasible(DoubleArray dueTimeArray,
49      DoubleArray serviceTimeArray, DoubleArray readyTimeArray, DoubleArray demandArray, DoubleValue capacity,
[6449]50      DistanceMatrix distMatrix) {
[4174]51      TourEvaluation eval = VRPEvaluator.EvaluateTour(this,
52        dueTimeArray,
53        serviceTimeArray,
54        readyTimeArray,
55        demandArray,
56        capacity,
57        new DoubleValue(0),
58        new DoubleValue(0),
59        new DoubleValue(0),
60        new DoubleValue(1),
61        new DoubleValue(1),
[6449]62        distMatrix);
[4174]63
64      return eval.Overload < double.Epsilon && eval.Tardiness < double.Epsilon;
65    }
[4722]66
[6449]67    public double GetLength(DistanceMatrix distMatrix) {
[4174]68      double length = 0;
69
70      if (Cities.Count > 0) {
71        List<int> cities = new List<int>();
72        cities.Add(0);
73        foreach (int city in Cities) {
74          cities.Add(city);
75        }
76        cities.Add(0);
77
78        for (int i = 1; i < cities.Count; i++) {
79          length += VRPUtilities.GetDistance(
[6449]80            cities[i - 1], cities[i], distMatrix);
[4174]81        }
82      }
83
84      return length;
85    }
[3938]86  }
87}
Note: See TracBrowser for help on using the repository browser.