Free cookie consent management tool by TermsFeed Policy Generator

source: branches/SpectralKernelForGaussianProcesses/HeuristicLab.Problems.VehicleRouting/3.4/Improver/VRPImprovementOperator.cs @ 10479

Last change on this file since 10479 was 10479, checked in by gkronber, 10 years ago

#2124 merged all changes from trunk to prepare for trunk-reintegration

File size: 4.4 KB
RevLine 
[8346]1#region License Information
2/* HeuristicLab
[9456]3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[8346]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 System;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using HeuristicLab.Problems.VehicleRouting.Encodings;
30using HeuristicLab.Problems.VehicleRouting.Encodings.Potvin;
31using HeuristicLab.Problems.VehicleRouting.Interfaces;
32using HeuristicLab.Problems.VehicleRouting.Variants;
33
34namespace HeuristicLab.Problems.VehicleRouting {
35  /// <summary>
[8894]36  /// A base class for operators which improve VRP solutions.
[8346]37  /// </summary>
[8894]38  [Item("VRPImprovementOperator", "A base class for operators which improve VRP solutions.")]
[8346]39  [StorableClass]
[8894]40  public abstract class VRPImprovementOperator : VRPOperator, IGeneralVRPOperator, ISingleObjectiveImprovementOperator {
[8346]41    #region Parameter properties
42    public ScopeParameter CurrentScopeParameter {
43      get { return (ScopeParameter)Parameters["CurrentScope"]; }
44    }
45    public IValueParameter<IntValue> ImprovementAttemptsParameter {
46      get { return (IValueParameter<IntValue>)Parameters["ImprovementAttempts"]; }
47    }
[8894]48    public IValueLookupParameter<IntValue> LocalEvaluatedSolutions {
49      get { return (IValueLookupParameter<IntValue>)Parameters["LocalEvaluatedSolutions"]; }
[8346]50    }
51    public ILookupParameter<IRandom> RandomParameter {
52      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
53    }
54    public IValueParameter<IntValue> SampleSizeParameter {
55      get { return (IValueParameter<IntValue>)Parameters["SampleSize"]; }
56    }
57    public IValueLookupParameter<IItem> SolutionParameter {
58      get { return (IValueLookupParameter<IItem>)Parameters["Solution"]; }
59    }
60    #endregion
61
62    [StorableConstructor]
[8894]63    protected VRPImprovementOperator(bool deserializing) : base(deserializing) { }
64    protected VRPImprovementOperator(VRPImprovementOperator original, Cloner cloner) : base(original, cloner) { }
65    protected VRPImprovementOperator()
[8346]66      : base() {
67      #region Create parameters
68      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the solution to be improved."));
69      Parameters.Add(new ValueParameter<IntValue>("ImprovementAttempts", "The number of improvement attempts the operator should perform.", new IntValue(100)));
[8894]70      Parameters.Add(new ValueLookupParameter<IntValue>("LocalEvaluatedSolutions", "The number of evaluated solutions."));
[8346]71      Parameters.Add(new LookupParameter<IRandom>("Random", "A pseudo random number generator."));
[8894]72      Parameters.Add(new ValueParameter<IntValue>("SampleSize", "The number of moves that should be executed.", new IntValue(25)));
[8346]73      Parameters.Add(new ValueLookupParameter<IItem>("Solution", "The solution to be improved. This parameter is used for name translation only."));
74      #endregion
75    }
76
[10479]77    public override IOperation InstrumentedApply() {
[8894]78      var solution = SolutionParameter.ActualValue as IVRPEncoding;
79      var potvinSolution = solution is PotvinEncoding ? solution as PotvinEncoding : PotvinEncoding.ConvertFrom(solution, ProblemInstance);
[8346]80
81      if (solution == null)
82        throw new ArgumentException("Cannot improve solution because it has the wrong type.");
83
[8894]84      int evaluatedSolutions = Improve(potvinSolution);
[8346]85
[8894]86      SolutionParameter.ActualValue = solution;
87      LocalEvaluatedSolutions.ActualValue = new IntValue(evaluatedSolutions);
[8346]88
[10479]89      return base.InstrumentedApply();
[8346]90    }
[8894]91
92    protected abstract int Improve(PotvinEncoding solution);
[8346]93  }
94}
Note: See TracBrowser for help on using the repository browser.