Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWProblemInstance.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.2 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("CVRPPDTWProblemInstance", "Represents a single depot CVRPPDTW instance.")]
38  [StorableClass]
39  public class CVRPPDTWProblemInstance: CVRPTWProblemInstance, IPickupAndDeliveryProblemInstance {
40    protected IValueParameter<IntArray> PickupDeliveryLocationParameter {
41      get { return (IValueParameter<IntArray>)Parameters["PickupDeliveryLocation"]; }
42    }
43    protected IValueParameter<DoubleValue> PickupViolationPenaltyParameter {
44      get { return (IValueParameter<DoubleValue>)Parameters["EvalPickupViolationPenalty"]; }
45    }
46   
47    public IntArray PickupDeliveryLocation {
48      get { return PickupDeliveryLocationParameter.Value; }
49      set { PickupDeliveryLocationParameter.Value = value; }
50    }
51
52    protected IValueParameter<DoubleValue> CurrentPickupViolationPenaltyParameter {
53      get { return (IValueParameter<DoubleValue>)Parameters["CurrentPickupViolationPenalty"]; }
54    }
55
56    public DoubleValue PickupViolationPenalty {
57      get {
58        DoubleValue currentPickupViolationPenalty = CurrentPickupViolationPenaltyParameter.Value;
59        if (currentPickupViolationPenalty != null)
60          return currentPickupViolationPenalty;
61        else
62          return PickupViolationPenaltyParameter.Value;
63      }
64      set { CurrentPickupViolationPenaltyParameter.Value = value; }
65    }
66
67    protected override IEnumerable<IOperator> GetOperators() {
68      return
69        ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()
70        .Where(o => !(o is IAnalyzer))
71        .Cast<IOperator>().Union(base.GetOperators());
72    }
73
74    protected override IEnumerable<IOperator> GetAnalyzers() {
75      return ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()
76        .Where(o => o is IAnalyzer)
77        .Cast<IOperator>().Union(base.GetAnalyzers());
78    }
79   
80    protected override IVRPEvaluator Evaluator {
81      get {
82        return new CVRPPDTWEvaluator();
83      }
84    }
85
86    public int GetPickupDeliveryLocation(int city) {
87      return PickupDeliveryLocation[city];
88    }
89   
90    [StorableConstructor]
91    protected CVRPPDTWProblemInstance(bool deserializing) : base(deserializing) { }
92
93    public CVRPPDTWProblemInstance() {
94      Parameters.Add(new ValueParameter<IntArray>("PickupDeliveryLocation", "The pickup and delivery location for each customer.", new IntArray()));
95
96      Parameters.Add(new ValueParameter<DoubleValue>("EvalPickupViolationPenalty", "The pickup violation penalty considered in the evaluation.", new DoubleValue(100)));
97      Parameters.Add(new OptionalValueParameter<DoubleValue>("CurrentPickupViolationPenalty", "The current pickup violation penalty considered in the evaluation."));
98
99      AttachEventHandlers();
100    }
101
102    public override IDeepCloneable Clone(Cloner cloner) {
103      return new CVRPPDTWProblemInstance(this, cloner);
104    }
105
106    protected CVRPPDTWProblemInstance(CVRPPDTWProblemInstance original, Cloner cloner)
107      : base(original, cloner) {
108        AttachEventHandlers();
109    }
110
111    [StorableHook(HookType.AfterDeserialization)]
112    private void AfterDeserializationHook() {
113      AttachEventHandlers();
114    }
115
116    private void AttachEventHandlers() {
117      PickupDeliveryLocationParameter.ValueChanged += new EventHandler(PickupDeliveryLocationParameter_ValueChanged);
118    }
119
120    public override void InitializeState() {
121      base.InitializeState();
122
123      CurrentPickupViolationPenaltyParameter.Value = null;
124    }
125
126    #region Event handlers
127    void PickupDeliveryLocationParameter_ValueChanged(object sender, EventArgs e) {
128      PickupDeliveryLocationParameter.Value.ItemChanged += new EventHandler<EventArgs<int>>(Value_ItemChanged);
129      EvalBestKnownSolution();
130    }
131
132    void Value_ItemChanged(object sender, EventArgs<int> e) {
133      EvalBestKnownSolution();
134    }
135    #endregion
136  }
137}
Note: See TracBrowser for help on using the repository browser.