Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/19/10 15:43:21 (14 years ago)
Author:
svonolfe
Message:

Merged changes from trunk into branch (#1177)

Location:
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestSolution/BestVRPSolutionAnalyzer.cs

    r4752 r4860  
    6262    }
    6363
     64    public LookupParameter<DoubleValue> BestKnownQualityParameter {
     65      get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     66    }
     67    public LookupParameter<VRPSolution> BestKnownSolutionParameter {
     68      get { return (LookupParameter<VRPSolution>)Parameters["BestKnownSolution"]; }
     69    }
     70
    6471    [StorableConstructor]
    6572    private BestVRPSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     
    6976        Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance."));
    7077        Parameters.Add(new ScopeTreeLookupParameter<IVRPEncoding>("VRPTours", "The VRP tours which should be evaluated."));
     78
     79        Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this VRP instance."));
     80        Parameters.Add(new LookupParameter<VRPSolution>("BestKnownSolution", "The best known solution of this VRP instance."));
    7181
    7282        Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the VRP solutions which should be analyzed."));
     
    8696    }
    8797
     98    [StorableHook(HookType.AfterDeserialization)]
     99    private void AfterDeserializationHook() {
     100      #region Backwards Compatibility
     101      if (!Parameters.ContainsKey("BestKnownQuality")) {
     102        Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this VRP instance."));
     103      }
     104      if (!Parameters.ContainsKey("BestKnownSolution")) {
     105        Parameters.Add(new LookupParameter<VRPSolution>("BestKnownSolution", "The best known solution of this VRP instance."));
     106      }
     107      #endregion
     108    }
     109
    88110    public override IOperation Apply() {
    89111      IVRPProblemInstance problemInstance = ProblemInstanceParameter.ActualValue;
     
    96118
    97119      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     120
     121      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
    98122
    99123      IVRPEncoding best = solutions[i].Clone() as IVRPEncoding;
     
    116140      }
    117141
     142      if (bestKnownQuality == null ||
     143          qualities[i].Value < bestKnownQuality.Value) {
     144        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
     145        BestKnownSolutionParameter.ActualValue = (VRPSolution)solution.Clone();
     146      }
     147
    118148      return base.Apply();
    119149    }
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/HeuristicLab.Problems.VehicleRouting-3.4.csproj

    r4383 r4860  
    227227    <Compile Include="Interfaces\IVRPEncoding.cs" />
    228228    <Compile Include="Interfaces\IVRPProblemInstance.cs" />
     229    <Compile Include="SolutionParser.cs" />
    229230    <Compile Include="Variants\Capacitated\Heterogenous\IHeterogenousCapacitatedProblemInstance.cs" />
    230231    <Compile Include="Variants\Capacitated\Heterogenous\IHeterogenousCapacitatedOperator.cs" />
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Interfaces/IVRPProblemInstance.cs

    r4363 r4860  
    3232    IValueParameter<IVRPEvaluator> EvaluatorParameter { get; }
    3333    IValueParameter<IVRPCreator> SolutionCreatorParameter { get; }
     34    IValueParameter<DoubleValue> BestKnownQualityParameter { get; }
     35    IValueParameter<VRPSolution> BestKnownSolutionParameter { get; }
    3436    IEnumerable<IOperator> Operators { get; }
    3537
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPProblemInstance.cs

    r4752 r4860  
    7777      Parameters.Add(new ValueParameter<DoubleValue>("Capacity", "The capacity of each vehicle.", new DoubleValue(0)));
    7878      Parameters.Add(new ValueParameter<DoubleValue>("EvalOverloadPenalty", "The overload penalty considered in the evaluation.", new DoubleValue(100)));
     79
     80      AttachEventHandlers();
    7981    }
    8082
     
    8587    protected CVRPProblemInstance(CVRPProblemInstance original, Cloner cloner)
    8688      : base(original, cloner) {
     89        AttachEventHandlers();
    8790    }
     91
     92    [StorableHook(HookType.AfterDeserialization)]
     93    private void AfterDeserializationHook() {
     94      AttachEventHandlers();
     95    }
     96
     97    private void AttachEventHandlers() {
     98      CapacityParameter.ValueChanged += new EventHandler(CapacityParameter_ValueChanged);
     99      CapacityParameter.Value.ValueChanged += new EventHandler(Capacity_ValueChanged);
     100      OverloadPenaltyParameter.ValueChanged += new EventHandler(OverloadPenaltyParameter_ValueChanged);
     101      OverloadPenaltyParameter.Value.ValueChanged += new EventHandler(OverloadPenalty_ValueChanged);
     102    }
     103
     104    #region Event handlers
     105    void CapacityParameter_ValueChanged(object sender, EventArgs e) {
     106      CapacityParameter.Value.ValueChanged += new EventHandler(Capacity_ValueChanged);
     107      BestKnownSolution = null;
     108    }
     109    void Capacity_ValueChanged(object sender, EventArgs e) {
     110      BestKnownSolution = null;
     111    }
     112    void OverloadPenaltyParameter_ValueChanged(object sender, EventArgs e) {
     113      OverloadPenaltyParameter.Value.ValueChanged += new EventHandler(OverloadPenalty_ValueChanged);
     114      EvalBestKnownSolution();
     115    }
     116    void OverloadPenalty_ValueChanged(object sender, EventArgs e) {
     117      EvalBestKnownSolution();
     118    }
     119    #endregion
    88120  }
    89121}
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWProblemInstance.cs

    r4752 r4860  
    103103      Parameters.Add(new ValueParameter<DoubleValue>("EvalTimeFactor", "The time factor considered in the evaluation.", new DoubleValue(0)));
    104104      Parameters.Add(new ValueParameter<DoubleValue>("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation.", new DoubleValue(100)));
     105
     106      AttachEventHandlers();
    105107    }
    106108
     
    111113    protected CVRPTWProblemInstance(CVRPTWProblemInstance original, Cloner cloner)
    112114      : base(original, cloner) {
     115        AttachEventHandlers();
    113116    }
     117
     118    [StorableHook(HookType.AfterDeserialization)]
     119    private void AfterDeserializationHook() {
     120      AttachEventHandlers();
     121    }
     122
     123    private void AttachEventHandlers() {
     124      TardinessPenaltyParameter.ValueChanged += new EventHandler(TardinessPenaltyParameter_ValueChanged);
     125      TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
     126      TimeFactorParameter.ValueChanged += new EventHandler(TimeFactorParameter_ValueChanged);
     127      TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
     128    }
     129
     130    #region Event handlers
     131    void TardinessPenaltyParameter_ValueChanged(object sender, EventArgs e) {
     132      TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
     133      EvalBestKnownSolution();
     134    }
     135    void TardinessPenalty_ValueChanged(object sender, EventArgs e) {
     136      EvalBestKnownSolution();
     137    }
     138    void TimeFactorParameter_ValueChanged(object sender, EventArgs e) {
     139      TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
     140      EvalBestKnownSolution();
     141    }
     142    void TimeFactor_ValueChanged(object sender, EventArgs e) {
     143      EvalBestKnownSolution();
     144    }
     145    #endregion
    114146  }
    115147}
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs

    r4752 r4860  
    7777    }
    7878
     79    protected OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
     80      get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     81    }
     82    protected OptionalValueParameter<VRPSolution> BestKnownSolutionParameter {
     83      get { return (OptionalValueParameter<VRPSolution>)Parameters["BestKnownSolution"]; }
     84    }
     85
     86    IValueParameter<DoubleValue> IVRPProblemInstance.BestKnownQualityParameter {
     87      get { return BestKnownQualityParameter; }
     88    }
     89
     90    IValueParameter<VRPSolution> IVRPProblemInstance.BestKnownSolutionParameter {
     91      get { return BestKnownSolutionParameter; }
     92    }
     93
    7994    public DoubleMatrix Coordinates {
    8095      get { return CoordinatesParameter.Value; }
     
    109124      get { return DistanceFactorParameter.Value; }
    110125      set { DistanceFactorParameter.Value = value; }
     126    }
     127
     128    public DoubleValue BestKnownQuality {
     129      get { return BestKnownQualityParameter.Value; }
     130      set { BestKnownQualityParameter.Value = value; }
     131    }
     132    public VRPSolution BestKnownSolution {
     133      get { return BestKnownSolutionParameter.Value; }
     134      set { BestKnownSolutionParameter.Value = value; }
    111135    }
    112136
     
    171195    public double Evaluate(Tour tour) {
    172196      return EvaluatorParameter.Value.Evaluate(this, tour).Quality;
     197    }
     198
     199    protected void EvalBestKnownSolution() {
     200      if (BestKnownSolution != null) {
     201        //call evaluator
     202        BestKnownQuality = new DoubleValue(Evaluate(BestKnownSolution.Solution));
     203        BestKnownSolution.Quality = BestKnownQuality;
     204      } else {
     205        BestKnownQuality = null;
     206      }
    173207    }
    174208
     
    192226      Parameters.Add(new ValueParameter<IVRPCreator>("SolutionCreator", "The operator which should be used to create new VRP solutions.", Creator));
    193227      Parameters.Add(new ValueParameter<IVRPEvaluator>("Evaluator", "The operator which should be used to evaluate VRP solutions.", Evaluator));
     228
     229      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this VRP instance."));
     230      Parameters.Add(new OptionalValueParameter<VRPSolution>("BestKnownSolution", "The best known solution of this VRP instance."));
     231
     232      AttachEventHandlers();
    194233    }
    195234
    196235    protected VRPProblemInstance(VRPProblemInstance original, Cloner cloner)
    197236      : base(original, cloner) {
    198     }
     237        AttachEventHandlers();
     238    }
     239
     240    [StorableHook(HookType.AfterDeserialization)]
     241    private void AfterDeserializationHook() {
     242      #region Backwards Compatibility
     243      if (!Parameters.ContainsKey("BestKnownSolution")) {
     244        Parameters.Add(new OptionalValueParameter<VRPSolution>("BestKnownSolution", "The best known solution of this TSP instance."));
     245      }
     246      #endregion
     247     
     248      AttachEventHandlers();
     249    }
     250
     251    private void AttachEventHandlers() {
     252      BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);
     253      DistanceFactorParameter.ValueChanged += new EventHandler(DistanceFactorParameter_ValueChanged);
     254      DistanceFactorParameter.Value.ValueChanged += new EventHandler(DistanceFactor_ValueChanged);
     255      FleetUsageFactorParameter.ValueChanged += new EventHandler(FleetUsageFactorParameter_ValueChanged);
     256      FleetUsageFactorParameter.Value.ValueChanged += new EventHandler(FleetUsageFactor_ValueChanged);
     257      DistanceMatrixParameter.ValueChanged += new EventHandler(DistanceMatrixParameter_ValueChanged);
     258      if (DistanceMatrix != null) {
     259        DistanceMatrix.ItemChanged += new EventHandler<EventArgs<int, int>>(DistanceMatrix_ItemChanged);
     260        DistanceMatrix.Reset += new EventHandler(DistanceMatrix_Reset);
     261      }
     262      UseDistanceMatrixParameter.ValueChanged += new EventHandler(UseDistanceMatrixParameter_ValueChanged);
     263      UseDistanceMatrix.ValueChanged += new EventHandler(UseDistanceMatrix_ValueChanged);
     264    }
     265
     266    #region Event handlers
     267    void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) {
     268      EvalBestKnownSolution();
     269    }
     270    void DistanceFactorParameter_ValueChanged(object sender, EventArgs e) {
     271      DistanceFactorParameter.Value.ValueChanged += new EventHandler(DistanceFactor_ValueChanged);
     272      EvalBestKnownSolution();
     273    }
     274    void DistanceFactor_ValueChanged(object sender, EventArgs e) {
     275      EvalBestKnownSolution();
     276    }
     277    void FleetUsageFactorParameter_ValueChanged(object sender, EventArgs e) {
     278      FleetUsageFactorParameter.Value.ValueChanged += new EventHandler(FleetUsageFactor_ValueChanged);
     279      EvalBestKnownSolution();
     280    }
     281    void FleetUsageFactor_ValueChanged(object sender, EventArgs e) {
     282      EvalBestKnownSolution();
     283    }
     284    void DistanceMatrixParameter_ValueChanged(object sender, EventArgs e) {
     285      if (DistanceMatrix != null) {
     286        DistanceMatrix.ItemChanged += new EventHandler<EventArgs<int, int>>(DistanceMatrix_ItemChanged);
     287        DistanceMatrix.Reset += new EventHandler(DistanceMatrix_Reset);
     288      }
     289      EvalBestKnownSolution();
     290    }
     291    void DistanceMatrix_Reset(object sender, EventArgs e) {
     292      EvalBestKnownSolution();
     293    }
     294    void DistanceMatrix_ItemChanged(object sender, EventArgs<int, int> e) {
     295      EvalBestKnownSolution();
     296    }
     297    void UseDistanceMatrixParameter_ValueChanged(object sender, EventArgs e) {
     298      UseDistanceMatrix.ValueChanged += new EventHandler(UseDistanceMatrix_ValueChanged);
     299      EvalBestKnownSolution();
     300    }
     301    void UseDistanceMatrix_ValueChanged(object sender, EventArgs e) {
     302      EvalBestKnownSolution();
     303    }
     304    #endregion
    199305  }
    200306}
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs

    r4752 r4860  
    6464      get { return BestKnownQualityParameter; }
    6565    }
     66    public OptionalValueParameter<VRPSolution> BestKnownSolutionParameter {
     67      get { return (OptionalValueParameter<VRPSolution>)Parameters["BestKnownSolution"]; }
     68    }
    6669    public IValueParameter<IVRPCreator> SolutionCreatorParameter {
    6770      get { return (IValueParameter<IVRPCreator>)Parameters["SolutionCreator"]; }
     
    8285      get { return ProblemInstanceParameter.Value; }
    8386      set { ProblemInstanceParameter.Value = value; }
     87    }
     88
     89    public VRPSolution BestKnownSolution {
     90      get { return BestKnownSolutionParameter.Value; }
     91      set { BestKnownSolutionParameter.Value = value; }
    8492    }
    8593
     
    111119      Parameters.Add(new ValueParameter<IVRPProblemInstance>("ProblemInstance", "The VRP problem instance"));
    112120      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this VRP instance."));
     121      Parameters.Add(new OptionalValueParameter<VRPSolution>("BestKnownSolution", "The best known solution of this VRP instance."));
    113122
    114123      operators = new List<IOperator>();
     
    172181        Parameters.Remove("SolutionCreator");
    173182
     183      if (Parameters.ContainsKey("BestKnownSolution"))
     184        Parameters.Remove("BestKnownSolution");
     185
     186      if (Parameters.ContainsKey("BestKnownQuality"))
     187        Parameters.Remove("BestKnownQuality");
     188
     189
    174190      if (ProblemInstance != null) {
    175191        ProblemInstance.SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
     
    177193        Parameters.Add(ProblemInstance.EvaluatorParameter);
    178194        Parameters.Add(ProblemInstance.SolutionCreatorParameter);
     195
     196        Parameters.Add(ProblemInstance.BestKnownQualityParameter);
     197        Parameters.Add(ProblemInstance.BestKnownSolutionParameter);
    179198      }
    180199    }
     
    251270      int problemSize = parser.Demands.Length;
    252271
    253       if (parser.Depot != 1)
    254         throw new Exception("Invalid depot specification");
    255 
    256       if (parser.WeightType != TSPLIBParser.TSPLIBEdgeWeightType.EUC_2D)
    257         throw new Exception("Invalid weight type");
     272      if (parser.Depot != 1) {
     273        ErrorHandling.ShowErrorDialog(new Exception("Invalid depot specification"));
     274        return;
     275      }
     276
     277      if (parser.WeightType != TSPLIBParser.TSPLIBEdgeWeightType.EUC_2D)  {
     278        ErrorHandling.ShowErrorDialog(new Exception("Invalid weight type"));
     279        return;
     280      }
    258281
    259282      CVRPTWProblemInstance problem = new CVRPTWProblemInstance();
     
    337360      this.ProblemInstance = problem;
    338361    }
     362
     363    public void ImportSolution(string solutionFileName) {
     364      SolutionParser parser = new SolutionParser(solutionFileName);
     365      parser.Parse();
     366
     367      HeuristicLab.Problems.VehicleRouting.Encodings.Potvin.PotvinEncoding encoding = new Encodings.Potvin.PotvinEncoding(ProblemInstance);
     368
     369      int cities = 0;
     370      foreach (List<int> route in parser.Routes) {
     371        Tour tour = new Tour();
     372        tour.Stops.AddRange(route);
     373        cities += tour.Stops.Count;
     374
     375        encoding.Tours.Add(tour);
     376      }
     377
     378      if (cities != ProblemInstance.Coordinates.Rows - 1)
     379        ErrorHandling.ShowErrorDialog(new Exception("The optimal solution does not seem to correspond with the problem data"));
     380      else {
     381        VRPSolution solution = new VRPSolution(ProblemInstance, encoding, new DoubleValue(0));
     382        ProblemInstance.BestKnownSolutionParameter.Value = solution;
     383      }
     384    }
    339385  }
    340386}
Note: See TracChangeset for help on using the changeset viewer.