- Timestamp:
- 09/19/19 20:35:46 (5 years ago)
- 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 20 20 #endregion 21 21 22 using System.Linq;23 22 using HEAL.Attic; 24 23 using HeuristicLab.Common; … … 48 47 Operators.Add(new PTSPAnalyticalTwoPointFiveMoveEvaluator()); 49 48 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); 54 50 } 55 51 56 52 public override IDeepCloneable Clone(Cloner cloner) { 57 53 return new AnalyticalPTSP(this, cloner); 54 } 55 56 protected override void OnEncodingChanged() { 57 base.OnEncodingChanged(); 58 Encoding.ConfigureOperators(Operators); 58 59 } 59 60 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/EstimatedPTSP.cs
r17260 r17264 29 29 using HeuristicLab.Encodings.PermutationEncoding; 30 30 using HeuristicLab.Parameters; 31 using HeuristicLab.Problems.Instances; 31 32 using HeuristicLab.Random; 32 33 … … 189 190 } 190 191 192 public override void Load(PTSPData data) { 193 base.Load(data); 194 UpdateRealizations(); 195 } 196 191 197 private void UpdateRealizations() { 192 198 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) { 195 203 var cities = 0; 196 204 var r = new bool[ProbabilisticTSPData.Cities]; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Improvers/PTSPAnalyticalInsertionLocalImprovement.cs
r17260 r17264 40 40 [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.")] 41 41 [StorableType("5adca9d8-02b2-4937-9f79-a24d8ea8ea19")] 42 public sealed class PTSPAnalyticalInsertionLocalImprovement : SingleSuccessorOperator, IAnalyticalPTSPOperator, I LocalImprovementOperator {42 public sealed class PTSPAnalyticalInsertionLocalImprovement : SingleSuccessorOperator, IAnalyticalPTSPOperator, IPermutationLocalImprovementOperator { 43 43 44 44 public ILookupParameter<IntValue> LocalIterationsParameter { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Improvers/PTSPAnalyticalInversionLocalImprovement.cs
r17260 r17264 40 40 [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.")] 41 41 [StorableType("88147d6a-e843-4f65-8058-421453b5206a")] 42 public sealed class PTSPAnalyticalInversionLocalImprovement : SingleSuccessorOperator, IAnalyticalPTSPOperator, I LocalImprovementOperator {42 public sealed class PTSPAnalyticalInversionLocalImprovement : SingleSuccessorOperator, IAnalyticalPTSPOperator, IPermutationLocalImprovementOperator { 43 43 44 44 public ILookupParameter<IntValue> LocalIterationsParameter { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Improvers/PTSPAnalyticalTwoPointFiveLocalImprovement.cs
r17260 r17264 40 40 [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.")] 41 41 [StorableType("6e07195e-0da7-45ea-9385-0c66594127db")] 42 public sealed class PTSPAnalyticalTwoPointFiveLocalImprovement : SingleSuccessorOperator, IAnalyticalPTSPOperator, I LocalImprovementOperator {42 public sealed class PTSPAnalyticalTwoPointFiveLocalImprovement : SingleSuccessorOperator, IAnalyticalPTSPOperator, IPermutationLocalImprovementOperator { 43 43 44 44 public ILookupParameter<IntValue> LocalIterationsParameter { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Improvers/PTSPEstimatedInsertionLocalImprovement.cs
r17260 r17264 42 42 [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.")] 43 43 [StorableType("B2D60579-A97D-4E44-B11C-61CDA6EBEBA7")] 44 public sealed class PTSPEstimatedInsertionLocalImprovement : SingleSuccessorOperator, IEstimatedPTSPOperator, I LocalImprovementOperator {44 public sealed class PTSPEstimatedInsertionLocalImprovement : SingleSuccessorOperator, IEstimatedPTSPOperator, IPermutationLocalImprovementOperator { 45 45 46 46 public ILookupParameter<IntValue> LocalIterationsParameter { … … 76 76 } 77 77 78 public ILookupParameter<ReadOnlyItemList<BoolArray>> Realization sParameter {79 get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["Realization s"]; }78 public ILookupParameter<ReadOnlyItemList<BoolArray>> RealizationDataParameter { 79 get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["RealizationData"]; } 80 80 } 81 81 … … 93 93 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem should be maximized or minimized.")); 94 94 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.")); 96 96 } 97 97 … … 131 131 var evaluations = EvaluatedSolutionsParameter.ActualValue; 132 132 var data = ProbabilisticTSPDataParameter.ActualValue; 133 var realizations = Realization sParameter.ActualValue;133 var realizations = RealizationDataParameter.ActualValue; 134 134 if (localIterations == null) { 135 135 localIterations = new IntValue(0); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Improvers/PTSPEstimatedInversionLocalImprovement.cs
r17260 r17264 42 42 [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.")] 43 43 [StorableType("AA67F3B1-2667-4F0B-A79F-4A02B89EE977")] 44 public sealed class PTSPEstimatedInversionLocalImprovement : SingleSuccessorOperator, IEstimatedPTSPOperator, I LocalImprovementOperator {44 public sealed class PTSPEstimatedInversionLocalImprovement : SingleSuccessorOperator, IEstimatedPTSPOperator, IPermutationLocalImprovementOperator { 45 45 46 46 public ILookupParameter<IntValue> LocalIterationsParameter { … … 76 76 } 77 77 78 public ILookupParameter<ReadOnlyItemList<BoolArray>> Realization sParameter {79 get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["Realization s"]; }78 public ILookupParameter<ReadOnlyItemList<BoolArray>> RealizationDataParameter { 79 get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["RealizationData"]; } 80 80 } 81 81 … … 93 93 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem should be maximized or minimized.")); 94 94 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.")); 96 96 } 97 97 … … 131 131 var evaluations = EvaluatedSolutionsParameter.ActualValue; 132 132 var data = ProbabilisticTSPDataParameter.ActualValue; 133 var realizations = Realization sParameter.ActualValue;133 var realizations = RealizationDataParameter.ActualValue; 134 134 if (localIterations == null) { 135 135 localIterations = new IntValue(0); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Improvers/PTSPEstimatedTwoPointFiveLocalImprovement.cs
r17260 r17264 42 42 [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.")] 43 43 [StorableType("8B04265A-50AD-4FAD-99F8-2357D6F10CC3")] 44 public sealed class PTSPEstimatedTwoPointFiveLocalImprovement : SingleSuccessorOperator, IEstimatedPTSPOperator, I LocalImprovementOperator {44 public sealed class PTSPEstimatedTwoPointFiveLocalImprovement : SingleSuccessorOperator, IEstimatedPTSPOperator, IPermutationLocalImprovementOperator { 45 45 46 46 public ILookupParameter<IntValue> LocalIterationsParameter { … … 75 75 get { return (ILookupParameter<IProbabilisticTSPData>)Parameters["PTSP Data"]; } 76 76 } 77 public ILookupParameter<ReadOnlyItemList<BoolArray>> Realization sParameter {78 get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["Realization s"]; }77 public ILookupParameter<ReadOnlyItemList<BoolArray>> RealizationDataParameter { 78 get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["RealizationData"]; } 79 79 } 80 80 … … 92 92 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem should be maximized or minimized.")); 93 93 Parameters.Add(new LookupParameter<IProbabilisticTSPData>("PTSP Data", "The main parameters of the pTSP.")); 94 Parameters.Add(new LookupParameter<ReadOnlyItemList<BoolArray>>("Realization s", "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.")); 95 95 } 96 96 … … 131 131 var evaluations = EvaluatedSolutionsParameter.ActualValue; 132 132 var data = ProbabilisticTSPDataParameter.ActualValue; 133 var realizations = Realization sParameter.ActualValue;133 var realizations = RealizationDataParameter.ActualValue; 134 134 if (localIterations == null) { 135 135 localIterations = new IntValue(0); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Interfaces/IEstimatedPTSPOperator.cs
r17253 r17264 28 28 public interface IEstimatedPTSPOperator : IItem { 29 29 ILookupParameter<IProbabilisticTSPData> ProbabilisticTSPDataParameter { get; } 30 ILookupParameter<ReadOnlyItemList<BoolArray>> Realization sParameter { get; }30 ILookupParameter<ReadOnlyItemList<BoolArray>> RealizationDataParameter { get; } 31 31 } 32 32 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Interfaces/ITwoPointFiveMoveOperator.cs
r17226 r17264 20 20 #endregion 21 21 22 using HEAL.Attic; 22 23 using HeuristicLab.Core; 23 using HeuristicLab.Optimization; 24 using HEAL.Attic; 24 using HeuristicLab.Encodings.PermutationEncoding; 25 25 26 26 namespace HeuristicLab.Problems.PTSP { 27 27 [StorableType("C21E0AC3-85BD-4F40-8DD6-E79A019278E1")] 28 public interface ITwoPointFiveMoveOperator : I MoveOperator {28 public interface ITwoPointFiveMoveOperator : IPermutationMoveOperator { 29 29 ILookupParameter<TwoPointFiveMove> TwoPointFiveMoveParameter { get; } 30 30 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Moves/EstimatedPTSPMoveEvaluator.cs
r17260 r17264 43 43 get { return (ILookupParameter<IProbabilisticTSPData>)Parameters["PTSP Data"]; } 44 44 } 45 public ILookupParameter<ReadOnlyItemList<BoolArray>> Realization sParameter {46 get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["Realization s"]; }45 public ILookupParameter<ReadOnlyItemList<BoolArray>> RealizationDataParameter { 46 get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["RealizationData"]; } 47 47 } 48 48 public ILookupParameter<DoubleValue> QualityParameter { … … 60 60 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation.")); 61 61 Parameters.Add(new LookupParameter<IProbabilisticTSPData>("PTSP Data", "The main parameters of the pTSP.")); 62 Parameters.Add(new LookupParameter<ReadOnlyItemList<BoolArray>>("Realization s", "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.")); 63 63 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of a TSP solution.")); 64 64 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The evaluated quality of a move on a TSP solution.")); … … 67 67 public override IOperation Apply() { 68 68 var permutation = PermutationParameter.ActualValue; 69 var realizations = Realization sParameter.ActualValue;69 var realizations = RealizationDataParameter.ActualValue; 70 70 var data = ProbabilisticTSPDataParameter.ActualValue; 71 71 var relativeQualityDifference = EvaluateMove(permutation, data, realizations); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/ProbabilisticTSP.cs
r17260 r17264 157 157 try { 158 158 var tour = new Permutation(PermutationTypes.RelativeUndirected, data.BestKnownTour); 159 var tourLength = Evaluate(tour, new FastRandom(1));159 var tourLength = Evaluate(tour, new MersenneTwister(1)); 160 160 BestKnownSolution = new ProbabilisticTSPSolution(data.Coordinates != null ? new DoubleMatrix(data.Coordinates) : null, new PercentArray(data.Probabilities), tour, new DoubleValue(tourLength)); 161 161 BestKnownQuality = tourLength;
Note: See TracChangeset
for help on using the changeset viewer.