[4362] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 | using HeuristicLab.Core;
|
---|
| 29 | using HeuristicLab.Parameters;
|
---|
| 30 | using HeuristicLab.Data;
|
---|
| 31 | using HeuristicLab.Optimization;
|
---|
| 32 | using HeuristicLab.PluginInfrastructure;
|
---|
[4363] | 33 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
[4752] | 34 | using HeuristicLab.Common;
|
---|
[4362] | 35 |
|
---|
| 36 | namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
|
---|
| 37 | [Item("CVRPProblemInstance", "Represents a single depot CVRP instance.")]
|
---|
| 38 | [StorableClass]
|
---|
[4376] | 39 | public class CVRPProblemInstance: SingleDepotVRPProblemInstance, IHomogenousCapacitatedProblemInstance {
|
---|
[4363] | 40 | protected IValueParameter<DoubleValue> CapacityParameter {
|
---|
| 41 | get { return (IValueParameter<DoubleValue>)Parameters["Capacity"]; }
|
---|
[4362] | 42 | }
|
---|
[4363] | 43 | protected IValueParameter<DoubleValue> OverloadPenaltyParameter {
|
---|
[4362] | 44 | get { return (IValueParameter<DoubleValue>)Parameters["EvalOverloadPenalty"]; }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | public DoubleValue Capacity {
|
---|
| 48 | get { return CapacityParameter.Value; }
|
---|
| 49 | set { CapacityParameter.Value = value; }
|
---|
| 50 | }
|
---|
[6711] | 51 |
|
---|
| 52 | [Storable]
|
---|
| 53 | private DoubleValue currentOverloadPenalty;
|
---|
| 54 |
|
---|
[4362] | 55 | public DoubleValue OverloadPenalty {
|
---|
[6711] | 56 | get {
|
---|
| 57 | if (currentOverloadPenalty != null)
|
---|
| 58 | return currentOverloadPenalty;
|
---|
| 59 | else
|
---|
| 60 | return OverloadPenaltyParameter.Value; }
|
---|
| 61 | set { currentOverloadPenalty = value; }
|
---|
[4362] | 62 | }
|
---|
[4374] | 63 |
|
---|
| 64 | protected override IEnumerable<IOperator> GetOperators() {
|
---|
| 65 | return base.GetOperators()
|
---|
[4376] | 66 | .Where(o => o is IHomogenousCapacitatedOperator).Cast<IOperator>();
|
---|
[4362] | 67 | }
|
---|
[4363] | 68 |
|
---|
[4374] | 69 | protected override IEnumerable<IOperator> GetAnalyzers() {
|
---|
| 70 | return ApplicationManager.Manager.GetInstances<ICapacitatedOperator>()
|
---|
| 71 | .Where(o => o is IAnalyzer)
|
---|
| 72 | .Cast<IOperator>().Union(base.GetAnalyzers());
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[4363] | 75 | protected override IVRPEvaluator Evaluator {
|
---|
| 76 | get {
|
---|
| 77 | return new CVRPEvaluator();
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
[4362] | 80 |
|
---|
| 81 | [StorableConstructor]
|
---|
| 82 | protected CVRPProblemInstance(bool deserializing) : base(deserializing) { }
|
---|
| 83 |
|
---|
| 84 | public CVRPProblemInstance() {
|
---|
| 85 | Parameters.Add(new ValueParameter<DoubleValue>("Capacity", "The capacity of each vehicle.", new DoubleValue(0)));
|
---|
[6710] | 86 | Parameters.Add(new ValueParameter<DoubleValue>("EvalOverloadPenalty", "The overload penalty considered in the evaluation.", new DoubleValue(100)));
|
---|
[4860] | 87 |
|
---|
| 88 | AttachEventHandlers();
|
---|
[4362] | 89 | }
|
---|
[4752] | 90 |
|
---|
| 91 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 92 | return new CVRPProblemInstance(this, cloner);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | protected CVRPProblemInstance(CVRPProblemInstance original, Cloner cloner)
|
---|
| 96 | : base(original, cloner) {
|
---|
[6711] | 97 | currentOverloadPenalty = cloner.Clone(original.currentOverloadPenalty) as DoubleValue;
|
---|
| 98 |
|
---|
[4860] | 99 | AttachEventHandlers();
|
---|
[4752] | 100 | }
|
---|
[4860] | 101 |
|
---|
| 102 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 103 | private void AfterDeserializationHook() {
|
---|
| 104 | AttachEventHandlers();
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | private void AttachEventHandlers() {
|
---|
| 108 | CapacityParameter.ValueChanged += new EventHandler(CapacityParameter_ValueChanged);
|
---|
| 109 | CapacityParameter.Value.ValueChanged += new EventHandler(Capacity_ValueChanged);
|
---|
| 110 | OverloadPenaltyParameter.ValueChanged += new EventHandler(OverloadPenaltyParameter_ValueChanged);
|
---|
| 111 | OverloadPenaltyParameter.Value.ValueChanged += new EventHandler(OverloadPenalty_ValueChanged);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
[6711] | 114 | public override void InitializeState() {
|
---|
| 115 | base.InitializeState();
|
---|
| 116 |
|
---|
| 117 | currentOverloadPenalty = null;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[4860] | 120 | #region Event handlers
|
---|
| 121 | void CapacityParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 122 | CapacityParameter.Value.ValueChanged += new EventHandler(Capacity_ValueChanged);
|
---|
| 123 | BestKnownSolution = null;
|
---|
| 124 | }
|
---|
| 125 | void Capacity_ValueChanged(object sender, EventArgs e) {
|
---|
| 126 | BestKnownSolution = null;
|
---|
| 127 | }
|
---|
| 128 | void OverloadPenaltyParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 129 | OverloadPenaltyParameter.Value.ValueChanged += new EventHandler(OverloadPenalty_ValueChanged);
|
---|
| 130 | EvalBestKnownSolution();
|
---|
| 131 | }
|
---|
| 132 | void OverloadPenalty_ValueChanged(object sender, EventArgs e) {
|
---|
| 133 | EvalBestKnownSolution();
|
---|
| 134 | }
|
---|
| 135 | #endregion
|
---|
[4362] | 136 | }
|
---|
| 137 | } |
---|