[4369] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12012] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[4369] | 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;
|
---|
[8053] | 23 | using HeuristicLab.Common;
|
---|
[4369] | 24 | using HeuristicLab.Core;
|
---|
[8053] | 25 | using HeuristicLab.Data;
|
---|
[4369] | 26 | using HeuristicLab.Optimization;
|
---|
| 27 | using HeuristicLab.Parameters;
|
---|
[8053] | 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[4369] | 29 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.Problems.VehicleRouting.Encodings.General {
|
---|
| 32 | [Item("VRPMoveMaker", "Performs a VRP move.")]
|
---|
| 33 | [StorableClass]
|
---|
[11970] | 34 | public abstract class VRPMoveMaker : VRPMoveOperator, IMoveMaker, ISingleObjectiveOperator {
|
---|
[4369] | 35 | public ILookupParameter<DoubleValue> QualityParameter {
|
---|
| 36 | get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
| 37 | }
|
---|
| 38 | public ILookupParameter<DoubleValue> MoveQualityParameter {
|
---|
| 39 | get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
|
---|
| 40 | }
|
---|
[5127] | 41 | public ILookupParameter<DoubleValue> MovePenaltyParameter {
|
---|
| 42 | get { return (ILookupParameter<DoubleValue>)Parameters["MovePenalty"]; }
|
---|
| 43 | }
|
---|
[4369] | 44 |
|
---|
| 45 | [StorableConstructor]
|
---|
| 46 | protected VRPMoveMaker(bool deserializing) : base(deserializing) { }
|
---|
| 47 |
|
---|
| 48 | public VRPMoveMaker()
|
---|
| 49 | : base() {
|
---|
| 50 | Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the solution."));
|
---|
| 51 | Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move."));
|
---|
[5127] | 52 | Parameters.Add(new LookupParameter<DoubleValue>("MovePenalty", "The penalty applied to the move."));
|
---|
[4369] | 53 | }
|
---|
| 54 |
|
---|
[4752] | 55 | protected VRPMoveMaker(VRPMoveMaker original, Cloner cloner)
|
---|
| 56 | : base(original, cloner) {
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[4369] | 59 | protected abstract void PerformMove();
|
---|
| 60 |
|
---|
| 61 | private void UpdateMoveEvaluation() {
|
---|
[7852] | 62 | IVRPEvaluator evaluator = ProblemInstance.SolutionEvaluator;
|
---|
[4370] | 63 | ICollection<IParameter> addedParameters = new List<IParameter>();
|
---|
[8053] | 64 |
|
---|
[4370] | 65 | try {
|
---|
| 66 | foreach (IParameter parameter in evaluator.Parameters) {
|
---|
[8053] | 67 | if (parameter is ILookupParameter
|
---|
| 68 | && parameter != evaluator.VRPToursParameter
|
---|
[4370] | 69 | && parameter != evaluator.ProblemInstanceParameter) {
|
---|
| 70 | ILookupParameter evaluatorParameter = parameter as ILookupParameter;
|
---|
[8053] | 71 |
|
---|
[4370] | 72 | string resultName = evaluatorParameter.ActualName;
|
---|
[6607] | 73 | if (!this.Parameters.ContainsKey(resultName)) {
|
---|
[4370] | 74 | ILookupParameter resultParameter = new LookupParameter<IItem>(resultName);
|
---|
| 75 | resultParameter.ExecutionContext = ExecutionContext;
|
---|
| 76 | this.Parameters.Add(resultParameter);
|
---|
| 77 | addedParameters.Add(resultParameter);
|
---|
| 78 | }
|
---|
[4369] | 79 |
|
---|
[4370] | 80 | string moveResultName = VRPMoveEvaluator.MovePrefix + resultName;
|
---|
[6607] | 81 | if (!this.Parameters.ContainsKey(moveResultName)) {
|
---|
[4370] | 82 | ILookupParameter moveResultParameter = new LookupParameter<IItem>(moveResultName);
|
---|
[8053] | 83 | moveResultParameter.ExecutionContext = ExecutionContext;
|
---|
[4370] | 84 | this.Parameters.Add(moveResultParameter);
|
---|
| 85 | addedParameters.Add(moveResultParameter);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | ILookupParameter result = Parameters[resultName] as ILookupParameter;
|
---|
| 89 | ILookupParameter moveResult = Parameters[moveResultName] as ILookupParameter;
|
---|
[6607] | 90 | result.ActualValue = moveResult.ActualValue;
|
---|
[4369] | 91 | }
|
---|
| 92 | }
|
---|
[11970] | 93 | } finally {
|
---|
[8053] | 94 | foreach (IParameter parameter in addedParameters) {
|
---|
[4370] | 95 | this.Parameters.Remove(parameter);
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
[4369] | 98 | }
|
---|
| 99 |
|
---|
[10298] | 100 | public override IOperation InstrumentedApply() {
|
---|
[4369] | 101 | PerformMove();
|
---|
| 102 | UpdateMoveEvaluation();
|
---|
[8053] | 103 |
|
---|
[10298] | 104 | return base.InstrumentedApply();
|
---|
[4369] | 105 | }
|
---|
| 106 | }
|
---|
| 107 | }
|
---|