Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/19/10 13:22:55 (14 years ago)
Author:
svonolfe
Message:

Add best known solution import for the VRP (TSPLib format) #1236

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.VehicleRouting.Views/3.3/VehicleRoutingProblemView.cs

    r4352 r4619  
    2626using HeuristicLab.Core.Views;
    2727using HeuristicLab.Core;
     28using HeuristicLab.Data;
     29using HeuristicLab.Parameters;
    2830
    2931namespace HeuristicLab.Problems.VehicleRouting.Views {
     
    4244    protected override void DeregisterContentEvents() {
    4345      Content.CoordinatesParameter.ValueChanged -= new EventHandler(CoordinatesParameter_ValueChanged);
     46      Content.BestKnownQualityParameter.ValueChanged -= new EventHandler(BestKnownQualityParameter_ValueChanged);
    4447      base.DeregisterContentEvents();
    4548    }
     
    4750      base.RegisterContentEvents();
    4851      Content.CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
     52      Content.BestKnownQualityParameter.ValueChanged += new EventHandler(BestKnownQualityParameter_ValueChanged);
    4953    }
    5054
     
    5660      } else {
    5761        parameterCollectionView.Content = ((IParameterizedNamedItem)Content).Parameters;
    58         vrpSolutionView.Content = new VRPSolution(Content.Coordinates);
     62        UpdateSolution();
    5963      }
    6064    }
     
    6468      parameterCollectionView.Enabled = Content != null;
    6569      vrpSolutionView.Enabled = Content != null;
    66       importButton.Enabled = importButton2.Enabled = importButton3.Enabled = Content != null && !ReadOnly;
     70      importBestButton.Enabled = importButton.Enabled = importButton2.Enabled = importButton3.Enabled = Content != null && !ReadOnly;
    6771    }
    6872
     
    8589    }
    8690
     91    private void importBestButton_Click(object sender, EventArgs e) {
     92      OpenFileDialog dialog = new OpenFileDialog();
     93      dialog.Filter = "VRP solution files (*.opt)|*.opt";
     94
     95      if (dialog.ShowDialog() == DialogResult.OK) {
     96        Content.ImportSolution(dialog.FileName);
     97      }
     98    }
     99
    87100    private void importButton3_Click(object sender, EventArgs e) {
    88101      OpenFileDialog dialog = new OpenFileDialog();
     
    96109    private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
    97110      vrpSolutionView.Content.Coordinates = Content.Coordinates;
    98     } 
     111    }
     112
     113    private void UpdateSolution() {
     114      if (Content.BestKnownSolution == null)
     115        vrpSolutionView.Content = new VRPSolution(Content.Coordinates);
     116      else {
     117        //call evaluator
     118        IValueLookupParameter<DoubleMatrix> distMatrix = new ValueLookupParameter<DoubleMatrix>("DistMatrix",
     119          Content.DistanceMatrix);
     120
     121        TourEvaluation eval = VRPEvaluator.Evaluate(
     122          Content.BestKnownSolution,
     123          Content.Vehicles,
     124          Content.DueTime,
     125          Content.ServiceTime,
     126          Content.ReadyTime,
     127          Content.Demand,
     128          Content.Capacity,
     129          Content.FleetUsageFactorParameter.Value,
     130          Content.TimeFactorParameter.Value,
     131          Content.DistanceFactorParameter.Value,
     132          Content.OverloadPenaltyParameter.Value,
     133          Content.TardinessPenaltyParameter.Value,
     134          Content.Coordinates,
     135          distMatrix,
     136          Content.UseDistanceMatrix);
     137
     138        Content.DistanceMatrix = distMatrix.Value;
     139
     140        vrpSolutionView.Content = new VRPSolution(Content.Coordinates,
     141          Content.BestKnownSolution,
     142          new DoubleValue(eval.Quality),
     143          new DoubleValue(eval.Distance),
     144          new DoubleValue(eval.Overload),
     145          new DoubleValue(eval.Tardiness),
     146          new DoubleValue(eval.TravelTime),
     147          new DoubleValue(eval.VehcilesUtilized),
     148          Content.DistanceMatrix,
     149          Content.UseDistanceMatrix,
     150          Content.ReadyTime,
     151          Content.DueTime,
     152          Content.ServiceTime);
     153      }
     154    }
     155
     156   void BestKnownQualityParameter_ValueChanged(object sender, EventArgs e) {
     157      UpdateSolution();
     158    }
    99159  }
    100160}
Note: See TracChangeset for help on using the changeset viewer.