Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs @ 4360

Last change on this file since 4360 was 4360, checked in by svonolfe, 14 years ago

Create VRP branch for 3.4 (#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.Drawing;
25using System.Linq;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29using HeuristicLab.Encodings.PermutationEncoding;
30using HeuristicLab.Optimization;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
33using HeuristicLab.PluginInfrastructure;
34
35namespace HeuristicLab.Problems.VehicleRouting {
36  [Item("Vehicle Routing Problem", "Represents a Vehicle Routing Problem.")]
37  [Creatable("Problems")]
38  [StorableClass]
39  public sealed class VehicleRoutingProblem : ParameterizedNamedItem, ISingleObjectiveProblem {
40    public override Image ItemImage {
41      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; }
42    }
43
44    #region ISingleObjectiveProblem Members
45    public IParameter BestKnownQualityParameter {
46      get { throw new NotImplementedException(); }
47    }
48
49    public ISingleObjectiveEvaluator Evaluator {
50      get { throw new NotImplementedException(); }
51    }
52
53    #endregion
54
55    #region IProblem Members
56    public IParameter SolutionCreatorParameter {
57      get { throw new NotImplementedException(); }
58    }
59
60    public ISolutionCreator SolutionCreator {
61      get { throw new NotImplementedException(); }
62    }
63
64    public IParameter EvaluatorParameter {
65      get { throw new NotImplementedException(); }
66    }
67
68    IEvaluator IProblem.Evaluator {
69      get { throw new NotImplementedException(); }
70    }
71
72    public IEnumerable<IOperator> Operators {
73      get { throw new NotImplementedException(); }
74    }
75    #endregion
76
77    #region Parameter Properties
78    public ValueParameter<BoolValue> MaximizationParameter {
79      get { return (ValueParameter<BoolValue>)Parameters["Maximization"]; }
80    }
81    IParameter ISingleObjectiveProblem.MaximizationParameter {
82      get { return MaximizationParameter; }
83    }
84    #endregion
85
86    #region Properties
87   
88    #endregion
89
90    [Storable]
91    private List<IOperator> operators;
92
93    [StorableConstructor]
94    private VehicleRoutingProblem(bool deserializing) : base(deserializing) { }
95    public VehicleRoutingProblem()
96      : base() {
97      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the Vehicle Routing Problem is a minimization problem.", new BoolValue(false)));
98   
99      InitializeRandomVRPInstance();
100
101      ParameterizeSolutionCreator();
102      ParameterizeEvaluator();
103
104      InitializeOperators();
105      AttachEventHandlers();
106    }
107
108    public override IDeepCloneable Clone(Cloner cloner) {
109      VehicleRoutingProblem clone = (VehicleRoutingProblem)base.Clone(cloner);
110      clone.operators = operators.Select(x => (IOperator)cloner.Clone(x)).ToList();
111      clone.AttachEventHandlers();
112      return clone;
113    }
114
115    #region Events
116    public event EventHandler SolutionCreatorChanged;
117    private void OnSolutionCreatorChanged() {
118      EventHandler handler = SolutionCreatorChanged;
119      if (handler != null) handler(this, EventArgs.Empty);
120    }
121    public event EventHandler EvaluatorChanged;
122    private void OnEvaluatorChanged() {
123      EventHandler handler = EvaluatorChanged;
124      if (handler != null) handler(this, EventArgs.Empty);
125    }
126    public event EventHandler OperatorsChanged;
127    private void OnOperatorsChanged() {
128      EventHandler handler = OperatorsChanged;
129      if (handler != null) handler(this, EventArgs.Empty);
130    }
131    public event EventHandler Reset;
132    private void OnReset() {
133      EventHandler handler = Reset;
134      if (handler != null) handler(this, EventArgs.Empty);
135    } 
136    #endregion
137
138    #region Helpers
139    [StorableHook(HookType.AfterDeserialization)]
140    private void AfterDeserializationHook() {
141      AttachEventHandlers();
142    }
143
144    private void AttachEventHandlers() {
145     
146    }
147    private void InitializeOperators() {
148      operators = new List<IOperator>();
149      ParameterizeAnalyzer();
150      //operators.AddRange(ApplicationManager.Manager.GetInstances<IVRPOperator>().Cast<IOperator>().OrderBy(op => op.Name));
151      ParameterizeOperators();
152      UpdateMoveEvaluators();
153      InitializeMoveGenerators();
154    }
155    private void InitializeMoveGenerators() {
156     
157    }
158    private void UpdateMoveEvaluators() {
159      ParameterizeOperators();
160      OnOperatorsChanged();
161    }
162    private void ParameterizeSolutionCreator() {
163     
164    }
165    private void ParameterizeEvaluator() {
166     
167    }
168    private void ParameterizeAnalyzer() {
169     
170    }
171    private void ParameterizeOperators() {
172     
173    }
174    private void ClearDistanceMatrix() {
175     
176    }
177    #endregion
178
179    public void ImportFromSolomon(string solomonFileName) {
180      SolomonParser parser = new SolomonParser(solomonFileName);
181      parser.Parse();
182
183      this.Name = parser.ProblemName;
184
185      OnReset();
186    }
187
188    public void ImportFromTSPLib(string tspFileName) {
189      TSPLIBParser parser = new TSPLIBParser(tspFileName);
190      parser.Parse();
191
192      this.Name = parser.Name;
193      int problemSize = parser.Demands.Length;
194
195      if (parser.Depot != 1)
196        throw new Exception("Invalid depot specification");
197
198      if (parser.WeightType != TSPLIBParser.TSPLIBEdgeWeightType.EUC_2D)
199        throw new Exception("Invalid weight type");
200
201      OnReset();
202    }
203
204    public void ImportFromORLib(string orFileName) {
205      ORLIBParser parser = new ORLIBParser(orFileName);
206      parser.Parse();
207
208      this.Name = parser.Name;
209      int problemSize = parser.Demands.Length;
210
211      OnReset();
212    }
213
214    private void InitializeRandomVRPInstance() {
215      System.Random rand = new System.Random();
216
217      int cities = 100;
218    }
219  }
220}
Note: See TracBrowser for help on using the repository browser.