Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/19/19 20:35:46 (5 years ago)
Author:
abeham
Message:

#2521: Finished refactoring pTSP

Location:
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/AnalyticalPTSP.cs

    r17260 r17264  
    2020#endregion
    2121
    22 using System.Linq;
    2322using HEAL.Attic;
    2423using HeuristicLab.Common;
     
    4847      Operators.Add(new PTSPAnalyticalTwoPointFiveMoveEvaluator());
    4948
    50       Encoding.ConfigureOperators(Operators.OfType<IOperator>());
    51       foreach (var twopointfiveMoveOperator in Operators.OfType<ITwoPointFiveMoveOperator>()) {
    52         twopointfiveMoveOperator.TwoPointFiveMoveParameter.ActualName = "Permutation.TwoPointFiveMove";
    53       }
     49      Encoding.ConfigureOperators(Operators);
    5450    }
    5551
    5652    public override IDeepCloneable Clone(Cloner cloner) {
    5753      return new AnalyticalPTSP(this, cloner);
     54    }
     55
     56    protected override void OnEncodingChanged() {
     57      base.OnEncodingChanged();
     58      Encoding.ConfigureOperators(Operators);
    5859    }
    5960
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/EstimatedPTSP.cs

    r17260 r17264  
    2929using HeuristicLab.Encodings.PermutationEncoding;
    3030using HeuristicLab.Parameters;
     31using HeuristicLab.Problems.Instances;
    3132using HeuristicLab.Random;
    3233
     
    189190    }
    190191
     192    public override void Load(PTSPData data) {
     193      base.Load(data);
     194      UpdateRealizations();
     195    }
     196
    191197    private void UpdateRealizations() {
    192198      var data = new List<BoolArray>(Realizations);
    193       var rng = new FastRandom(RealizationsSeed);
    194       for (var i = 0; i < Realizations; i++) {
     199      var rng = new MersenneTwister((uint)RealizationsSeed);
     200      if (Enumerable.Range(0, ProbabilisticTSPData.Cities).All(c => ProbabilisticTSPData.GetProbability(c) <= 0))
     201        throw new InvalidOperationException("All probabilities are zero.");
     202      while (data.Count < Realizations) {
    195203        var cities = 0;
    196204        var r = new bool[ProbabilisticTSPData.Cities];
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Improvers/PTSPAnalyticalInsertionLocalImprovement.cs

    r17260 r17264  
    4040  [Item("pTSP Analytical Insertion Local Improvement", "An operator that improves probabilistic traveling salesman solutions. The operator tries to improve the probabilistic traveling salesman solution by swapping two randomly chosen edges for a certain number of times.")]
    4141  [StorableType("5adca9d8-02b2-4937-9f79-a24d8ea8ea19")]
    42   public sealed class PTSPAnalyticalInsertionLocalImprovement : SingleSuccessorOperator, IAnalyticalPTSPOperator, ILocalImprovementOperator {
     42  public sealed class PTSPAnalyticalInsertionLocalImprovement : SingleSuccessorOperator, IAnalyticalPTSPOperator, IPermutationLocalImprovementOperator {
    4343
    4444    public ILookupParameter<IntValue> LocalIterationsParameter {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Improvers/PTSPAnalyticalInversionLocalImprovement.cs

    r17260 r17264  
    4040  [Item("pTSP Analytical Inversion Local Improvement", "An operator that improves probabilistic traveling salesman solutions. The operator tries to improve the probabilistic traveling salesman solution by swapping two randomly chosen edges for a certain number of times.")]
    4141  [StorableType("88147d6a-e843-4f65-8058-421453b5206a")]
    42   public sealed class PTSPAnalyticalInversionLocalImprovement : SingleSuccessorOperator, IAnalyticalPTSPOperator, ILocalImprovementOperator {
     42  public sealed class PTSPAnalyticalInversionLocalImprovement : SingleSuccessorOperator, IAnalyticalPTSPOperator, IPermutationLocalImprovementOperator {
    4343
    4444    public ILookupParameter<IntValue> LocalIterationsParameter {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Improvers/PTSPAnalyticalTwoPointFiveLocalImprovement.cs

    r17260 r17264  
    4040  [Item("pTSP Analytical 2.5 Local Improvement", "An operator that improves probabilistic traveling salesman solutions. The operator tries to improve the probabilistic traveling salesman solution by swapping two randomly chosen edges for a certain number of times.")]
    4141  [StorableType("6e07195e-0da7-45ea-9385-0c66594127db")]
    42   public sealed class PTSPAnalyticalTwoPointFiveLocalImprovement : SingleSuccessorOperator, IAnalyticalPTSPOperator, ILocalImprovementOperator {
     42  public sealed class PTSPAnalyticalTwoPointFiveLocalImprovement : SingleSuccessorOperator, IAnalyticalPTSPOperator, IPermutationLocalImprovementOperator {
    4343
    4444    public ILookupParameter<IntValue> LocalIterationsParameter {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Improvers/PTSPEstimatedInsertionLocalImprovement.cs

    r17260 r17264  
    4242  [Item("pTSP Estimated Insertion Local Improvement", "An operator that improves probabilistic traveling salesman solutions. The operator tries to improve the probabilistic traveling salesman solution by swapping two randomly chosen edges for a certain number of times.")]
    4343  [StorableType("B2D60579-A97D-4E44-B11C-61CDA6EBEBA7")]
    44   public sealed class PTSPEstimatedInsertionLocalImprovement : SingleSuccessorOperator, IEstimatedPTSPOperator, ILocalImprovementOperator {
     44  public sealed class PTSPEstimatedInsertionLocalImprovement : SingleSuccessorOperator, IEstimatedPTSPOperator, IPermutationLocalImprovementOperator {
    4545
    4646    public ILookupParameter<IntValue> LocalIterationsParameter {
     
    7676    }
    7777
    78     public ILookupParameter<ReadOnlyItemList<BoolArray>> RealizationsParameter {
    79       get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["Realizations"]; }
     78    public ILookupParameter<ReadOnlyItemList<BoolArray>> RealizationDataParameter {
     79      get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["RealizationData"]; }
    8080    }
    8181
     
    9393      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem should be maximized or minimized."));
    9494      Parameters.Add(new LookupParameter<IProbabilisticTSPData>("PTSP Data", "The main parameters of the pTSP."));
    95       Parameters.Add(new LookupParameter<ItemList<BoolArray>>("Realizations", "The list of samples drawn from all possible stochastic instances."));
     95      Parameters.Add(new LookupParameter<ReadOnlyItemList<BoolArray>>("RealizationData", "The list of samples drawn from all possible stochastic instances."));
    9696    }
    9797
     
    131131      var evaluations = EvaluatedSolutionsParameter.ActualValue;
    132132      var data = ProbabilisticTSPDataParameter.ActualValue;
    133       var realizations = RealizationsParameter.ActualValue;
     133      var realizations = RealizationDataParameter.ActualValue;
    134134      if (localIterations == null) {
    135135        localIterations = new IntValue(0);
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Improvers/PTSPEstimatedInversionLocalImprovement.cs

    r17260 r17264  
    4242  [Item("PTSP Estimated Inversion Local Improvement", "An operator that improves probabilistic traveling salesman solutions. The operator tries to improve the probabilistic traveling salesman solution by swapping two randomly chosen edges for a certain number of times.")]
    4343  [StorableType("AA67F3B1-2667-4F0B-A79F-4A02B89EE977")]
    44   public sealed class PTSPEstimatedInversionLocalImprovement : SingleSuccessorOperator, IEstimatedPTSPOperator, ILocalImprovementOperator {
     44  public sealed class PTSPEstimatedInversionLocalImprovement : SingleSuccessorOperator, IEstimatedPTSPOperator, IPermutationLocalImprovementOperator {
    4545
    4646    public ILookupParameter<IntValue> LocalIterationsParameter {
     
    7676    }
    7777
    78     public ILookupParameter<ReadOnlyItemList<BoolArray>> RealizationsParameter {
    79       get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["Realizations"]; }
     78    public ILookupParameter<ReadOnlyItemList<BoolArray>> RealizationDataParameter {
     79      get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["RealizationData"]; }
    8080    }
    8181
     
    9393      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem should be maximized or minimized."));
    9494      Parameters.Add(new LookupParameter<IProbabilisticTSPData>("PTSP Data", "The main parameters of the pTSP."));
    95       Parameters.Add(new LookupParameter<ItemList<BoolArray>>("Realizations", "The list of samples drawn from all possible stochastic instances."));
     95      Parameters.Add(new LookupParameter<ReadOnlyItemList<BoolArray>>("RealizationData", "The list of samples drawn from all possible stochastic instances."));
    9696    }
    9797
     
    131131      var evaluations = EvaluatedSolutionsParameter.ActualValue;
    132132      var data = ProbabilisticTSPDataParameter.ActualValue;
    133       var realizations = RealizationsParameter.ActualValue;
     133      var realizations = RealizationDataParameter.ActualValue;
    134134      if (localIterations == null) {
    135135        localIterations = new IntValue(0);
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Improvers/PTSPEstimatedTwoPointFiveLocalImprovement.cs

    r17260 r17264  
    4242  [Item("PTSP Estimated 2.5 Local Improvement", "An operator that improves probabilistic traveling salesman solutions. The operator tries to improve the probabilistic traveling salesman solution by swapping two randomly chosen edges for a certain number of times.")]
    4343  [StorableType("8B04265A-50AD-4FAD-99F8-2357D6F10CC3")]
    44   public sealed class PTSPEstimatedTwoPointFiveLocalImprovement : SingleSuccessorOperator, IEstimatedPTSPOperator, ILocalImprovementOperator {
     44  public sealed class PTSPEstimatedTwoPointFiveLocalImprovement : SingleSuccessorOperator, IEstimatedPTSPOperator, IPermutationLocalImprovementOperator {
    4545
    4646    public ILookupParameter<IntValue> LocalIterationsParameter {
     
    7575      get { return (ILookupParameter<IProbabilisticTSPData>)Parameters["PTSP Data"]; }
    7676    }
    77     public ILookupParameter<ReadOnlyItemList<BoolArray>> RealizationsParameter {
    78       get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["Realizations"]; }
     77    public ILookupParameter<ReadOnlyItemList<BoolArray>> RealizationDataParameter {
     78      get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["RealizationData"]; }
    7979    }
    8080
     
    9292      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem should be maximized or minimized."));
    9393      Parameters.Add(new LookupParameter<IProbabilisticTSPData>("PTSP Data", "The main parameters of the pTSP."));
    94       Parameters.Add(new LookupParameter<ReadOnlyItemList<BoolArray>>("Realizations", "The list of samples drawn from all possible stochastic instances."));
     94      Parameters.Add(new LookupParameter<ReadOnlyItemList<BoolArray>>("RealizationData", "The list of samples drawn from all possible stochastic instances."));
    9595    }
    9696
     
    131131      var evaluations = EvaluatedSolutionsParameter.ActualValue;
    132132      var data = ProbabilisticTSPDataParameter.ActualValue;
    133       var realizations = RealizationsParameter.ActualValue;
     133      var realizations = RealizationDataParameter.ActualValue;
    134134      if (localIterations == null) {
    135135        localIterations = new IntValue(0);
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Interfaces/IEstimatedPTSPOperator.cs

    r17253 r17264  
    2828  public interface IEstimatedPTSPOperator : IItem {
    2929    ILookupParameter<IProbabilisticTSPData> ProbabilisticTSPDataParameter { get; }
    30     ILookupParameter<ReadOnlyItemList<BoolArray>> RealizationsParameter { get; }
     30    ILookupParameter<ReadOnlyItemList<BoolArray>> RealizationDataParameter { get; }
    3131  }
    3232}
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Interfaces/ITwoPointFiveMoveOperator.cs

    r17226 r17264  
    2020#endregion
    2121
     22using HEAL.Attic;
    2223using HeuristicLab.Core;
    23 using HeuristicLab.Optimization;
    24 using HEAL.Attic;
     24using HeuristicLab.Encodings.PermutationEncoding;
    2525
    2626namespace HeuristicLab.Problems.PTSP {
    2727  [StorableType("C21E0AC3-85BD-4F40-8DD6-E79A019278E1")]
    28   public interface ITwoPointFiveMoveOperator : IMoveOperator {
     28  public interface ITwoPointFiveMoveOperator : IPermutationMoveOperator {
    2929    ILookupParameter<TwoPointFiveMove> TwoPointFiveMoveParameter { get; }
    3030  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Moves/EstimatedPTSPMoveEvaluator.cs

    r17260 r17264  
    4343      get { return (ILookupParameter<IProbabilisticTSPData>)Parameters["PTSP Data"]; }
    4444    }
    45     public ILookupParameter<ReadOnlyItemList<BoolArray>> RealizationsParameter {
    46       get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["Realizations"]; }
     45    public ILookupParameter<ReadOnlyItemList<BoolArray>> RealizationDataParameter {
     46      get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["RealizationData"]; }
    4747    }
    4848    public ILookupParameter<DoubleValue> QualityParameter {
     
    6060      Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation."));
    6161      Parameters.Add(new LookupParameter<IProbabilisticTSPData>("PTSP Data", "The main parameters of the pTSP."));
    62       Parameters.Add(new LookupParameter<ReadOnlyItemList<BoolArray>>("Realizations", "The list of samples drawn from all possible stochastic instances."));
     62      Parameters.Add(new LookupParameter<ReadOnlyItemList<BoolArray>>("RealizationData", "The list of samples drawn from all possible stochastic instances."));
    6363      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of a TSP solution."));
    6464      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The evaluated quality of a move on a TSP solution."));
     
    6767    public override IOperation Apply() {
    6868      var permutation = PermutationParameter.ActualValue;
    69       var realizations = RealizationsParameter.ActualValue;
     69      var realizations = RealizationDataParameter.ActualValue;
    7070      var data = ProbabilisticTSPDataParameter.ActualValue;
    7171      var relativeQualityDifference = EvaluateMove(permutation, data, realizations);
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/ProbabilisticTSP.cs

    r17260 r17264  
    157157        try {
    158158          var tour = new Permutation(PermutationTypes.RelativeUndirected, data.BestKnownTour);
    159           var tourLength = Evaluate(tour, new FastRandom(1));
     159          var tourLength = Evaluate(tour, new MersenneTwister(1));
    160160          BestKnownSolution = new ProbabilisticTSPSolution(data.Coordinates != null ? new DoubleMatrix(data.Coordinates) : null, new PercentArray(data.Probabilities), tour, new DoubleValue(tourLength));
    161161          BestKnownQuality = tourLength;
Note: See TracChangeset for help on using the changeset viewer.