Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWProblemInstance.cs @ 6711

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

Added adaptive constraint relaxation for all VRP variants (#1177)

File size: 4.7 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    [Storable]
53    private DoubleValue currentPickupViolationPenalty;
54
55    public DoubleValue PickupViolationPenalty {
56      get {
57        if (currentPickupViolationPenalty != null)
58          return currentPickupViolationPenalty;
59        else
60          return PickupViolationPenaltyParameter.Value;
61      }
62      set { currentPickupViolationPenalty = value; }
63    }
64
65    protected override IEnumerable<IOperator> GetOperators() {
66      return
67        ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()
68        .Cast<IOperator>().Union(base.GetOperators());
69    }
70
71    protected override IEnumerable<IOperator> GetAnalyzers() {
72      return ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()
73        .Where(o => o is IAnalyzer)
74        .Cast<IOperator>().Union(base.GetAnalyzers());
75    }
76   
77    protected override IVRPEvaluator Evaluator {
78      get {
79        return new CVRPPDTWEvaluator();
80      }
81    }
82   
83    [StorableConstructor]
84    protected CVRPPDTWProblemInstance(bool deserializing) : base(deserializing) { }
85
86    public CVRPPDTWProblemInstance() {
87      Parameters.Add(new ValueParameter<IntArray>("PickupDeliveryLocation", "The pickup and delivery location for each customer.", new IntArray()));
88
89      Parameters.Add(new ValueParameter<DoubleValue>("EvalPickupViolationPenalty", "The pickup violation penalty considered in the evaluation.", new DoubleValue(100)));
90
91      AttachEventHandlers();
92    }
93
94    public override IDeepCloneable Clone(Cloner cloner) {
95      return new CVRPPDTWProblemInstance(this, cloner);
96    }
97
98    protected CVRPPDTWProblemInstance(CVRPPDTWProblemInstance original, Cloner cloner)
99      : base(original, cloner) {
100        currentPickupViolationPenalty = cloner.Clone(original.currentPickupViolationPenalty) as DoubleValue;
101
102        AttachEventHandlers();
103    }
104
105    [StorableHook(HookType.AfterDeserialization)]
106    private void AfterDeserializationHook() {
107      AttachEventHandlers();
108    }
109
110    private void AttachEventHandlers() {
111      PickupDeliveryLocationParameter.ValueChanged += new EventHandler(PickupDeliveryLocationParameter_ValueChanged);
112    }
113
114    public override void InitializeState() {
115      base.InitializeState();
116
117      currentPickupViolationPenalty = null;
118    }
119
120    #region Event handlers
121    void PickupDeliveryLocationParameter_ValueChanged(object sender, EventArgs e) {
122      PickupDeliveryLocationParameter.Value.ItemChanged += new EventHandler<EventArgs<int>>(Value_ItemChanged);
123      EvalBestKnownSolution();
124    }
125
126    void Value_ItemChanged(object sender, EventArgs<int> e) {
127      EvalBestKnownSolution();
128    }
129    #endregion
130  }
131}
Note: See TracBrowser for help on using the repository browser.