Free cookie consent management tool by TermsFeed Policy Generator

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

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

removed duplicate analyzer (#1177)

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