Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWProblemInstance.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: 6.6 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
74    protected IValueParameter<DoubleValue> CurrentTardinessPenaltyParameter {
75      get { return (IValueParameter<DoubleValue>)Parameters["CurrentTardinessPenalty"]; }
76    }
77
78    public DoubleValue TardinessPenalty {
79      get {
80        DoubleValue currentTardinessPenalty = CurrentTardinessPenaltyParameter.Value;
81        if (currentTardinessPenalty != null)
82          return currentTardinessPenalty;
83        else
84          return TardinessPenaltyParameter.Value;
85      }
86      set { CurrentTardinessPenaltyParameter.Value = value; }
87    }
88
89    protected override IEnumerable<IOperator> GetOperators() {
90      return base.GetOperators()
91        .Where(o => o is ITimeWindowedOperator).Cast<IOperator>();
92    }
93
94    protected override IEnumerable<IOperator> GetAnalyzers() {
95      return ApplicationManager.Manager.GetInstances<ITimeWindowedOperator>()
96        .Where(o => o is IAnalyzer)
97        .Cast<IOperator>().Union(base.GetAnalyzers());
98    }
99   
100    protected override IVRPEvaluator Evaluator {
101      get {
102        return new CVRPTWEvaluator();
103      }
104    }
105   
106    [StorableConstructor]
107    protected CVRPTWProblemInstance(bool deserializing) : base(deserializing) { }
108
109    public CVRPTWProblemInstance() {
110      Parameters.Add(new ValueParameter<DoubleArray>("ReadyTime", "The ready time of each customer.", new DoubleArray()));
111      Parameters.Add(new ValueParameter<DoubleArray>("DueTime", "The due time of each customer.", new DoubleArray()));
112      Parameters.Add(new ValueParameter<DoubleArray>("ServiceTime", "The service time of each customer.", new DoubleArray()));
113
114      Parameters.Add(new ValueParameter<DoubleValue>("EvalTimeFactor", "The time factor considered in the evaluation.", new DoubleValue(0)));
115      Parameters.Add(new ValueParameter<DoubleValue>("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation.", new DoubleValue(100)));
116      Parameters.Add(new OptionalValueParameter<DoubleValue>("CurrentTardinessPenalty", "The current tardiness penalty considered in the evaluation."));
117
118      AttachEventHandlers();
119    }
120
121    public override IDeepCloneable Clone(Cloner cloner) {
122      return new CVRPTWProblemInstance(this, cloner);
123    }
124
125    protected CVRPTWProblemInstance(CVRPTWProblemInstance original, Cloner cloner)
126      : base(original, cloner) {
127        AttachEventHandlers();
128    }
129
130    [StorableHook(HookType.AfterDeserialization)]
131    private void AfterDeserializationHook() {
132      AttachEventHandlers();
133    }
134
135    private void AttachEventHandlers() {
136      TardinessPenaltyParameter.ValueChanged += new EventHandler(TardinessPenaltyParameter_ValueChanged);
137      TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
138      TimeFactorParameter.ValueChanged += new EventHandler(TimeFactorParameter_ValueChanged);
139      TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
140    }
141
142    public override void InitializeState() {
143      base.InitializeState();
144
145      CurrentTardinessPenaltyParameter.Value = null;
146    }
147
148    #region Event handlers
149    void TardinessPenaltyParameter_ValueChanged(object sender, EventArgs e) {
150      TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
151      EvalBestKnownSolution();
152    }
153    void TardinessPenalty_ValueChanged(object sender, EventArgs e) {
154      EvalBestKnownSolution();
155    }
156    void TimeFactorParameter_ValueChanged(object sender, EventArgs e) {
157      TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
158      EvalBestKnownSolution();
159    }
160    void TimeFactor_ValueChanged(object sender, EventArgs e) {
161      EvalBestKnownSolution();
162    }
163    #endregion
164  }
165}
Note: See TracBrowser for help on using the repository browser.