Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPPDTW/MDCVRPPDTWProblemInstance.cs @ 11171

Last change on this file since 11171 was 11171, checked in by ascheibe, 10 years ago

#2115 merged r11170 (copyright update) into trunk

File size: 5.2 KB
RevLine 
[6856]1#region License Information
2/* HeuristicLab
[11171]3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[6856]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;
[7934]25using HeuristicLab.Common;
[6856]26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Optimization;
[7934]29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[6856]31using HeuristicLab.PluginInfrastructure;
[7934]32using HeuristicLab.Problems.VehicleRouting.Interfaces;
[6856]33using HeuristicLab.Problems.VehicleRouting.Variants;
34
35namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
36  [Item("MDCVRPPDTWProblemInstance", "Represents a multi depot CVRPPDTW instance.")]
37  [StorableClass]
[7934]38  public class MDCVRPPDTWProblemInstance : MDCVRPTWProblemInstance, IPickupAndDeliveryProblemInstance {
[6856]39    protected IValueParameter<IntArray> PickupDeliveryLocationParameter {
40      get { return (IValueParameter<IntArray>)Parameters["PickupDeliveryLocation"]; }
41    }
42    protected IValueParameter<DoubleValue> PickupViolationPenaltyParameter {
43      get { return (IValueParameter<DoubleValue>)Parameters["EvalPickupViolationPenalty"]; }
44    }
[7934]45
[6856]46    public IntArray PickupDeliveryLocation {
47      get { return PickupDeliveryLocationParameter.Value; }
48      set { PickupDeliveryLocationParameter.Value = value; }
49    }
50
[7864]51    protected IValueParameter<DoubleValue> CurrentPickupViolationPenaltyParameter {
52      get { return (IValueParameter<DoubleValue>)Parameters["CurrentPickupViolationPenalty"]; }
53    }
[6856]54
55    public DoubleValue PickupViolationPenalty {
56      get {
[7864]57        DoubleValue currentPickupViolationPenalty = CurrentPickupViolationPenaltyParameter.Value;
[6856]58        if (currentPickupViolationPenalty != null)
59          return currentPickupViolationPenalty;
60        else
61          return PickupViolationPenaltyParameter.Value;
62      }
[7864]63      set { CurrentPickupViolationPenaltyParameter.Value = value; }
[6856]64    }
65
66    protected override IEnumerable<IOperator> GetOperators() {
[7934]67      return
[6856]68        ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()
69        .Where(o => !(o is IAnalyzer))
70        .Cast<IOperator>().Union(base.GetOperators());
71    }
72
73    protected override IEnumerable<IOperator> GetAnalyzers() {
74      return ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()
75        .Where(o => o is IAnalyzer)
76        .Cast<IOperator>().Union(base.GetAnalyzers());
77    }
[7934]78
[6856]79    protected override IVRPEvaluator Evaluator {
80      get {
81        return new MDCVRPPDTWEvaluator();
82      }
83    }
84
85    public int GetPickupDeliveryLocation(int city) {
86      return PickupDeliveryLocation[city - 1];
87    }
[7934]88
[6856]89    [StorableConstructor]
90    protected MDCVRPPDTWProblemInstance(bool deserializing) : base(deserializing) { }
91
92    public MDCVRPPDTWProblemInstance() {
93      Parameters.Add(new ValueParameter<IntArray>("PickupDeliveryLocation", "The pickup and delivery location for each customer.", new IntArray()));
94
95      Parameters.Add(new ValueParameter<DoubleValue>("EvalPickupViolationPenalty", "The pickup violation penalty considered in the evaluation.", new DoubleValue(100)));
[7864]96      Parameters.Add(new OptionalValueParameter<DoubleValue>("CurrentPickupViolationPenalty", "The current pickup violation penalty considered in the evaluation."));
[6856]97
98      AttachEventHandlers();
99    }
100
101    public override IDeepCloneable Clone(Cloner cloner) {
102      return new MDCVRPPDTWProblemInstance(this, cloner);
103    }
104
105    protected MDCVRPPDTWProblemInstance(MDCVRPPDTWProblemInstance original, Cloner cloner)
106      : base(original, cloner) {
[7934]107      AttachEventHandlers();
[6856]108    }
109
110    [StorableHook(HookType.AfterDeserialization)]
[7934]111    private void AfterDeserialization() {
[6856]112      AttachEventHandlers();
113    }
114
115    private void AttachEventHandlers() {
116      PickupDeliveryLocationParameter.ValueChanged += new EventHandler(PickupDeliveryLocationParameter_ValueChanged);
117    }
118
119    public override void InitializeState() {
120      base.InitializeState();
121
[7864]122      CurrentPickupViolationPenaltyParameter.Value = null;
[6856]123    }
124
125    #region Event handlers
126    void PickupDeliveryLocationParameter_ValueChanged(object sender, EventArgs e) {
127      PickupDeliveryLocationParameter.Value.ItemChanged += new EventHandler<EventArgs<int>>(Value_ItemChanged);
128      EvalBestKnownSolution();
129    }
130
131    void Value_ItemChanged(object sender, EventArgs<int> e) {
132      EvalBestKnownSolution();
133    }
134    #endregion
135  }
136}
Note: See TracBrowser for help on using the repository browser.