Changeset 15168


Ignore:
Timestamp:
07/07/17 12:51:24 (3 months ago)
Author:
abeham
Message:

#2696:

  • Added additional event handlers to detect change of problem instance data
  • Cleared best known solution if it cannot be evaluated anymore due to an exception, e.g. structural change
  • Cleared distance matrix in case coordinates change
Location:
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPProblemInstance.cs

    r14185 r15168  
    110110
    111111    private void AttachEventHandlers() {
    112       CapacityParameter.ValueChanged += new EventHandler(CapacityParameter_ValueChanged);
    113       OverloadPenaltyParameter.ValueChanged += new EventHandler(OverloadPenaltyParameter_ValueChanged);
    114       OverloadPenaltyParameter.Value.ValueChanged += new EventHandler(OverloadPenalty_ValueChanged);
     112      CapacityParameter.ValueChanged += CapacityParameter_ValueChanged;
     113      Capacity.Reset += Capacity_Changed;
     114      Capacity.ItemChanged += Capacity_Changed;
     115      OverloadPenaltyParameter.ValueChanged += OverloadPenaltyParameter_ValueChanged;
     116      OverloadPenalty.ValueChanged += OverloadPenalty_ValueChanged;
    115117    }
    116118
     
    123125    #region Event handlers
    124126    void CapacityParameter_ValueChanged(object sender, EventArgs e) {
     127      Capacity.Reset += Capacity_Changed;
     128      Capacity.ItemChanged += Capacity_Changed;
     129      EvalBestKnownSolution();
     130    }
     131    private void Capacity_Changed(object sender, EventArgs e) {
    125132      EvalBestKnownSolution();
    126133    }
    127134    void OverloadPenaltyParameter_ValueChanged(object sender, EventArgs e) {
    128       OverloadPenaltyParameter.Value.ValueChanged += new EventHandler(OverloadPenalty_ValueChanged);
     135      OverloadPenalty.ValueChanged += OverloadPenalty_ValueChanged;
    129136      EvalBestKnownSolution();
    130137    }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPPDTW/MDCVRPPDTWProblemInstance.cs

    r14185 r15168  
    117117
    118118    private void AttachEventHandlers() {
    119       PickupDeliveryLocationParameter.ValueChanged += new EventHandler(PickupDeliveryLocationParameter_ValueChanged);
     119      PickupDeliveryLocationParameter.ValueChanged += PickupDeliveryLocationParameter_ValueChanged;
     120      PickupDeliveryLocation.Reset += PickupDeliveryLocation_Changed;
     121      PickupDeliveryLocation.ItemChanged += PickupDeliveryLocation_Changed;
     122      PickupViolationPenaltyParameter.ValueChanged += PickupViolationPenaltyParameter_ValueChanged;
     123      PickupViolationPenalty.ValueChanged += PickupViolationPenalty_Changed;
    120124    }
    121125
     
    128132    #region Event handlers
    129133    void PickupDeliveryLocationParameter_ValueChanged(object sender, EventArgs e) {
    130       PickupDeliveryLocationParameter.Value.ItemChanged += new EventHandler<EventArgs<int>>(Value_ItemChanged);
     134      PickupDeliveryLocation.Reset += PickupDeliveryLocation_Changed;
     135      PickupDeliveryLocation.ItemChanged += PickupDeliveryLocation_Changed;
    131136      EvalBestKnownSolution();
    132137    }
    133 
    134     void Value_ItemChanged(object sender, EventArgs<int> e) {
     138    private void PickupDeliveryLocation_Changed(object sender, EventArgs e) {
     139      EvalBestKnownSolution();
     140    }
     141    private void PickupViolationPenaltyParameter_ValueChanged(object sender, EventArgs e) {
     142      PickupViolationPenalty.ValueChanged += PickupViolationPenalty_Changed;
     143      EvalBestKnownSolution();
     144    }
     145    private void PickupViolationPenalty_Changed(object sender, EventArgs e) {
    135146      EvalBestKnownSolution();
    136147    }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPTWProblemInstance.cs

    r14185 r15168  
    136136
    137137    private void AttachEventHandlers() {
    138       TardinessPenaltyParameter.ValueChanged += new EventHandler(TardinessPenaltyParameter_ValueChanged);
    139       TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
    140       TimeFactorParameter.ValueChanged += new EventHandler(TimeFactorParameter_ValueChanged);
    141       TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
     138      ReadyTimeParameter.ValueChanged += ReadyTimeParameter_ValueChanged;
     139      ReadyTime.Reset += ReadyTime_Changed;
     140      ReadyTime.ItemChanged += ReadyTime_Changed;
     141      DueTimeParameter.ValueChanged += DueTimeParameter_ValueChanged;
     142      DueTime.Reset += DueTime_Changed;
     143      DueTime.ItemChanged += DueTime_Changed;
     144      ServiceTimeParameter.ValueChanged += ServiceTimeParameter_ValueChanged;
     145      ServiceTime.Reset += ServiceTime_Changed;
     146      ServiceTime.ItemChanged += ServiceTime_Changed;
     147      TardinessPenaltyParameter.ValueChanged += TardinessPenaltyParameter_ValueChanged;
     148      TardinessPenalty.ValueChanged += TardinessPenalty_ValueChanged;
     149      TimeFactorParameter.ValueChanged += TimeFactorParameter_ValueChanged;
     150      TimeFactor.ValueChanged += TimeFactor_ValueChanged;
    142151    }
    143152
     
    149158
    150159    #region Event handlers
    151     void TardinessPenaltyParameter_ValueChanged(object sender, EventArgs e) {
    152       TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
    153       EvalBestKnownSolution();
    154     }
    155     void TardinessPenalty_ValueChanged(object sender, EventArgs e) {
    156       EvalBestKnownSolution();
    157     }
    158     void TimeFactorParameter_ValueChanged(object sender, EventArgs e) {
    159       TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
    160       EvalBestKnownSolution();
    161     }
    162     void TimeFactor_ValueChanged(object sender, EventArgs e) {
     160    private void ReadyTimeParameter_ValueChanged(object sender, EventArgs e) {
     161      ReadyTime.Reset += ReadyTime_Changed;
     162      ReadyTime.ItemChanged += ReadyTime_Changed;
     163      EvalBestKnownSolution();
     164    }
     165    private void ReadyTime_Changed(object sender, EventArgs e) {
     166      EvalBestKnownSolution();
     167    }
     168    private void DueTimeParameter_ValueChanged(object sender, EventArgs e) {
     169      DueTime.Reset += DueTime_Changed;
     170      DueTime.ItemChanged += DueTime_Changed;
     171      EvalBestKnownSolution();
     172    }
     173    private void DueTime_Changed(object sender, EventArgs e) {
     174      EvalBestKnownSolution();
     175    }
     176    private void ServiceTimeParameter_ValueChanged(object sender, EventArgs e) {
     177      ServiceTime.Reset += ServiceTime_Changed;
     178      ServiceTime.ItemChanged += ServiceTime_Changed;
     179      EvalBestKnownSolution();
     180    }
     181    private void ServiceTime_Changed(object sender, EventArgs e) {
     182      EvalBestKnownSolution();
     183    }
     184    private void TardinessPenaltyParameter_ValueChanged(object sender, EventArgs e) {
     185      TardinessPenalty.ValueChanged += TardinessPenalty_ValueChanged;
     186      EvalBestKnownSolution();
     187    }
     188    private void TardinessPenalty_ValueChanged(object sender, EventArgs e) {
     189      EvalBestKnownSolution();
     190    }
     191    private void TimeFactorParameter_ValueChanged(object sender, EventArgs e) {
     192      TimeFactor.ValueChanged += TimeFactor_ValueChanged;
     193      EvalBestKnownSolution();
     194    }
     195    private void TimeFactor_ValueChanged(object sender, EventArgs e) {
    163196      EvalBestKnownSolution();
    164197    }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MultiDepotVRPProblemInstance.cs

    r14185 r15168  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    174175    [StorableConstructor]
    175176    protected MultiDepotVRPProblemInstance(bool deserializing) : base(deserializing) { }
    176 
     177    protected MultiDepotVRPProblemInstance(MultiDepotVRPProblemInstance original, Cloner cloner)
     178      : base(original, cloner) {
     179      AttachEventHandlers();
     180    }
    177181    public MultiDepotVRPProblemInstance() {
    178182      Parameters.Add(new ValueParameter<IntValue>("Depots", "The number of depots", new IntValue(0)));
    179183      Parameters.Add(new ValueParameter<IntArray>("VehicleDepotAssignment", "The assignment of vehicles to depots", new IntArray()));
     184      AttachEventHandlers();
    180185    }
    181186
     
    184189    }
    185190
    186     protected MultiDepotVRPProblemInstance(MultiDepotVRPProblemInstance original, Cloner cloner)
    187       : base(original, cloner) {
    188     }
     191    [StorableHook(HookType.AfterDeserialization)]
     192    private void AfterDeserialization() {
     193      AttachEventHandlers();
     194    }
     195
     196    private void AttachEventHandlers() {
     197      DepotsParameter.ValueChanged += DepotsParameter_ValueChanged;
     198      Depots.ValueChanged += Depots_ValueChanged;
     199      VehicleDepotAssignmentParameter.ValueChanged += VehicleDepotAssignmentParameter_ValueChanged;
     200      VehicleDepotAssignment.Reset += VehicleDepotAssignment_Changed;
     201      VehicleDepotAssignment.ItemChanged += VehicleDepotAssignment_Changed;
     202    }
     203
     204    #region Event handlers
     205    private void DepotsParameter_ValueChanged(object sender, EventArgs e) {
     206      Depots.ValueChanged += Depots_ValueChanged;
     207      EvalBestKnownSolution();
     208    }
     209    private void Depots_ValueChanged(object sender, EventArgs e) {
     210      EvalBestKnownSolution();
     211    }
     212    private void VehicleDepotAssignmentParameter_ValueChanged(object sender, EventArgs e) {
     213      VehicleDepotAssignment.Reset += VehicleDepotAssignment_Changed;
     214      VehicleDepotAssignment.ItemChanged += VehicleDepotAssignment_Changed;
     215      EvalBestKnownSolution();
     216    }
     217    private void VehicleDepotAssignment_Changed(object sender, EventArgs e) {
     218      EvalBestKnownSolution();
     219    }
     220    #endregion
    189221  }
    190222}
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWProblemInstance.cs

    r14185 r15168  
    117117
    118118    private void AttachEventHandlers() {
    119       PickupDeliveryLocationParameter.ValueChanged += new EventHandler(PickupDeliveryLocationParameter_ValueChanged);
     119      PickupDeliveryLocationParameter.ValueChanged += PickupDeliveryLocationParameter_ValueChanged;
     120      PickupDeliveryLocation.Reset += PickupDeliveryLocation_Changed;
     121      PickupDeliveryLocation.ItemChanged += PickupDeliveryLocation_Changed;
    120122    }
    121123
     
    128130    #region Event handlers
    129131    void PickupDeliveryLocationParameter_ValueChanged(object sender, EventArgs e) {
    130       PickupDeliveryLocationParameter.Value.ItemChanged += new EventHandler<EventArgs<int>>(Value_ItemChanged);
     132      PickupDeliveryLocation.Reset += PickupDeliveryLocation_Changed;
     133      PickupDeliveryLocation.ItemChanged += PickupDeliveryLocation_Changed;
    131134      EvalBestKnownSolution();
    132135    }
    133 
    134     void Value_ItemChanged(object sender, EventArgs<int> e) {
     136    private void PickupDeliveryLocation_Changed(object sender, EventArgs e) {
    135137      EvalBestKnownSolution();
    136138    }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWProblemInstance.cs

    r14185 r15168  
    136136
    137137    private void AttachEventHandlers() {
    138       TardinessPenaltyParameter.ValueChanged += new EventHandler(TardinessPenaltyParameter_ValueChanged);
    139       TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
    140       TimeFactorParameter.ValueChanged += new EventHandler(TimeFactorParameter_ValueChanged);
    141       TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
     138      ReadyTimeParameter.ValueChanged += ReadyTimeParameter_ValueChanged;
     139      ReadyTime.Reset += ReadyTime_Changed;
     140      ReadyTime.ItemChanged += ReadyTime_Changed;
     141      DueTimeParameter.ValueChanged += DueTimeParameter_ValueChanged;
     142      DueTime.Reset += DueTime_Changed;
     143      DueTime.ItemChanged += DueTime_Changed;
     144      ServiceTimeParameter.ValueChanged += ServiceTimeParameter_ValueChanged;
     145      ServiceTime.Reset += ServiceTime_Changed;
     146      ServiceTime.ItemChanged += ServiceTime_Changed;
     147      TardinessPenaltyParameter.ValueChanged += TardinessPenaltyParameter_ValueChanged;
     148      TardinessPenalty.ValueChanged += TardinessPenalty_ValueChanged;
     149      TimeFactorParameter.ValueChanged += TimeFactorParameter_ValueChanged;
     150      TimeFactor.ValueChanged += TimeFactor_ValueChanged;
    142151    }
    143152
     
    149158
    150159    #region Event handlers
    151     void TardinessPenaltyParameter_ValueChanged(object sender, EventArgs e) {
    152       TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
    153       EvalBestKnownSolution();
    154     }
    155     void TardinessPenalty_ValueChanged(object sender, EventArgs e) {
    156       EvalBestKnownSolution();
    157     }
    158     void TimeFactorParameter_ValueChanged(object sender, EventArgs e) {
    159       TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
    160       EvalBestKnownSolution();
    161     }
    162     void TimeFactor_ValueChanged(object sender, EventArgs e) {
     160    private void ReadyTimeParameter_ValueChanged(object sender, EventArgs e) {
     161      ReadyTime.Reset += ReadyTime_Changed;
     162      ReadyTime.ItemChanged += ReadyTime_Changed;
     163      EvalBestKnownSolution();
     164    }
     165    private void ReadyTime_Changed(object sender, EventArgs e) {
     166      EvalBestKnownSolution();
     167    }
     168    private void DueTimeParameter_ValueChanged(object sender, EventArgs e) {
     169      DueTime.Reset += DueTime_Changed;
     170      DueTime.ItemChanged += DueTime_Changed;
     171      EvalBestKnownSolution();
     172    }
     173    private void DueTime_Changed(object sender, EventArgs e) {
     174      EvalBestKnownSolution();
     175    }
     176    private void ServiceTimeParameter_ValueChanged(object sender, EventArgs e) {
     177      ServiceTime.Reset += ServiceTime_Changed;
     178      ServiceTime.ItemChanged += ServiceTime_Changed;
     179      EvalBestKnownSolution();
     180    }
     181    private void ServiceTime_Changed(object sender, EventArgs e) {
     182      EvalBestKnownSolution();
     183    }
     184    private void TardinessPenaltyParameter_ValueChanged(object sender, EventArgs e) {
     185      TardinessPenaltyParameter.Value.ValueChanged += TardinessPenalty_ValueChanged;
     186      EvalBestKnownSolution();
     187    }
     188    private void TardinessPenalty_ValueChanged(object sender, EventArgs e) {
     189      EvalBestKnownSolution();
     190    }
     191    private void TimeFactorParameter_ValueChanged(object sender, EventArgs e) {
     192      TimeFactorParameter.Value.ValueChanged += TimeFactor_ValueChanged;
     193      EvalBestKnownSolution();
     194    }
     195    private void TimeFactor_ValueChanged(object sender, EventArgs e) {
    163196      EvalBestKnownSolution();
    164197    }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs

    r14482 r15168  
    280280
    281281    private void AttachEventHandlers() {
    282       DistanceFactorParameter.ValueChanged += new EventHandler(DistanceFactorParameter_ValueChanged);
    283       DistanceFactorParameter.Value.ValueChanged += new EventHandler(DistanceFactor_ValueChanged);
    284       FleetUsageFactorParameter.ValueChanged += new EventHandler(FleetUsageFactorParameter_ValueChanged);
    285       FleetUsageFactorParameter.Value.ValueChanged += new EventHandler(FleetUsageFactor_ValueChanged);
    286       DistanceMatrixParameter.ValueChanged += new EventHandler(DistanceMatrixParameter_ValueChanged);
     282      CoordinatesParameter.ValueChanged += CoordinatesParameter_ValueChanged;
     283      Coordinates.Reset += Coordinates_Changed;
     284      Coordinates.ItemChanged += Coordinates_Changed;
     285      DemandParameter.ValueChanged += DemandParameter_ValueChanged;
     286      Demand.Reset += Demand_Changed;
     287      Demand.ItemChanged += Demand_Changed;
     288      VehiclesParameter.ValueChanged += VehiclesParameter_ValueChanged;
     289      VehiclesParameter.Value.ValueChanged += Vehicles_Changed;
     290      DistanceFactorParameter.ValueChanged += DistanceFactorParameter_ValueChanged;
     291      DistanceFactorParameter.Value.ValueChanged += DistanceFactor_ValueChanged;
     292      FleetUsageFactorParameter.ValueChanged += FleetUsageFactorParameter_ValueChanged;
     293      FleetUsageFactorParameter.Value.ValueChanged += FleetUsageFactor_ValueChanged;
     294      DistanceMatrixParameter.ValueChanged += DistanceMatrixParameter_ValueChanged;
    287295      if (DistanceMatrix != null) {
    288         DistanceMatrix.ItemChanged += new EventHandler<EventArgs<int, int>>(DistanceMatrix_ItemChanged);
    289         DistanceMatrix.Reset += new EventHandler(DistanceMatrix_Reset);
    290       }
    291       UseDistanceMatrixParameter.ValueChanged += new EventHandler(UseDistanceMatrixParameter_ValueChanged);
    292       UseDistanceMatrix.ValueChanged += new EventHandler(UseDistanceMatrix_ValueChanged);
     296        DistanceMatrix.ItemChanged += DistanceMatrix_ItemChanged;
     297        DistanceMatrix.Reset += DistanceMatrix_Reset;
     298      }
     299      UseDistanceMatrixParameter.ValueChanged += UseDistanceMatrixParameter_ValueChanged;
     300      UseDistanceMatrix.ValueChanged += UseDistanceMatrix_ValueChanged;
    293301    }
    294302
     
    300308
    301309    #region Event handlers
     310    private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
     311      if (distanceMatrix != null) distanceMatrix = null;
     312      if (DistanceMatrix != null && DistanceMatrix.Rows != Coordinates.Rows) DistanceMatrix = null;
     313      Coordinates.Reset += Coordinates_Changed;
     314      Coordinates.ItemChanged += Coordinates_Changed;
     315      EvalBestKnownSolution();
     316    }
     317    private void Coordinates_Changed(object sender, EventArgs e) {
     318      if (distanceMatrix != null) distanceMatrix = null;
     319      if (DistanceMatrix != null && DistanceMatrix.Rows != Coordinates.Rows) DistanceMatrix = null;
     320      EvalBestKnownSolution();
     321    }
     322    private void DemandParameter_ValueChanged(object sender, EventArgs e) {
     323      Demand.Reset += Demand_Changed;
     324      Demand.ItemChanged += Demand_Changed;
     325      EvalBestKnownSolution();
     326    }
     327    private void Demand_Changed(object sender, EventArgs e) {
     328      EvalBestKnownSolution();
     329    }
     330    private void VehiclesParameter_ValueChanged(object sender, EventArgs e) {
     331      Vehicles.ValueChanged += Vehicles_Changed;
     332      EvalBestKnownSolution();
     333    }
     334    private void Vehicles_Changed(object sender, EventArgs e) {
     335      EvalBestKnownSolution();
     336    }
    302337    void DistanceFactorParameter_ValueChanged(object sender, EventArgs e) {
    303       DistanceFactorParameter.Value.ValueChanged += new EventHandler(DistanceFactor_ValueChanged);
     338      DistanceFactorParameter.Value.ValueChanged += DistanceFactor_ValueChanged;
    304339      EvalBestKnownSolution();
    305340    }
     
    308343    }
    309344    void FleetUsageFactorParameter_ValueChanged(object sender, EventArgs e) {
    310       FleetUsageFactorParameter.Value.ValueChanged += new EventHandler(FleetUsageFactor_ValueChanged);
     345      FleetUsageFactorParameter.Value.ValueChanged += FleetUsageFactor_ValueChanged;
    311346      EvalBestKnownSolution();
    312347    }
     
    316351    void DistanceMatrixParameter_ValueChanged(object sender, EventArgs e) {
    317352      if (DistanceMatrix != null) {
    318         DistanceMatrix.ItemChanged += new EventHandler<EventArgs<int, int>>(DistanceMatrix_ItemChanged);
    319         DistanceMatrix.Reset += new EventHandler(DistanceMatrix_Reset);
     353        DistanceMatrix.ItemChanged += DistanceMatrix_ItemChanged;
     354        DistanceMatrix.Reset += DistanceMatrix_Reset;
    320355      }
    321356      distanceMatrix = DistanceMatrix;
     
    330365    }
    331366    void UseDistanceMatrixParameter_ValueChanged(object sender, EventArgs e) {
    332       UseDistanceMatrix.ValueChanged += new EventHandler(UseDistanceMatrix_ValueChanged);
     367      UseDistanceMatrix.ValueChanged += UseDistanceMatrix_ValueChanged;
    333368      if (!UseDistanceMatrix.Value)
    334369        distanceMatrix = null;
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs

    r15069 r15168  
    194194
    195195    private void EvalBestKnownSolution() {
    196       if (BestKnownSolution != null) {
     196      if (BestKnownSolution == null) return;
     197      try {
    197198        //call evaluator
    198199        BestKnownQuality = new DoubleValue(ProblemInstance.Evaluate(BestKnownSolution.Solution).Quality);
    199200        BestKnownSolution.Quality = BestKnownQuality;
     201      } catch {
     202        BestKnownQuality = null;
     203        BestKnownSolution = null;
    200204      }
    201205    }
     
    207211    void ProblemInstance_EvaluationChanged(object sender, EventArgs e) {
    208212      BestKnownQuality = null;
    209       EvalBestKnownSolution();
     213      if (BestKnownSolution != null) {
     214        // the tour is not valid if there are more vehicles in it than allowed
     215        if (ProblemInstance.Vehicles.Value < BestKnownSolution.Solution.GetTours().Count) {
     216          BestKnownSolution = null;
     217        } else EvalBestKnownSolution();
     218      }
    210219    }
    211220
Note: See TracChangeset for help on using the changeset viewer.