Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWProblemInstance.cs @ 4860

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

Merged changes from trunk into branch (#1177)

File size: 5.9 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("CVRPTWProblemInstance", "Represents a single depot CVRPTW instance.")]
38  [StorableClass]
39  public class CVRPTWProblemInstance: CVRPProblemInstance, 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    public DoubleValue TardinessPenalty {
74      get { return TardinessPenaltyParameter.Value; }
75      set { TardinessPenaltyParameter.Value = value; }
76    }
77
78    protected override IEnumerable<IOperator> GetOperators() {
79      return base.GetOperators()
80        .Where(o => o is ITimeWindowedOperator).Cast<IOperator>();
81    }
82
83    protected override IEnumerable<IOperator> GetAnalyzers() {
84      return ApplicationManager.Manager.GetInstances<ITimeWindowedOperator>()
85        .Where(o => o is IAnalyzer)
86        .Cast<IOperator>().Union(base.GetAnalyzers());
87    }
88   
89    protected override IVRPEvaluator Evaluator {
90      get {
91        return new CVRPTWEvaluator();
92      }
93    }
94   
95    [StorableConstructor]
96    protected CVRPTWProblemInstance(bool deserializing) : base(deserializing) { }
97
98    public CVRPTWProblemInstance() {
99      Parameters.Add(new ValueParameter<DoubleArray>("ReadyTime", "The ready time of each customer.", new DoubleArray()));
100      Parameters.Add(new ValueParameter<DoubleArray>("DueTime", "The due time of each customer.", new DoubleArray()));
101      Parameters.Add(new ValueParameter<DoubleArray>("ServiceTime", "The service time of each customer.", new DoubleArray()));
102
103      Parameters.Add(new ValueParameter<DoubleValue>("EvalTimeFactor", "The time factor considered in the evaluation.", new DoubleValue(0)));
104      Parameters.Add(new ValueParameter<DoubleValue>("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation.", new DoubleValue(100)));
105
106      AttachEventHandlers();
107    }
108
109    public override IDeepCloneable Clone(Cloner cloner) {
110      return new CVRPTWProblemInstance(this, cloner);
111    }
112
113    protected CVRPTWProblemInstance(CVRPTWProblemInstance original, Cloner cloner)
114      : base(original, cloner) {
115        AttachEventHandlers();
116    }
117
118    [StorableHook(HookType.AfterDeserialization)]
119    private void AfterDeserializationHook() {
120      AttachEventHandlers();
121    }
122
123    private void AttachEventHandlers() {
124      TardinessPenaltyParameter.ValueChanged += new EventHandler(TardinessPenaltyParameter_ValueChanged);
125      TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
126      TimeFactorParameter.ValueChanged += new EventHandler(TimeFactorParameter_ValueChanged);
127      TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
128    }
129
130    #region Event handlers
131    void TardinessPenaltyParameter_ValueChanged(object sender, EventArgs e) {
132      TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
133      EvalBestKnownSolution();
134    }
135    void TardinessPenalty_ValueChanged(object sender, EventArgs e) {
136      EvalBestKnownSolution();
137    }
138    void TimeFactorParameter_ValueChanged(object sender, EventArgs e) {
139      TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
140      EvalBestKnownSolution();
141    }
142    void TimeFactor_ValueChanged(object sender, EventArgs e) {
143      EvalBestKnownSolution();
144    }
145    #endregion
146  }
147}
Note: See TracBrowser for help on using the repository browser.