Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPProblemInstance.cs @ 7864

Last change on this file since 7864 was 7864, checked in by svonolfe, 12 years ago

Moved adaptive penalties to parameter values (#1177)

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