Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4619 for trunk/sources


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

Location:
trunk/sources
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.VehicleRouting.Views/3.3/HeuristicLab.Problems.VehicleRouting.Views-3.3.csproj

    r4065 r4619  
    172172      <Name>HeuristicLab.MainForm-3.3</Name>
    173173    </ProjectReference>
     174    <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
     175      <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project>
     176      <Name>HeuristicLab.Operators-3.3</Name>
     177    </ProjectReference>
    174178    <ProjectReference Include="..\..\HeuristicLab.Optimization.Views\3.3\HeuristicLab.Optimization.Views-3.3.csproj">
    175179      <Project>{662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}</Project>
  • trunk/sources/HeuristicLab.Problems.VehicleRouting.Views/3.3/HeuristicLabProblemsVehicleRoutingViewsPlugin.cs.frame

    r4497 r4619  
    3838  [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.3")]
    3939  [PluginDependency("HeuristicLab.Optimization", "3.3")]
     40  [PluginDependency("HeuristicLab.Operators", "3.3")]
    4041  [PluginDependency("HeuristicLab.Optimization.Views", "3.3")]
    4142  [PluginDependency("HeuristicLab.Parameters", "3.3")]
  • trunk/sources/HeuristicLab.Problems.VehicleRouting.Views/3.3/VRPSolutionView.Designer.cs

    r4352 r4619  
    123123      this.tourGridView.Location = new System.Drawing.Point(3, 16);
    124124      this.tourGridView.Name = "tourGridView";
     125      this.tourGridView.ReadOnly = true;
    125126      this.tourGridView.Size = new System.Drawing.Size(403, 507);
    126127      this.tourGridView.TabIndex = 0;
  • trunk/sources/HeuristicLab.Problems.VehicleRouting.Views/3.3/VehicleRoutingProblemView.Designer.cs

    r4352 r4619  
    3131      this.importButton2 = new System.Windows.Forms.Button();
    3232      this.importButton3 = new System.Windows.Forms.Button();
     33      this.importBestButton = new System.Windows.Forms.Button();
    3334      this.vrpSolutionView = new HeuristicLab.Problems.VehicleRouting.Views.VRPSolutionView();
    3435      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
     
    6061      this.tabControl1.Controls.Add(this.tabPage1);
    6162      this.tabControl1.Controls.Add(this.tabPage2);
    62       this.tabControl1.Location = new System.Drawing.Point(0, 84);
     63      this.tabControl1.Location = new System.Drawing.Point(0, 111);
    6364      this.tabControl1.Name = "tabControl1";
    6465      this.tabControl1.SelectedIndex = 0;
    65       this.tabControl1.Size = new System.Drawing.Size(490, 265);
     66      this.tabControl1.Size = new System.Drawing.Size(490, 255);
    6667      this.tabControl1.TabIndex = 6;
    6768      //
     
    7273      this.tabPage1.Name = "tabPage1";
    7374      this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
    74       this.tabPage1.Size = new System.Drawing.Size(482, 239);
     75      this.tabPage1.Size = new System.Drawing.Size(482, 229);
    7576      this.tabPage1.TabIndex = 0;
    7677      this.tabPage1.Text = "Parameters";
     
    7980      // parameterCollectionView
    8081      //
     82      this.parameterCollectionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     83                  | System.Windows.Forms.AnchorStyles.Left)
     84                  | System.Windows.Forms.AnchorStyles.Right)));
    8185      this.parameterCollectionView.Caption = "ParameterCollection View";
    8286      this.parameterCollectionView.Content = null;
    83       this.parameterCollectionView.Dock = System.Windows.Forms.DockStyle.Fill;
    8487      this.parameterCollectionView.Location = new System.Drawing.Point(3, 3);
    8588      this.parameterCollectionView.Name = "parameterCollectionView";
    8689      this.parameterCollectionView.ReadOnly = false;
    87       this.parameterCollectionView.Size = new System.Drawing.Size(476, 233);
     90      this.parameterCollectionView.Size = new System.Drawing.Size(476, 223);
    8891      this.parameterCollectionView.TabIndex = 1;
    8992      //
     
    9497      this.tabPage2.Name = "tabPage2";
    9598      this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
    96       this.tabPage2.Size = new System.Drawing.Size(482, 239);
     99      this.tabPage2.Size = new System.Drawing.Size(482, 229);
    97100      this.tabPage2.TabIndex = 1;
    98101      this.tabPage2.Text = "Visualization";
     
    119122      this.importButton3.Click += new System.EventHandler(this.importButton3_Click);
    120123      //
     124      // importBestButton
     125      //
     126      this.importBestButton.Location = new System.Drawing.Point(0, 82);
     127      this.importBestButton.Name = "importBestButton";
     128      this.importBestButton.Size = new System.Drawing.Size(139, 23);
     129      this.importBestButton.TabIndex = 9;
     130      this.importBestButton.Text = "Import solution";
     131      this.importBestButton.UseVisualStyleBackColor = true;
     132      this.importBestButton.Click += new System.EventHandler(this.importBestButton_Click);
     133      //
    121134      // vrpSolutionView
    122135      //
     
    127140      this.vrpSolutionView.Name = "vrpSolutionView";
    128141      this.vrpSolutionView.ReadOnly = false;
    129       this.vrpSolutionView.Size = new System.Drawing.Size(476, 233);
     142      this.vrpSolutionView.Size = new System.Drawing.Size(476, 223);
    130143      this.vrpSolutionView.TabIndex = 0;
    131144      //
     
    133146      //
    134147      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     148      this.Controls.Add(this.importBestButton);
    135149      this.Controls.Add(this.importButton3);
    136150      this.Controls.Add(this.importButton2);
     
    138152      this.Controls.Add(this.tabControl1);
    139153      this.Name = "VehicleRoutingProblemView";
    140       this.Size = new System.Drawing.Size(490, 352);
     154      this.Size = new System.Drawing.Size(490, 369);
    141155      this.Controls.SetChildIndex(this.tabControl1, 0);
    142156      this.Controls.SetChildIndex(this.importButton, 0);
     
    147161      this.Controls.SetChildIndex(this.importButton2, 0);
    148162      this.Controls.SetChildIndex(this.importButton3, 0);
     163      this.Controls.SetChildIndex(this.importBestButton, 0);
    149164      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    150165      this.tabControl1.ResumeLayout(false);
     
    166181    private System.Windows.Forms.Button importButton2;
    167182    private System.Windows.Forms.Button importButton3;
     183    private System.Windows.Forms.Button importBestButton;
    168184  }
    169185}
  • 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}
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/HeuristicLab.Problems.VehicleRouting-3.3.csproj

    r4352 r4619  
    110110    <Compile Include="Analyzers\BestVRPToursMemorizer.cs" />
    111111    <Compile Include="Analyzers\BestVRPSolutionAnalyzer.cs" />
     112    <Compile Include="SolutionParser.cs" />
    112113    <Compile Include="Encodings\Alba\Crossovers\AlbaPermutationCrossover.cs" />
    113114    <Compile Include="Encodings\Alba\Manipulators\AlbaIntraRouteInversionManipulator.cs" />
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/VRPUtilities.cs

    r4352 r4619  
    5656
    5757    public static double GetDistance(int start, int end,
    58       DoubleMatrix coordinates, ILookupParameter<DoubleMatrix> distanceMatrix, BoolValue useDistanceMatrix) {
     58      DoubleMatrix coordinates, IParameter distanceMatrix, BoolValue useDistanceMatrix) {
    5959      double distance = 0.0;
    6060
    6161      if (useDistanceMatrix.Value) {
    62         if (distanceMatrix is IValueLookupParameter<DoubleMatrix> &&
    63           (distanceMatrix as IValueLookupParameter<DoubleMatrix>).Value != null) {
    64             distance = (distanceMatrix as IValueLookupParameter<DoubleMatrix>).Value[start, end];
     62        if (distanceMatrix is IValueLookupParameter<DoubleMatrix>) {
     63          if ((distanceMatrix as IValueLookupParameter<DoubleMatrix>).Value == null) {
     64            (distanceMatrix as IValueLookupParameter<DoubleMatrix>).Value = CreateDistanceMatrix(coordinates);
     65          }
     66         
     67          distance = (distanceMatrix as IValueLookupParameter<DoubleMatrix>).Value[start, end];
    6568        } else {
    6669          if (distanceMatrix.ActualValue == null) {
     
    6871          }
    6972
    70           distance = distanceMatrix.ActualValue[start, end];
    71         }      
     73          distance = (distanceMatrix.ActualValue as DoubleMatrix)[start, end];
     74        }     
    7275      } else {
    7376        distance = CalculateDistance(start, end, coordinates);
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/VehicleRoutingProblem.cs

    r4419 r4619  
    9393      get { return EvaluatorParameter; }
    9494    }
    95     public IValueParameter<DoubleValue> FleetUsageFactor {
     95    public IValueParameter<DoubleValue> FleetUsageFactorParameter {
    9696      get { return (IValueParameter<DoubleValue>)Parameters["EvalFleetUsageFactor"]; }
    9797    }
    98     public IValueParameter<DoubleValue> TimeFactor {
     98    public IValueParameter<DoubleValue> TimeFactorParameter {
    9999      get { return (IValueParameter<DoubleValue>)Parameters["EvalTimeFactor"]; }
    100100    }
    101     public IValueParameter<DoubleValue> DistanceFactor {
     101    public IValueParameter<DoubleValue> DistanceFactorParameter {
    102102      get { return (IValueParameter<DoubleValue>)Parameters["EvalDistanceFactor"]; }
    103103    }
    104     public IValueParameter<DoubleValue> OverloadPenalty {
     104    public IValueParameter<DoubleValue> OverloadPenaltyParameter {
    105105      get { return (IValueParameter<DoubleValue>)Parameters["EvalOverloadPenalty"]; }
    106106    }
    107     public IValueParameter<DoubleValue> TardinessPenalty {
     107    public IValueParameter<DoubleValue> TardinessPenaltyParameter {
    108108      get { return (IValueParameter<DoubleValue>)Parameters["EvalTardinessPenalty"]; }
    109109    }
     
    113113    IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
    114114      get { return BestKnownQualityParameter; }
     115    }
     116    public OptionalValueParameter<IVRPEncoding> BestKnownSolutionParameter {
     117      get { return (OptionalValueParameter<IVRPEncoding>)Parameters["BestKnownSolution"]; }
    115118    }
    116119    #endregion
     
    157160      set { BestKnownQualityParameter.Value = value; }
    158161    }
     162    public IVRPEncoding BestKnownSolution {
     163      get { return BestKnownSolutionParameter.Value; }
     164      set { BestKnownSolutionParameter.Value = value; }
     165    }
    159166    IVRPCreator SolutionCreator {
    160167      get { return SolutionCreatorParameter.Value; }
     
    190197    [StorableConstructor]
    191198    private VehicleRoutingProblem(bool deserializing) : base(deserializing) { }
     199
     200    #region Backwards Compatibility
     201    [StorableHook(Persistence.Default.CompositeSerializers.Storable.HookType.AfterDeserialization)]
     202    private void CheckParameters() {
     203      if (!Parameters.ContainsKey("BestKnownSolution")) {
     204        Parameters.Add(new OptionalValueParameter<IVRPEncoding>("BestKnownSolution", "The best known solution of this TSP instance."));
     205      }
     206    }
     207    #endregion
     208
    192209    public VehicleRoutingProblem()
    193210      : base() {
     
    206223      Parameters.Add(new ValueParameter<DoubleArray>("ServiceTime", "The service time of each customer.", new DoubleArray()));
    207224      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this VRP instance."));
     225      Parameters.Add(new OptionalValueParameter<IVRPEncoding>("BestKnownSolution", "The best known solution of this TSP instance."));
    208226      Parameters.Add(new ValueParameter<DoubleValue>("EvalFleetUsageFactor", "The fleet usage factor considered in the evaluation.", new DoubleValue(100)));
    209227      Parameters.Add(new ValueParameter<DoubleValue>("EvalTimeFactor", "The time factor considered in the evaluation.", new DoubleValue(0)));
     
    264282      ParameterizeSolutionCreator();
    265283      ClearDistanceMatrix();
     284
     285      BestKnownSolution = null;
     286      BestKnownQuality = null;
    266287    }
    267288    private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
    268289      ClearDistanceMatrix();
     290
     291      BestKnownSolution = null;
     292      BestKnownQuality = null;
    269293    }
    270294    private void Coordinates_Reset(object sender, EventArgs e) {
    271295      ParameterizeSolutionCreator();
    272296      ClearDistanceMatrix();
     297
     298      BestKnownSolution = null;
     299      BestKnownQuality = null;
    273300    }
    274301    private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
     
    300327      }
    301328    }
     329
     330    void DistanceFactor_ValueChanged(object sender, EventArgs e) {
     331      DistanceFactorParameter.Value.ValueChanged += new EventHandler(DistanceFactorValue_ValueChanged);
     332      EvalBestKnownSolution();
     333    }
     334    void DistanceFactorValue_ValueChanged(object sender, EventArgs e) {
     335      EvalBestKnownSolution();
     336    }
     337    void FleetUsageFactor_ValueChanged(object sender, EventArgs e) {
     338      FleetUsageFactorParameter.Value.ValueChanged += new EventHandler(FleetUsageFactorValue_ValueChanged);
     339      EvalBestKnownSolution();
     340    }
     341    void FleetUsageFactorValue_ValueChanged(object sender, EventArgs e) {
     342      EvalBestKnownSolution();
     343    }
     344    void OverloadPenalty_ValueChanged(object sender, EventArgs e) {
     345      OverloadPenaltyParameter.Value.ValueChanged += new EventHandler(OverloadPenaltyValue_ValueChanged);
     346      EvalBestKnownSolution();
     347    }
     348    void OverloadPenaltyValue_ValueChanged(object sender, EventArgs e) {
     349      EvalBestKnownSolution();
     350    }
     351    void TardinessPenalty_ValueChanged(object sender, EventArgs e) {
     352      TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenaltyValue_ValueChanged);
     353      EvalBestKnownSolution();
     354    }
     355    void TardinessPenaltyValue_ValueChanged(object sender, EventArgs e) {
     356      EvalBestKnownSolution();
     357    }
     358    void TimeFactor_ValueChanged(object sender, EventArgs e) {
     359      TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactorValue_ValueChanged);
     360      EvalBestKnownSolution();
     361    }
     362    void TimeFactorValue_ValueChanged(object sender, EventArgs e) {
     363      EvalBestKnownSolution();
     364    }
     365    void DistanceMatrixParameter_ValueChanged(object sender, EventArgs e) {
     366      DistanceMatrix.ItemChanged += new EventHandler<EventArgs<int, int>>(DistanceMatrix_ItemChanged);
     367      DistanceMatrix.Reset += new EventHandler(DistanceMatrix_Reset);
     368      EvalBestKnownSolution();
     369    }
     370    void DistanceMatrix_Reset(object sender, EventArgs e) {
     371      EvalBestKnownSolution();
     372    }
     373    void DistanceMatrix_ItemChanged(object sender, EventArgs<int, int> e) {
     374      EvalBestKnownSolution();
     375    }
     376    void UseDistanceMatrixParameter_ValueChanged(object sender, EventArgs e) {
     377      UseDistanceMatrix.ValueChanged += new EventHandler(UseDistanceMatrix_ValueChanged);
     378      EvalBestKnownSolution();
     379    }
     380    void UseDistanceMatrix_ValueChanged(object sender, EventArgs e) {
     381      EvalBestKnownSolution();
     382    }
     383    void CapacityParameter_ValueChanged(object sender, EventArgs e) {
     384      Capacity.ValueChanged += new EventHandler(Capacity_ValueChanged);
     385      BestKnownSolution = null;
     386      BestKnownQuality = null;
     387    }
     388    void Capacity_ValueChanged(object sender, EventArgs e) {
     389      BestKnownSolution = null;
     390      BestKnownQuality = null;
     391    }
     392    void DemandParameter_ValueChanged(object sender, EventArgs e) {
     393      Demand.ItemChanged += new EventHandler<EventArgs<int>>(Demand_ItemChanged);
     394      Demand.Reset += new EventHandler(Demand_Reset);
     395
     396      BestKnownSolution = null;
     397      BestKnownQuality = null;
     398    }
     399    void Demand_Reset(object sender, EventArgs e) {
     400      BestKnownSolution = null;
     401      BestKnownQuality = null;
     402    }
     403    void Demand_ItemChanged(object sender, EventArgs<int> e) {
     404      BestKnownSolution = null;
     405      BestKnownQuality = null;
     406    }
     407    void DueTimeParameter_ValueChanged(object sender, EventArgs e) {
     408      DueTime.ItemChanged += new EventHandler<EventArgs<int>>(DueTime_ItemChanged);
     409      DueTime.Reset += new EventHandler(DueTime_Reset);
     410      BestKnownSolution = null;
     411      BestKnownQuality = null;
     412    }
     413    void DueTime_Reset(object sender, EventArgs e) {
     414      BestKnownSolution = null;
     415      BestKnownQuality = null;
     416    }
     417    void DueTime_ItemChanged(object sender, EventArgs<int> e) {
     418      BestKnownSolution = null;
     419      BestKnownQuality = null;
     420    }
     421    void ReadyTimeParameter_ValueChanged(object sender, EventArgs e) {
     422      ReadyTime.ItemChanged += new EventHandler<EventArgs<int>>(ReadyTime_ItemChanged);
     423      ReadyTime.Reset += new EventHandler(ReadyTime_Reset);
     424      BestKnownSolution = null;
     425      BestKnownQuality = null;
     426    }
     427    void ReadyTime_Reset(object sender, EventArgs e) {
     428      BestKnownSolution = null;
     429      BestKnownQuality = null;
     430    }
     431    void ReadyTime_ItemChanged(object sender, EventArgs<int> e) {
     432      BestKnownSolution = null;
     433      BestKnownQuality = null;
     434    }
     435    void ServiceTimeParameter_ValueChanged(object sender, EventArgs e) {
     436      ServiceTime.ItemChanged += new EventHandler<EventArgs<int>>(ServiceTime_ItemChanged);
     437      ServiceTime.Reset += new EventHandler(ServiceTime_Reset);
     438      BestKnownSolution = null;
     439      BestKnownQuality = null;
     440    }
     441    void ServiceTime_Reset(object sender, EventArgs e) {
     442      BestKnownSolution = null;
     443      BestKnownQuality = null;
     444    }
     445    void ServiceTime_ItemChanged(object sender, EventArgs<int> e) {
     446      BestKnownSolution = null;
     447      BestKnownQuality = null;
     448    }
     449    void VehiclesParameter_ValueChanged(object sender, EventArgs e) {
     450      Vehicles.ValueChanged += new EventHandler(Vehicles_ValueChanged);
     451      BestKnownSolution = null;
     452      BestKnownQuality = null;
     453    }
     454    void Vehicles_ValueChanged(object sender, EventArgs e) {
     455      BestKnownSolution = null;
     456      BestKnownQuality = null;
     457    }
    302458    #endregion
    303459
     
    310466    private void AttachEventHandlers() {
    311467      CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
    312       Vehicles.ValueChanged += new EventHandler(VehiclesValue_ValueChanged);
    313468      Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
    314469      Coordinates.Reset += new EventHandler(Coordinates_Reset);
     470
     471      Vehicles.ValueChanged += new EventHandler(VehiclesValue_ValueChanged);
     472
    315473      SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
     474     
    316475      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
    317476      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    318     }
     477
     478      DistanceFactorParameter.ValueChanged += new EventHandler(DistanceFactor_ValueChanged);
     479      DistanceFactorParameter.Value.ValueChanged += new EventHandler(DistanceFactorValue_ValueChanged);
     480      FleetUsageFactorParameter.ValueChanged += new EventHandler(FleetUsageFactor_ValueChanged);
     481      FleetUsageFactorParameter.Value.ValueChanged += new EventHandler(FleetUsageFactorValue_ValueChanged);
     482      OverloadPenaltyParameter.ValueChanged += new EventHandler(OverloadPenalty_ValueChanged);
     483      OverloadPenaltyParameter.Value.ValueChanged += new EventHandler(OverloadPenaltyValue_ValueChanged);
     484      TardinessPenaltyParameter.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
     485      TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenaltyValue_ValueChanged);
     486      TimeFactorParameter.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
     487      TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactorValue_ValueChanged);
     488
     489      DistanceMatrixParameter.ValueChanged += new EventHandler(DistanceMatrixParameter_ValueChanged);
     490      UseDistanceMatrixParameter.ValueChanged += new EventHandler(UseDistanceMatrixParameter_ValueChanged);
     491      UseDistanceMatrix.ValueChanged += new EventHandler(UseDistanceMatrix_ValueChanged);
     492
     493      CapacityParameter.ValueChanged += new EventHandler(CapacityParameter_ValueChanged);
     494      Capacity.ValueChanged += new EventHandler(Capacity_ValueChanged);
     495      DemandParameter.ValueChanged += new EventHandler(DemandParameter_ValueChanged);
     496      Demand.ItemChanged += new EventHandler<EventArgs<int>>(Demand_ItemChanged);
     497      Demand.Reset += new EventHandler(Demand_Reset);
     498      DueTimeParameter.ValueChanged += new EventHandler(DueTimeParameter_ValueChanged);
     499      DueTime.ItemChanged += new EventHandler<EventArgs<int>>(DueTime_ItemChanged);
     500      DueTime.Reset += new EventHandler(DueTime_Reset);
     501      ReadyTimeParameter.ValueChanged += new EventHandler(ReadyTimeParameter_ValueChanged);
     502      ReadyTime.ItemChanged += new EventHandler<EventArgs<int>>(ReadyTime_ItemChanged);
     503      ReadyTime.Reset += new EventHandler(ReadyTime_Reset);
     504      ServiceTimeParameter.ValueChanged += new EventHandler(ServiceTimeParameter_ValueChanged);
     505      ServiceTime.ItemChanged += new EventHandler<EventArgs<int>>(ServiceTime_ItemChanged);
     506      ServiceTime.Reset += new EventHandler(ServiceTime_Reset);
     507      VehiclesParameter.ValueChanged += new EventHandler(VehiclesParameter_ValueChanged);
     508      Vehicles.ValueChanged += new EventHandler(Vehicles_ValueChanged);
     509    }
     510
    319511    private void InitializeOperators() {
    320512      operators = new List<IOperator>();
     
    361553      Evaluator.DueTimeParameter.ActualName = DueTimeParameter.Name;
    362554      Evaluator.ServiceTimeParameter.ActualName = ServiceTimeParameter.Name;
    363       Evaluator.FleetUsageFactor.ActualName = FleetUsageFactor.Name;
    364       Evaluator.TimeFactor.ActualName = TimeFactor.Name;
    365       Evaluator.DistanceFactor.ActualName = DistanceFactor.Name;
    366       Evaluator.OverloadPenalty.ActualName = OverloadPenalty.Name;
    367       Evaluator.TardinessPenalty.ActualName = TardinessPenalty.Name;
     555      Evaluator.FleetUsageFactor.ActualName = FleetUsageFactorParameter.Name;
     556      Evaluator.TimeFactor.ActualName = TimeFactorParameter.Name;
     557      Evaluator.DistanceFactor.ActualName = DistanceFactorParameter.Name;
     558      Evaluator.OverloadPenalty.ActualName = OverloadPenaltyParameter.Name;
     559      Evaluator.TardinessPenalty.ActualName = TardinessPenaltyParameter.Name;
    368560    }
    369561    private void ParameterizeAnalyzer() {
     
    403595
    404596      foreach (IPrinsOperator op in Operators.OfType<IPrinsOperator>()) {
    405         op.FleetUsageFactor.ActualName = FleetUsageFactor.Name;
    406         op.TimeFactor.ActualName = TimeFactor.Name;
    407         op.DistanceFactor.ActualName = DistanceFactor.Name;
    408         op.OverloadPenalty.ActualName = OverloadPenalty.Name;
    409         op.TardinessPenalty.ActualName = TardinessPenalty.Name;
     597        op.FleetUsageFactor.ActualName = FleetUsageFactorParameter.Name;
     598        op.TimeFactor.ActualName = TimeFactorParameter.Name;
     599        op.DistanceFactor.ActualName = DistanceFactorParameter.Name;
     600        op.OverloadPenalty.ActualName = OverloadPenaltyParameter.Name;
     601        op.TardinessPenalty.ActualName = TardinessPenaltyParameter.Name;
    410602      }
    411603
    412604      foreach (IVRPMoveEvaluator op in Operators.OfType<IVRPMoveEvaluator>()) {
    413         op.FleetUsageFactor.ActualName = FleetUsageFactor.Name;
    414         op.TimeFactor.ActualName = TimeFactor.Name;
    415         op.DistanceFactor.ActualName = DistanceFactor.Name;
    416         op.OverloadPenalty.ActualName = OverloadPenalty.Name;
    417         op.TardinessPenalty.ActualName = TardinessPenalty.Name;
     605        op.FleetUsageFactor.ActualName = FleetUsageFactorParameter.Name;
     606        op.TimeFactor.ActualName = TimeFactorParameter.Name;
     607        op.DistanceFactor.ActualName = DistanceFactorParameter.Name;
     608        op.OverloadPenalty.ActualName = OverloadPenaltyParameter.Name;
     609        op.TardinessPenalty.ActualName = TardinessPenaltyParameter.Name;
    418610        op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
    419611        op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
     
    490682
    491683      OnReset();
     684    }
     685
     686    private void EvalBestKnownSolution() {
     687      if (BestKnownSolution != null) {
     688        //call evaluator
     689        IValueLookupParameter<DoubleMatrix> distMatrix = new ValueLookupParameter<DoubleMatrix>("DistMatrix",
     690          DistanceMatrix);
     691
     692        TourEvaluation eval = VRPEvaluator.Evaluate(
     693          BestKnownSolution,
     694          Vehicles,
     695          DueTime,
     696          ServiceTime,
     697          ReadyTime,
     698          Demand,
     699          Capacity,
     700          FleetUsageFactorParameter.Value,
     701          TimeFactorParameter.Value,
     702          DistanceFactorParameter.Value,
     703          OverloadPenaltyParameter.Value,
     704          TardinessPenaltyParameter.Value,
     705          Coordinates,
     706          distMatrix,
     707          UseDistanceMatrix);
     708
     709        DistanceMatrix = distMatrix.Value;
     710
     711        BestKnownQuality = new DoubleValue(eval.Quality);
     712      } else {
     713        BestKnownQuality = null;
     714      }
     715    }
     716
     717    public void ImportSolution(string solutionFileName) {
     718      SolutionParser parser = new SolutionParser(solutionFileName);
     719      parser.Parse();
     720
     721      HeuristicLab.Problems.VehicleRouting.Encodings.Potvin.PotvinEncoding encoding = new Encodings.Potvin.PotvinEncoding();
     722
     723      int cities = 0;
     724      foreach (List<int> route in parser.Routes) {
     725        Encodings.Tour tour = new Encodings.Tour();
     726        tour.Cities.AddRange(route);
     727        cities += tour.Cities.Count;
     728
     729        encoding.Tours.Add(tour);
     730      }
     731
     732      if (cities != Coordinates.Rows - 1)
     733        throw new Exception("Invalid solution");
     734
     735      BestKnownSolutionParameter.Value = encoding;
     736      EvalBestKnownSolution();
    492737    }
    493738
Note: See TracChangeset for help on using the changeset viewer.