[3938] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Windows.Forms;
|
---|
[4722] | 24 | using HeuristicLab.Core;
|
---|
[4185] | 25 | using HeuristicLab.Core.Views;
|
---|
[4619] | 26 | using HeuristicLab.Data;
|
---|
[4722] | 27 | using HeuristicLab.MainForm;
|
---|
[4619] | 28 | using HeuristicLab.Parameters;
|
---|
[4847] | 29 | using HeuristicLab.PluginInfrastructure;
|
---|
[3938] | 30 |
|
---|
| 31 | namespace HeuristicLab.Problems.VehicleRouting.Views {
|
---|
| 32 | [View("VehicleRouting Problem View")]
|
---|
| 33 | [Content(typeof(VehicleRoutingProblem), true)]
|
---|
[4185] | 34 | public partial class VehicleRoutingProblemView : NamedItemView {
|
---|
[4847] | 35 | private VRPImportDialog vrpImportDialog;
|
---|
| 36 |
|
---|
[3938] | 37 | public new VehicleRoutingProblem Content {
|
---|
| 38 | get { return (VehicleRoutingProblem)base.Content; }
|
---|
| 39 | set { base.Content = value; }
|
---|
| 40 | }
|
---|
[4068] | 41 |
|
---|
[3938] | 42 | public VehicleRoutingProblemView() {
|
---|
| 43 | InitializeComponent();
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[4185] | 46 | protected override void DeregisterContentEvents() {
|
---|
| 47 | Content.CoordinatesParameter.ValueChanged -= new EventHandler(CoordinatesParameter_ValueChanged);
|
---|
[4619] | 48 | Content.BestKnownQualityParameter.ValueChanged -= new EventHandler(BestKnownQualityParameter_ValueChanged);
|
---|
[4185] | 49 | base.DeregisterContentEvents();
|
---|
| 50 | }
|
---|
| 51 | protected override void RegisterContentEvents() {
|
---|
| 52 | base.RegisterContentEvents();
|
---|
| 53 | Content.CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
|
---|
[4619] | 54 | Content.BestKnownQualityParameter.ValueChanged += new EventHandler(BestKnownQualityParameter_ValueChanged);
|
---|
[4185] | 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;
|
---|
[4619] | 64 | UpdateSolution();
|
---|
[4185] | 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | protected override void SetEnabledStateOfControls() {
|
---|
| 69 | base.SetEnabledStateOfControls();
|
---|
| 70 | parameterCollectionView.Enabled = Content != null;
|
---|
| 71 | vrpSolutionView.Enabled = Content != null;
|
---|
[4847] | 72 | importButton.Enabled = Content != null && !ReadOnly;
|
---|
[4185] | 73 | }
|
---|
| 74 |
|
---|
[3938] | 75 | private void importButton_Click(object sender, EventArgs e) {
|
---|
[4847] | 76 | if (vrpImportDialog == null) vrpImportDialog = new VRPImportDialog();
|
---|
[3938] | 77 |
|
---|
[4847] | 78 | if (vrpImportDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 79 | try {
|
---|
| 80 | switch (vrpImportDialog.Format) {
|
---|
| 81 | case VRPFormat.TSPLib:
|
---|
| 82 | Content.ImportFromTSPLib(vrpImportDialog.VRPFileName);
|
---|
| 83 | break;
|
---|
[4185] | 84 |
|
---|
[4847] | 85 | case VRPFormat.Solomon:
|
---|
| 86 | Content.ImportFromSolomon(vrpImportDialog.VRPFileName);
|
---|
| 87 | break;
|
---|
[4352] | 88 |
|
---|
[4847] | 89 | case VRPFormat.ORLib:
|
---|
| 90 | Content.ImportFromORLib(vrpImportDialog.VRPFileName);
|
---|
| 91 | break;
|
---|
| 92 | }
|
---|
[4352] | 93 |
|
---|
[4847] | 94 | if(!string.IsNullOrEmpty(vrpImportDialog.TourFileName))
|
---|
| 95 | Content.ImportSolution(vrpImportDialog.TourFileName);
|
---|
| 96 | }
|
---|
| 97 | catch (Exception ex) {
|
---|
| 98 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
| 99 | }
|
---|
[4619] | 100 | }
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[4185] | 103 | private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 104 | vrpSolutionView.Content.Coordinates = Content.Coordinates;
|
---|
[4619] | 105 | }
|
---|
| 106 |
|
---|
| 107 | private void UpdateSolution() {
|
---|
| 108 | if (Content.BestKnownSolution == null)
|
---|
| 109 | vrpSolutionView.Content = new VRPSolution(Content.Coordinates);
|
---|
| 110 | else {
|
---|
[4852] | 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);
|
---|
[4619] | 147 | }
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | void BestKnownQualityParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 151 | UpdateSolution();
|
---|
| 152 | }
|
---|
[3938] | 153 | }
|
---|
| 154 | }
|
---|