Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPTWProblemInstance.cs @ 6883

Last change on this file since 6883 was 6854, checked in by svonolfe, 13 years ago

Added support for the multi depot CVRP with time windows (#1177)

File size: 6.3 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("MDCVRPTWProblemInstance", "Represents a multi depot CVRPTW instance.")]
38  [StorableClass]
39  public class MDCVRPTWProblemInstance: MDCVRPProblemInstance, ITimeWindowedProblemInstance {
40    protected IValueParameter<DoubleArray> ReadyTimeParameter {
41      get { return (IValueParameter<DoubleArray>)Parameters["ReadyTime"]; }
42    }
43    protected IValueParameter<DoubleArray> DueTimeParameter {
44      get { return (IValueParameter<DoubleArray>)Parameters["DueTime"]; }
45    }
46    protected IValueParameter<DoubleArray> ServiceTimeParameter {
47      get { return (IValueParameter<DoubleArray>)Parameters["ServiceTime"]; }
48    }
49
50    protected IValueParameter<DoubleValue> TimeFactorParameter {
51      get { return (IValueParameter<DoubleValue>)Parameters["EvalTimeFactor"]; }
52    }
53    protected IValueParameter<DoubleValue> TardinessPenaltyParameter {
54      get { return (IValueParameter<DoubleValue>)Parameters["EvalTardinessPenalty"]; }
55    }
56
57    public DoubleArray ReadyTime {
58      get { return ReadyTimeParameter.Value; }
59      set { ReadyTimeParameter.Value = value; }
60    }
61    public DoubleArray DueTime {
62      get { return DueTimeParameter.Value; }
63      set { DueTimeParameter.Value = value; }
64    }
65    public DoubleArray ServiceTime {
66      get { return ServiceTimeParameter.Value; }
67      set { ServiceTimeParameter.Value = value; }
68    }
69    public DoubleValue TimeFactor {
70      get { return TimeFactorParameter.Value; }
71      set { TimeFactorParameter.Value = value; }
72    }
73
74    [Storable]
75    private DoubleValue currentTardinessPenalty;
76
77    public DoubleValue TardinessPenalty {
78      get {
79        if (currentTardinessPenalty != null)
80          return currentTardinessPenalty;
81        else
82          return TardinessPenaltyParameter.Value;
83      }
84      set { currentTardinessPenalty = value; }
85    }
86
87    protected override IEnumerable<IOperator> GetOperators() {
88      return base.GetOperators()
89        .Where(o => o is ITimeWindowedOperator).Cast<IOperator>();
90    }
91
92    protected override IEnumerable<IOperator> GetAnalyzers() {
93      return ApplicationManager.Manager.GetInstances<ITimeWindowedOperator>()
94        .Where(o => o is IAnalyzer)
95        .Cast<IOperator>().Union(base.GetAnalyzers());
96    }
97   
98    protected override IVRPEvaluator Evaluator {
99      get {
100        return new MDCVRPTWEvaluator();
101      }
102    }
103   
104    [StorableConstructor]
105    protected MDCVRPTWProblemInstance(bool deserializing) : base(deserializing) { }
106
107    public MDCVRPTWProblemInstance() {
108      Parameters.Add(new ValueParameter<DoubleArray>("ReadyTime", "The ready time of each customer.", new DoubleArray()));
109      Parameters.Add(new ValueParameter<DoubleArray>("DueTime", "The due time of each customer.", new DoubleArray()));
110      Parameters.Add(new ValueParameter<DoubleArray>("ServiceTime", "The service time of each customer.", new DoubleArray()));
111
112      Parameters.Add(new ValueParameter<DoubleValue>("EvalTimeFactor", "The time factor considered in the evaluation.", new DoubleValue(0)));
113      Parameters.Add(new ValueParameter<DoubleValue>("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation.", new DoubleValue(100)));
114
115      AttachEventHandlers();
116    }
117
118    public override IDeepCloneable Clone(Cloner cloner) {
119      return new MDCVRPTWProblemInstance(this, cloner);
120    }
121
122    protected MDCVRPTWProblemInstance(MDCVRPTWProblemInstance original, Cloner cloner)
123      : base(original, cloner) {
124        currentTardinessPenalty = cloner.Clone(original.currentTardinessPenalty) as DoubleValue;
125
126        AttachEventHandlers();
127    }
128
129    [StorableHook(HookType.AfterDeserialization)]
130    private void AfterDeserializationHook() {
131      AttachEventHandlers();
132    }
133
134    private void AttachEventHandlers() {
135      TardinessPenaltyParameter.ValueChanged += new EventHandler(TardinessPenaltyParameter_ValueChanged);
136      TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
137      TimeFactorParameter.ValueChanged += new EventHandler(TimeFactorParameter_ValueChanged);
138      TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
139    }
140
141    public override void InitializeState() {
142      base.InitializeState();
143
144      currentTardinessPenalty = null;
145    }
146
147    #region Event handlers
148    void TardinessPenaltyParameter_ValueChanged(object sender, EventArgs e) {
149      TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
150      EvalBestKnownSolution();
151    }
152    void TardinessPenalty_ValueChanged(object sender, EventArgs e) {
153      EvalBestKnownSolution();
154    }
155    void TimeFactorParameter_ValueChanged(object sender, EventArgs e) {
156      TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
157      EvalBestKnownSolution();
158    }
159    void TimeFactor_ValueChanged(object sender, EventArgs e) {
160      EvalBestKnownSolution();
161    }
162    #endregion
163  }
164}
Note: See TracBrowser for help on using the repository browser.