Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/VehicleAssignment/PotvinVehicleAssignmentSingleMoveGenerator.cs

Last change on this file was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 3.3 KB
RevLine 
[6857]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[6857]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
[8053]22using System.Collections.Generic;
23using HeuristicLab.Common;
[6857]24using HeuristicLab.Core;
25using HeuristicLab.Optimization;
[8053]26using HeuristicLab.Parameters;
[16565]27using HEAL.Attic;
[6857]28using HeuristicLab.Problems.VehicleRouting.Interfaces;
29
30namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
31  [Item("PotvinVehicleAssignmentSingleMoveGenerator", "Generates a single vehicle assignment move from a given VRP encoding.")]
[16565]32  [StorableType("437E0361-CEEE-41E4-BD20-BA40D6BB8DA4")]
[6857]33  public sealed class PotvinVehicleAssignmentSingleMoveGenerator : PotvinVehicleAssignmentMoveGenerator,
34    ISingleMoveGenerator {
35    #region IMultiVRPMoveOperator Members
36
37    public override ILookupParameter VRPMoveParameter {
38      get { return (ILookupParameter)Parameters["PotvinVehicleAssignmentMove"]; }
39    }
40
41    #endregion
[8053]42
[6857]43    public ILookupParameter<IRandom> RandomParameter {
44      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
45    }
46
47    public override IDeepCloneable Clone(Cloner cloner) {
48      return new PotvinVehicleAssignmentSingleMoveGenerator(this, cloner);
49    }
50
51    [StorableConstructor]
[16565]52    private PotvinVehicleAssignmentSingleMoveGenerator(StorableConstructorFlag _) : base(_) { }
[6857]53
54    public PotvinVehicleAssignmentSingleMoveGenerator()
55      : base() {
56      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator."));
57    }
58
[7906]59    private PotvinVehicleAssignmentSingleMoveGenerator(PotvinVehicleAssignmentSingleMoveGenerator original, Cloner cloner)
[6857]60      : base(original, cloner) {
61    }
62
63    public static PotvinVehicleAssignmentMove Apply(PotvinEncoding individual, IVRPProblemInstance problemInstance, IRandom rand) {
[6909]64      if (individual.Tours.Count > 1) {
65        int tour1 = rand.Next(individual.Tours.Count);
66        int tour2 = rand.Next(problemInstance.Vehicles.Value);
[6857]67
[6909]68        while (tour2 == tour1)
69          tour2 = rand.Next(problemInstance.Vehicles.Value);
[6857]70
[6909]71        return new PotvinVehicleAssignmentMove(tour1, tour2, individual);
72      } else {
73        return null;
74      }
[6857]75    }
76
77    protected override PotvinVehicleAssignmentMove[] GenerateMoves(PotvinEncoding individual, IVRPProblemInstance problemInstance) {
78      List<PotvinVehicleAssignmentMove> result = new List<PotvinVehicleAssignmentMove>();
79
80      PotvinVehicleAssignmentMove move = Apply(individual, ProblemInstance, RandomParameter.ActualValue);
81      if (move != null)
82        result.Add(move);
83
84      return result.ToArray();
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.