Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterBinding/HeuristicLab.Problems.VehicleRouting.Views/3.3/VehicleRoutingProblemView.cs @ 6036

Last change on this file since 6036 was 4722, checked in by swagner, 14 years ago

Merged cloning refactoring branch back into trunk (#922)

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