Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.VehicleRouting.Views/3.3/VehicleRoutingProblemView.cs @ 5447

Last change on this file since 5447 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

File size: 5.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Windows.Forms;
24using HeuristicLab.Core;
25using HeuristicLab.Core.Views;
26using HeuristicLab.Data;
27using HeuristicLab.MainForm;
28using HeuristicLab.Parameters;
29using HeuristicLab.PluginInfrastructure;
30
31namespace HeuristicLab.Problems.VehicleRouting.Views {
32  [View("VehicleRouting Problem View")]
33  [Content(typeof(VehicleRoutingProblem), true)]
34  public partial class VehicleRoutingProblemView : NamedItemView {
35    private VRPImportDialog vrpImportDialog;
36   
37    public new VehicleRoutingProblem Content {
38      get { return (VehicleRoutingProblem)base.Content; }
39      set { base.Content = value; }
40    }
41
42    public VehicleRoutingProblemView() {
43      InitializeComponent();
44    }
45
46    protected override void DeregisterContentEvents() {
47      Content.CoordinatesParameter.ValueChanged -= new EventHandler(CoordinatesParameter_ValueChanged);
48      Content.BestKnownQualityParameter.ValueChanged -= new EventHandler(BestKnownQualityParameter_ValueChanged);
49      base.DeregisterContentEvents();
50    }
51    protected override void RegisterContentEvents() {
52      base.RegisterContentEvents();
53      Content.CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
54      Content.BestKnownQualityParameter.ValueChanged += new EventHandler(BestKnownQualityParameter_ValueChanged);
55    }
56
57    protected override void OnContentChanged() {
58      base.OnContentChanged();
59      if (Content == null) {
60        parameterCollectionView.Content = null;
61        vrpSolutionView.Content = null;
62      } else {
63        parameterCollectionView.Content = ((IParameterizedNamedItem)Content).Parameters;
64        UpdateSolution();
65      }
66    }
67
68    protected override void SetEnabledStateOfControls() {
69      base.SetEnabledStateOfControls();
70      parameterCollectionView.Enabled = Content != null;
71      vrpSolutionView.Enabled = Content != null;
72      importButton.Enabled = Content != null && !ReadOnly;
73    }
74
75    private void importButton_Click(object sender, EventArgs e) {
76      if (vrpImportDialog == null) vrpImportDialog = new VRPImportDialog();
77
78      if (vrpImportDialog.ShowDialog(this) == DialogResult.OK) {
79        try {
80          switch (vrpImportDialog.Format) {
81            case VRPFormat.TSPLib:
82              Content.ImportFromTSPLib(vrpImportDialog.VRPFileName);
83              break;
84
85            case VRPFormat.Solomon:
86              Content.ImportFromSolomon(vrpImportDialog.VRPFileName);
87              break;
88
89            case VRPFormat.ORLib:
90              Content.ImportFromORLib(vrpImportDialog.VRPFileName);
91              break;
92          }
93
94          if(!string.IsNullOrEmpty(vrpImportDialog.TourFileName))
95            Content.ImportSolution(vrpImportDialog.TourFileName);
96         }
97        catch (Exception ex) {
98          ErrorHandling.ShowErrorDialog(this, ex);
99        }
100      }
101    }
102
103    private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
104      vrpSolutionView.Content.Coordinates = Content.Coordinates;
105    }
106
107    private void UpdateSolution() {
108      if (Content.BestKnownSolution == null)
109        vrpSolutionView.Content = new VRPSolution(Content.Coordinates);
110      else {
111        //call evaluator
112        IValueLookupParameter<DoubleMatrix> distMatrix = new ValueLookupParameter<DoubleMatrix>("DistMatrix",
113          Content.DistanceMatrix);
114
115        TourEvaluation eval = VRPEvaluator.Evaluate(
116          Content.BestKnownSolution,
117          Content.Vehicles,
118          Content.DueTime,
119          Content.ServiceTime,
120          Content.ReadyTime,
121          Content.Demand,
122          Content.Capacity,
123          Content.FleetUsageFactorParameter.Value,
124          Content.TimeFactorParameter.Value,
125          Content.DistanceFactorParameter.Value,
126          Content.OverloadPenaltyParameter.Value,
127          Content.TardinessPenaltyParameter.Value,
128          Content.Coordinates,
129          distMatrix,
130          Content.UseDistanceMatrix);
131
132        Content.DistanceMatrix = distMatrix.Value;
133
134        vrpSolutionView.Content = new VRPSolution(Content.Coordinates,
135          Content.BestKnownSolution,
136          new DoubleValue(eval.Quality),
137          new DoubleValue(eval.Distance),
138          new DoubleValue(eval.Overload),
139          new DoubleValue(eval.Tardiness),
140          new DoubleValue(eval.TravelTime),
141          new DoubleValue(eval.VehcilesUtilized),
142          Content.DistanceMatrix,
143          Content.UseDistanceMatrix,
144          Content.ReadyTime,
145          Content.DueTime,
146          Content.ServiceTime);
147      }
148    }
149
150   void BestKnownQualityParameter_ValueChanged(object sender, EventArgs e) {
151      UpdateSolution();
152    }
153  }
154}
Note: See TracBrowser for help on using the repository browser.