- Timestamp:
- 05/08/20 16:55:51 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 1 added
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringProblemDataView.Designer.cs
r17529 r17533 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 HeuristicLab.Problems.TravelingSalesman.Views.TSPVisualizer tspVisualizer1 = new HeuristicLab.Problems.TravelingSalesman.Views.TSPVisualizer(); 47 48 this.tabControl = new System.Windows.Forms.TabControl(); 48 49 this.routingDataTabPage = new System.Windows.Forms.TabPage(); 49 this.routingDataViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();50 50 this.OrienteeringDataTabPage = new System.Windows.Forms.TabPage(); 51 51 this.splitContainer1 = new System.Windows.Forms.SplitContainer(); … … 60 60 this.startingPointTextBox = new System.Windows.Forms.TextBox(); 61 61 this.startingPointLabel = new System.Windows.Forms.Label(); 62 this.tspDataView = new HeuristicLab.Problems.TravelingSalesman.Views.ITSPDataView(); 62 63 this.tabControl.SuspendLayout(); 63 64 this.routingDataTabPage.SuspendLayout(); … … 82 83 // routingDataTabPage 83 84 // 84 this.routingDataTabPage.Controls.Add(this. routingDataViewHost);85 this.routingDataTabPage.Controls.Add(this.tspDataView); 85 86 this.routingDataTabPage.Location = new System.Drawing.Point(4, 22); 86 87 this.routingDataTabPage.Name = "routingDataTabPage"; … … 90 91 this.routingDataTabPage.Text = "Routing Data"; 91 92 this.routingDataTabPage.UseVisualStyleBackColor = true; 92 //93 // routingDataViewHost94 //95 this.routingDataViewHost.Caption = "View";96 this.routingDataViewHost.Content = null;97 this.routingDataViewHost.Dock = System.Windows.Forms.DockStyle.Fill;98 this.routingDataViewHost.Enabled = false;99 this.routingDataViewHost.Location = new System.Drawing.Point(3, 3);100 this.routingDataViewHost.Name = "routingDataViewHost";101 this.routingDataViewHost.ReadOnly = false;102 this.routingDataViewHost.Size = new System.Drawing.Size(527, 395);103 this.routingDataViewHost.TabIndex = 0;104 this.routingDataViewHost.ViewsLabelVisible = true;105 this.routingDataViewHost.ViewType = null;106 93 // 107 94 // OrienteeringDataTabPage … … 238 225 this.startingPointLabel.TabIndex = 0; 239 226 this.startingPointLabel.Text = "Starting Point:"; 227 // 228 // tspDataView 229 // 230 this.tspDataView.Caption = "TSP Data View"; 231 this.tspDataView.Content = null; 232 this.tspDataView.Dock = System.Windows.Forms.DockStyle.Fill; 233 this.tspDataView.Location = new System.Drawing.Point(3, 3); 234 this.tspDataView.Name = "tspDataView"; 235 this.tspDataView.ReadOnly = false; 236 this.tspDataView.Size = new System.Drawing.Size(527, 395); 237 this.tspDataView.TabIndex = 0; 238 tspVisualizer1.Coordinates = null; 239 tspVisualizer1.Tour = null; 240 this.tspDataView.Visualizer = tspVisualizer1; 240 241 // 241 242 // OrienteeringProblemDataView … … 263 264 private System.Windows.Forms.TabControl tabControl; 264 265 private System.Windows.Forms.TabPage routingDataTabPage; 265 private MainForm.WindowsForms.ViewHost routingDataViewHost;266 266 private System.Windows.Forms.TabPage OrienteeringDataTabPage; 267 267 private System.Windows.Forms.SplitContainer splitContainer1; … … 276 276 private System.Windows.Forms.TextBox terminalPointTextBox; 277 277 private System.Windows.Forms.Label terminalPointLabel; 278 private TravelingSalesman.Views.ITSPDataView tspDataView; 278 279 } 279 280 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringProblemDataView.cs
r17529 r17533 22 22 using HeuristicLab.Core.Views; 23 23 using HeuristicLab.MainForm; 24 using HeuristicLab.Problems.TravelingSalesman.Views;25 24 26 25 namespace HeuristicLab.Problems.Orienteering.Views { … … 41 40 base.OnContentChanged(); 42 41 if (Content == null) { 43 routingDataViewHost.Content = null;44 42 startingPointTextBox.Text = string.Empty; 45 43 terminalPointTextBox.Text = string.Empty; … … 48 46 scoresArrayView.Content = null; 49 47 } else { 50 routingDataViewHost.Content = Content.RoutingData;51 48 startingPointTextBox.Text = Content.StartingPoint.ToString(); 52 49 terminalPointTextBox.Text = Content.TerminalPoint.ToString(); … … 54 51 maximumTravelCostsTextBox.Text = Content.MaximumTravelCosts.ToString(); 55 52 scoresArrayView.Content = Content.Scores; 56 if (routingDataViewHost.ActiveView is ITSPVisualizerView tspVis)57 tspVis.Visualizer = new OrienteeringVisualizer() {58 Data = Content59 };60 53 } 54 tspDataView.Content = Content?.RoutingData; 61 55 } 62 56 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringSolutionView.Designer.cs
r17526 r17533 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 HeuristicLab.Problems.TravelingSalesman.Views.TSPVisualizer tspVisualizer2 = new HeuristicLab.Problems.TravelingSalesman.Views.TSPVisualizer(); 47 48 this.scoreLabel = new System.Windows.Forms.Label(); 48 49 this.qualityLabel = new System.Windows.Forms.Label(); 49 50 this.qualityValueView = new HeuristicLab.Data.Views.StringConvertibleValueView(); 50 51 this.scoreValueView = new HeuristicLab.Data.Views.StringConvertibleValueView(); 51 this.tabControl.SuspendLayout(); 52 this.visualizationTabPage.SuspendLayout(); 53 ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); 54 this.routeTabPage.SuspendLayout(); 52 this.tspSolutionView = new HeuristicLab.Problems.TravelingSalesman.Views.TSPSolutionView(); 55 53 this.SuspendLayout(); 56 //57 // tabControl58 //59 this.tabControl.Location = new System.Drawing.Point(3, 88);60 this.tabControl.Size = new System.Drawing.Size(417, 314);61 //62 // visualizationTabPage63 //64 this.visualizationTabPage.Size = new System.Drawing.Size(409, 288);65 //66 // pictureBox67 //68 this.pictureBox.Size = new System.Drawing.Size(403, 282);69 //70 // routeTabPage71 //72 this.routeTabPage.Size = new System.Drawing.Size(409, 234);73 //74 // tourViewHost75 //76 this.tourViewHost.Size = new System.Drawing.Size(403, 228);77 //78 // distanceView79 //80 this.distanceView.Location = new System.Drawing.Point(62, 61);81 //82 // distanceLabel83 //84 this.distanceLabel.Location = new System.Drawing.Point(4, 64);85 54 // 86 55 // scoreLabel … … 112 81 this.qualityValueView.Name = "qualityValueView"; 113 82 this.qualityValueView.ReadOnly = false; 114 this.qualityValueView.Size = new System.Drawing.Size( 357, 21);83 this.qualityValueView.Size = new System.Drawing.Size(565, 21); 115 84 this.qualityValueView.TabIndex = 0; 116 85 // … … 125 94 this.scoreValueView.Name = "scoreValueView"; 126 95 this.scoreValueView.ReadOnly = false; 127 this.scoreValueView.Size = new System.Drawing.Size( 357, 21);96 this.scoreValueView.Size = new System.Drawing.Size(565, 21); 128 97 this.scoreValueView.TabIndex = 0; 98 // 99 // tspSolutionView 100 // 101 this.tspSolutionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 102 | System.Windows.Forms.AnchorStyles.Left) 103 | System.Windows.Forms.AnchorStyles.Right))); 104 this.tspSolutionView.Caption = "TSP Solution View"; 105 this.tspSolutionView.Content = null; 106 this.tspSolutionView.Location = new System.Drawing.Point(0, 61); 107 this.tspSolutionView.Name = "tspSolutionView"; 108 this.tspSolutionView.ReadOnly = false; 109 this.tspSolutionView.Size = new System.Drawing.Size(630, 252); 110 this.tspSolutionView.TabIndex = 2; 111 tspVisualizer2.Coordinates = null; 112 tspVisualizer2.Tour = null; 113 this.tspSolutionView.Visualizer = tspVisualizer2; 129 114 // 130 115 // OrienteeringSolutionView 131 116 // 132 117 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 118 this.Controls.Add(this.tspSolutionView); 133 119 this.Controls.Add(this.scoreLabel); 134 120 this.Controls.Add(this.qualityLabel); … … 136 122 this.Controls.Add(this.scoreValueView); 137 123 this.Name = "OrienteeringSolutionView"; 138 this.Controls.SetChildIndex(this.scoreValueView, 0); 139 this.Controls.SetChildIndex(this.qualityValueView, 0); 140 this.Controls.SetChildIndex(this.qualityLabel, 0); 141 this.Controls.SetChildIndex(this.scoreLabel, 0); 142 this.Controls.SetChildIndex(this.tabControl, 0); 143 this.Controls.SetChildIndex(this.distanceView, 0); 144 this.Controls.SetChildIndex(this.distanceLabel, 0); 145 this.tabControl.ResumeLayout(false); 146 this.visualizationTabPage.ResumeLayout(false); 147 ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); 148 this.routeTabPage.ResumeLayout(false); 124 this.Size = new System.Drawing.Size(630, 313); 149 125 this.ResumeLayout(false); 150 126 this.PerformLayout(); … … 157 133 private Data.Views.StringConvertibleValueView qualityValueView; 158 134 private Data.Views.StringConvertibleValueView scoreValueView; 135 private TravelingSalesman.Views.TSPSolutionView tspSolutionView; 159 136 } 160 137 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringSolutionView.cs
r17526 r17533 21 21 22 22 using System.ComponentModel; 23 using HeuristicLab.Core.Views; 23 24 using HeuristicLab.MainForm; 24 using HeuristicLab.Problems.TravelingSalesman.Views;25 25 26 26 namespace HeuristicLab.Problems.Orienteering.Views { 27 27 [View("OrienteeringSolution View")] 28 [Content(typeof(OrienteeringSolution), true)] 29 public partial class OrienteeringSolutionView : TSPSolutionView { 30 public new OrienteeringVisualizer Visualizer { 31 get { return (OrienteeringVisualizer)base.Visualizer; } 32 set { base.Visualizer = value; } 33 } 34 public new OrienteeringSolution Content { 35 get { return (OrienteeringSolution)base.Content; } 28 [Content(typeof(IOrienteeringSolution), true)] 29 public partial class OrienteeringSolutionView : ItemView { 30 public OrienteeringVisualizer Visualizer { get; set; } 31 32 public new IOrienteeringSolution Content { 33 get { return (IOrienteeringSolution)base.Content; } 36 34 set { base.Content = value; } 37 35 } … … 39 37 InitializeComponent(); 40 38 Visualizer = new OrienteeringVisualizer(); 39 tspSolutionView.Visualizer = Visualizer; 41 40 } 42 41 … … 50 49 } 51 50 52 protected override void ContentOnPropertyChanged(object sender, PropertyChangedEventArgs e) { 53 base.ContentOnPropertyChanged(sender, e); 51 protected virtual void ContentOnPropertyChanged(object sender, PropertyChangedEventArgs e) { 54 52 switch (e.PropertyName) { 55 53 case nameof(Content.Quality): … … 71 69 qualityValueView.Content = Content.Quality; 72 70 scoreValueView.Content = Content.Score; 73 Visualizer.Data = Content. OPData;74 Visualizer.IsFeasible = Content.TravelCosts.Value <= Content. OPData.MaximumTravelCosts;71 Visualizer.Data = Content.Data; 72 Visualizer.IsFeasible = Content.TravelCosts.Value <= Content.Data.MaximumTravelCosts; 75 73 } 74 tspSolutionView.Content = Content; 76 75 base.OnContentChanged(); 77 76 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringVisualizer.cs
r17525 r17533 36 36 37 37 if ((coordinates != null) && (coordinates.Rows > 0) && (coordinates.Columns == 2) 38 && (coordinates.Rows == Data. RoutingData.Cities)) {38 && (coordinates.Rows == Data.Cities)) { 39 39 double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue; 40 40 for (int i = 0; i < coordinates.Rows; i++) { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/Creators/GreedyOrienteeringTourCreator.cs
r17525 r17533 66 66 // Find all points within the maximum distance allowed (ellipse) 67 67 var feasiblePoints = ( 68 from point in Enumerable.Range(0, data. RoutingData.Cities)69 let travelCosts = data. RoutingData.GetDistance(data.StartingPoint, point)70 + data. RoutingData.GetDistance(point, data.TerminalPoint) + data.PointVisitingCosts68 from point in Enumerable.Range(0, data.Cities) 69 let travelCosts = data.GetDistance(data.StartingPoint, point) 70 + data.GetDistance(point, data.TerminalPoint) + data.PointVisitingCosts 71 71 let score = data.GetScore(point) 72 72 where travelCosts <= data.MaximumTravelCosts … … 81 81 data.TerminalPoint 82 82 }; 83 double tourLength = data. RoutingData.GetDistance(data.StartingPoint, data.TerminalPoint);83 double tourLength = data.GetDistance(data.StartingPoint, data.TerminalPoint); 84 84 85 85 // Add points in a greedy way -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/Improvers/OrienteeringLocalImprovementOperator.cs
r17525 r17533 126 126 127 127 // Determine all points that have not yet been visited by this tour 128 var visitablePoints = Enumerable.Range(0, data. RoutingData.Cities).Except(tour).ToList();128 var visitablePoints = Enumerable.Range(0, data.Cities).Except(tour).ToList(); 129 129 130 130 // Determine if any of the visitable points can be included at any position within the tour … … 168 168 double newLength = tourLength; 169 169 // Recalculate length of whole swapped part, in case distances are not symmetric 170 for (int index = position - 1; index < position + blockLength; index++) newLength -= data. RoutingData.GetDistance(tour[index], tour[index + 1]);171 for (int index = position + blockLength - 1; index > position; index--) newLength += data. RoutingData.GetDistance(tour[index], tour[index - 1]);172 newLength += data. RoutingData.GetDistance(tour[position - 1], tour[position + blockLength - 1]);173 newLength += data. RoutingData.GetDistance(tour[position], tour[position + blockLength]);170 for (int index = position - 1; index < position + blockLength; index++) newLength -= data.GetDistance(tour[index], tour[index + 1]); 171 for (int index = position + blockLength - 1; index > position; index--) newLength += data.GetDistance(tour[index], tour[index - 1]); 172 newLength += data.GetDistance(tour[position - 1], tour[position + blockLength - 1]); 173 newLength += data.GetDistance(tour[position], tour[position + blockLength]); 174 174 175 175 if (newLength < tourLength - 0.00001) { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs
r17529 r17533 96 96 } 97 97 public static double CalculateTravelCosts(IOrienteeringProblemData data, IntegerVector solution) { 98 var distance = data. RoutingData.GetPathDistance(solution, closed: false);98 var distance = data.GetPathDistance(solution, closed: false); 99 99 distance += (solution.Length - 2) * data.PointVisitingCosts; 100 100 return distance; 101 101 } 102 102 public static double CalculateTravelCosts(IOrienteeringProblemData data, IList<int> solution) { 103 var distance = data. RoutingData.GetPathDistance(solution, closed: false);103 var distance = data.GetPathDistance(solution, closed: false); 104 104 distance += (solution.Count - 2) * data.PointVisitingCosts; 105 105 return distance; … … 127 127 } 128 128 public static double CalculateInsertionCosts(IOrienteeringProblemData data, IList<int> path, int insertPosition, int point) { 129 double detour = data. RoutingData.GetDistance(path[insertPosition - 1], point) + data.RoutingData.GetDistance(point, path[insertPosition]);129 double detour = data.GetDistance(path[insertPosition - 1], point) + data.GetDistance(point, path[insertPosition]); 130 130 detour += data.PointVisitingCosts; 131 detour -= data. RoutingData.GetDistance(path[insertPosition - 1], path[insertPosition]);131 detour -= data.GetDistance(path[insertPosition - 1], path[insertPosition]); 132 132 return detour; 133 133 } 134 134 public static double CalculateReplacementCosts(IOrienteeringProblemData data, IList<int> path, int replacePosition, int point) { 135 double detour = data. RoutingData.GetDistance(path[replacePosition - 1], point) + data.RoutingData.GetDistance(point, path[replacePosition + 1]);136 detour -= data. RoutingData.GetDistance(path[replacePosition - 1], path[replacePosition]) + data.RoutingData.GetDistance(path[replacePosition], path[replacePosition + 1]);135 double detour = data.GetDistance(path[replacePosition - 1], point) + data.GetDistance(point, path[replacePosition + 1]); 136 detour -= data.GetDistance(path[replacePosition - 1], path[replacePosition]) + data.GetDistance(path[replacePosition], path[replacePosition + 1]); 137 137 return detour; 138 138 } 139 139 public static double CalculateRemovementSaving(IOrienteeringProblemData data, IList<int> path, int removePosition) { 140 double saving = data. RoutingData.GetDistance(path[removePosition - 1], path[removePosition]);141 saving += data. RoutingData.GetDistance(path[removePosition], path[removePosition + 1]);142 saving -= data. RoutingData.GetDistance(path[removePosition - 1], path[removePosition + 1]);140 double saving = data.GetDistance(path[removePosition - 1], path[removePosition]); 141 saving += data.GetDistance(path[removePosition], path[removePosition + 1]); 142 saving -= data.GetDistance(path[removePosition - 1], path[removePosition + 1]); 143 143 saving += data.PointVisitingCosts; 144 144 return saving; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblemdata.cs
r17531 r17533 1 1 using System; 2 using System.Collections.Generic; 2 3 using HEAL.Attic; 3 4 using HeuristicLab.Common; … … 5 6 using HeuristicLab.Data; 6 7 using HeuristicLab.Encodings.IntegerVectorEncoding; 8 using HeuristicLab.Encodings.PermutationEncoding; 9 using HeuristicLab.Problems.Instances; 7 10 using HeuristicLab.Problems.Instances.Types; 8 11 using HeuristicLab.Problems.TravelingSalesman; … … 10 13 namespace HeuristicLab.Problems.Orienteering { 11 14 [StorableType("c33063a6-a2ee-4054-9dd8-46a738003139")] 12 public interface IOrienteeringProblemData : INamedItem { 13 ITSPData RoutingData { get; } 15 public interface IOrienteeringProblemData : ITSPData { 14 16 int StartingPoint { get; } 15 17 int TerminalPoint { get; } … … 19 21 double GetScore(int city); 20 22 OrienteeringSolution GetSolution(IntegerVector route, double quality, double score, double travelCosts); 21 OPData Export();23 new OPData Export(); 22 24 } 23 25 … … 93 95 } 94 96 97 #region ITSPData members 98 int ITSPData.Cities => RoutingData.Cities; 99 double ITSPData.GetDistance(int fromCity, int toCity) => RoutingData.GetDistance(fromCity, toCity); 100 double ITSPData.GetPathDistance(IEnumerable<int> path, bool closed) => RoutingData.GetPathDistance(path, closed); 101 ITSPSolution ITSPData.GetSolution(Permutation tspTour, double tourLength) => RoutingData.GetSolution(tspTour, tourLength); 102 TSPData ITSPData.Export() => RoutingData.Export(); 103 DoubleMatrix ITSPData.GetCoordinatesOrDefault() => RoutingData.GetCoordinatesOrDefault(); 104 #endregion 105 95 106 private static double[,] defaultCoordinates = new double[21, 2] { 96 107 { 4.60, 7.10 }, { 5.70, 11.40 }, { 4.40, 12.30 }, { 2.80, 14.30 }, { 3.20, 10.30 }, -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringSolution.cs
r17526 r17533 31 31 32 32 namespace HeuristicLab.Problems.Orienteering { 33 public interface IOrienteeringSolution : ITSPSolution { 34 new IOrienteeringProblemData Data { get; } 35 new IntegerVector Tour { get; } 36 DoubleValue Quality { get; } 37 DoubleValue Score { get; } 38 DoubleValue TravelCosts { get; } 39 } 40 33 41 [Item("OrienteeringSolution", "Represents a Orienteering solution which can be visualized in the GUI.")] 34 42 [StorableType("BC58ED08-B9A7-40F3-B8E0-A6B33AA993F4")] 35 public sealed class OrienteeringSolution : Item, I TSPSolution {43 public sealed class OrienteeringSolution : Item, IOrienteeringSolution { 36 44 public static new Image StaticItemImage { 37 45 get { return HeuristicLab.Common.Resources.VSImageLibrary.Image; } … … 40 48 [Storable] private Permutation routeAsPermutation; 41 49 [Storable] private IntegerVector route; 42 public IntegerVector Route{50 public IntegerVector Tour { 43 51 get { return route; } 44 52 set { … … 46 54 route = value; 47 55 routeAsPermutation = new Permutation(PermutationTypes.RelativeDirected, value); 48 OnPropertyChanged(nameof(Route)); 49 OnPropertyChanged(nameof(ITSPSolution.Tour)); 56 OnPropertyChanged(nameof(Tour)); 50 57 } 51 58 } 52 [Storable] private IOrienteeringProblemData opData;53 public IOrienteeringProblemData OPData {54 get { return opData; }59 [Storable] private IOrienteeringProblemData data; 60 public IOrienteeringProblemData Data { 61 get { return data; } 55 62 set { 56 if (opData == value) return; 57 opData = value; 58 OnPropertyChanged(nameof(OPData)); 59 OnPropertyChanged(nameof(ITSPSolution.TSPData)); 63 if (data == value) return; 64 data = value; 65 OnPropertyChanged(nameof(Data)); 60 66 } 61 67 } … … 92 98 } 93 99 94 ITSPData ITSPSolution. TSPData => OPData.RoutingData;100 ITSPData ITSPSolution.Data => Data; 95 101 Permutation ITSPSolution.Tour => routeAsPermutation; 96 102 DoubleValue ITSPSolution.TourLength => TravelCosts; … … 102 108 this.route = cloner.Clone(original.route); 103 109 this.routeAsPermutation = cloner.Clone(original.routeAsPermutation); 104 this. opData = cloner.Clone(original.opData);110 this.data = cloner.Clone(original.data); 105 111 this.quality = cloner.Clone(original.quality); 106 112 this.score = cloner.Clone(original.score); … … 112 118 this.route = route; 113 119 this.routeAsPermutation = new Permutation(PermutationTypes.RelativeDirected, route); 114 this. opData = opData;120 this.data = opData; 115 121 this.quality = quality; 116 122 this.score = score; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/Shakers/OrienteeringShakingOperator.cs
r17525 r17533 96 96 var initialTour = IntegerVectorParameter.ActualValue; 97 97 var data = OrienteeringProblemDataParameter.ActualValue; 98 int numPoints = data. RoutingData.Cities;98 int numPoints = data.Cities; 99 99 100 100 if (NeighborhoodCountParameter.ActualValue == null) … … 117 117 from point in Enumerable.Range(0, numPoints) 118 118 // Calculate the distance when going from the starting point to this point and then to the end point 119 let distance = data. RoutingData.GetDistance(data.StartingPoint, point) + data.RoutingData.GetDistance(point, data.TerminalPoint) + data.PointVisitingCosts119 let distance = data.GetDistance(data.StartingPoint, point) + data.GetDistance(point, data.TerminalPoint) + data.PointVisitingCosts 120 120 // If this distance is feasible and the point is neither starting nor ending point, check the point 121 121 where distance < data.MaximumTravelCosts && point != data.StartingPoint && point != data.TerminalPoint -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP.Views/3.3/Plugin.cs.frame
r17361 r17533 25 25 [Plugin("HeuristicLab.Problems.PTSP.Views", "3.3.16.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Problems.PTSP.Views-3.3.dll", PluginFileType.Assembly)] 27 [PluginDependency("HeuristicLab.Common", "3.3")]28 27 [PluginDependency("HeuristicLab.Core", "3.3")] 29 28 [PluginDependency("HeuristicLab.Core.Views", "3.3")] -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP.Views/3.3/ProbabilisticTSPDataView.Designer.cs
r17335 r17533 28 28 this.probabilitiesTabPage = new System.Windows.Forms.TabPage(); 29 29 this.probabilitiesView = new HeuristicLab.Data.Views.StringConvertibleArrayView(); 30 this.tsp ViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();30 this.tspDataView = new HeuristicLab.Problems.TravelingSalesman.Views.ITSPDataView(); 31 31 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 32 32 this.tabControl.SuspendLayout(); … … 55 55 // coordinatesTabPage 56 56 // 57 this.coordinatesTabPage.Controls.Add(this.tsp ViewHost);57 this.coordinatesTabPage.Controls.Add(this.tspDataView); 58 58 this.coordinatesTabPage.Location = new System.Drawing.Point(4, 22); 59 59 this.coordinatesTabPage.Name = "coordinatesTabPage"; … … 86 86 this.probabilitiesView.TabIndex = 0; 87 87 // 88 // tsp ViewHost88 // tspDataView 89 89 // 90 this.tspViewHost.Caption = "View"; 91 this.tspViewHost.Content = null; 92 this.tspViewHost.Dock = System.Windows.Forms.DockStyle.Fill; 93 this.tspViewHost.Enabled = false; 94 this.tspViewHost.Location = new System.Drawing.Point(3, 3); 95 this.tspViewHost.Name = "tspViewHost"; 96 this.tspViewHost.ReadOnly = false; 97 this.tspViewHost.Size = new System.Drawing.Size(337, 360); 98 this.tspViewHost.TabIndex = 0; 99 this.tspViewHost.ViewsLabelVisible = true; 100 this.tspViewHost.ViewType = null; 90 this.tspDataView.Caption = "TSP Data View"; 91 this.tspDataView.Content = null; 92 this.tspDataView.Dock = System.Windows.Forms.DockStyle.Fill; 93 this.tspDataView.Location = new System.Drawing.Point(3, 3); 94 this.tspDataView.Name = "tspDataView"; 95 this.tspDataView.ReadOnly = false; 96 this.tspDataView.Size = new System.Drawing.Size(337, 360); 97 this.tspDataView.TabIndex = 0; 101 98 // 102 99 // ProbabilisticTSPDataView … … 124 121 private System.Windows.Forms.TabPage probabilitiesTabPage; 125 122 private Data.Views.StringConvertibleArrayView probabilitiesView; 126 private MainForm.WindowsForms.ViewHost tspViewHost;123 private TravelingSalesman.Views.ITSPDataView tspDataView; 127 124 } 128 125 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP.Views/3.3/ProbabilisticTSPDataView.cs
r17335 r17533 24 24 using HeuristicLab.MainForm; 25 25 using HeuristicLab.MainForm.WindowsForms; 26 using HeuristicLab.Problems.TravelingSalesman.Views;27 26 28 27 namespace HeuristicLab.Problems.PTSP.Views { … … 41 40 InitializeComponent(); 42 41 Visualizer = new ProbabilisticTSPVisualizer(); 42 tspDataView.Visualizer = Visualizer; 43 43 } 44 44 … … 47 47 if (Content == null) { 48 48 probabilitiesView.Content = null; 49 tspViewHost.Content = null;50 49 Visualizer.Probabilities = null; 51 50 } else { 52 51 probabilitiesView.Content = Content.Probabilities; 53 52 Visualizer.Probabilities = Content.Probabilities; 54 tspViewHost.Content = Content.TSPData;55 if (tspViewHost.ActiveView is ITSPVisualizerView view)56 view.Visualizer = Visualizer;57 53 } 54 tspDataView.Content = Content?.TSPData; 58 55 } 59 56 … … 61 58 base.SetEnabledStateOfControls(); 62 59 probabilitiesView.Enabled = !ReadOnly && !Locked && Content != null; 63 tsp ViewHost.Enabled = !ReadOnly && !Locked && Content != null;60 tspDataView.Enabled = !ReadOnly && !Locked && Content != null; 64 61 } 65 62 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP.Views/3.3/ProbabilisticTSPSolutionView.Designer.cs
r17260 r17533 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 HeuristicLab.Problems.TravelingSalesman.Views.TSPVisualizer tspVisualizer1 = new HeuristicLab.Problems.TravelingSalesman.Views.TSPVisualizer(); 48 this.tspSolutionView = new HeuristicLab.Problems.TravelingSalesman.Views.TSPSolutionView(); 49 this.SuspendLayout(); 50 // 51 // tspSolutionView 52 // 53 this.tspSolutionView.Caption = "TSP Solution View"; 54 this.tspSolutionView.Content = null; 55 this.tspSolutionView.Dock = System.Windows.Forms.DockStyle.Fill; 56 this.tspSolutionView.Location = new System.Drawing.Point(0, 0); 57 this.tspSolutionView.Name = "tspSolutionView"; 58 this.tspSolutionView.ReadOnly = false; 59 this.tspSolutionView.Size = new System.Drawing.Size(704, 496); 60 this.tspSolutionView.TabIndex = 0; 61 tspVisualizer1.Coordinates = null; 62 tspVisualizer1.Tour = null; 63 this.tspSolutionView.Visualizer = tspVisualizer1; 64 // 65 // ProbabilisticTSPSolutionView 66 // 67 this.Controls.Add(this.tspSolutionView); 68 this.Name = "ProbabilisticTSPSolutionView"; 69 this.Size = new System.Drawing.Size(704, 496); 70 this.ResumeLayout(false); 71 47 72 } 48 73 #endregion 74 75 private TravelingSalesman.Views.TSPSolutionView tspSolutionView; 49 76 } 50 77 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP.Views/3.3/ProbabilisticTSPSolutionView.cs
r17335 r17533 20 20 #endregion 21 21 22 using System;23 using System.Drawing;24 22 using HeuristicLab.Core.Views; 25 using HeuristicLab.Data;26 using HeuristicLab.Encodings.PermutationEncoding;27 23 using HeuristicLab.MainForm; 28 using HeuristicLab.Problems.TravelingSalesman.Views;29 24 30 25 namespace HeuristicLab.Problems.PTSP.Views { … … 35 30 [Content(typeof(IProbabilisticTSPSolution), true)] 36 31 public sealed partial class ProbabilisticTSPSolutionView : ItemView { 37 public TSPVisualizer Visualizer { get; set; } 32 33 public ProbabilisticTSPVisualizer Visualizer { get; set; } 38 34 39 35 public new IProbabilisticTSPSolution Content { … … 48 44 InitializeComponent(); 49 45 Visualizer = new ProbabilisticTSPVisualizer(); 46 tspSolutionView.Visualizer = Visualizer; 47 } 48 49 protected override void OnContentChanged() { 50 base.OnContentChanged(); 51 if (Content == null) 52 Visualizer.Probabilities = null; 53 else Visualizer.Probabilities = Content.Probabilities; 54 tspSolutionView.Content = Content; 50 55 } 51 56 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/AnalyticalPTSP.cs
r17382 r17533 71 71 for (var i = 0; i < tour.Length - 1; i++) { 72 72 for (var j = i + 1; j < tour.Length; j++) { 73 var prod1 = data. TSPData.GetDistance(tour[i], tour[j]) * data.GetProbability(tour[i]) * data.GetProbability(tour[j]);73 var prod1 = data.GetDistance(tour[i], tour[j]) * data.GetProbability(tour[i]) * data.GetProbability(tour[j]); 74 74 for (var k = i + 1; k < j; k++) { 75 75 prod1 *= (1 - data.GetProbability(tour[k])); … … 81 81 for (var j = 0; j < tour.Length; j++) { 82 82 for (var i = 0; i < j; i++) { 83 var prod2 = data. TSPData.GetDistance(tour[j], tour[i]) * data.GetProbability(tour[i]) * data.GetProbability(tour[j]);83 var prod2 = data.GetDistance(tour[j], tour[i]) * data.GetProbability(tour[i]) * data.GetProbability(tour[j]); 84 84 for (var k = j + 1; k < tour.Length; k++) { 85 85 prod2 *= (1 - data.GetProbability(tour[k])); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/EstimatedPTSP.cs
r17382 r17533 119 119 foreach (var r in realizations) { 120 120 int singleRealization = -1, firstNode = -1; 121 for (var j = 0; j < data. TSPData.Cities; j++) {121 for (var j = 0; j < data.Cities; j++) { 122 122 if (r[tour[j]]) { 123 123 if (singleRealization != -1) { 124 estimatedSum += data. TSPData.GetDistance(singleRealization, tour[j]);124 estimatedSum += data.GetDistance(singleRealization, tour[j]); 125 125 } else { 126 126 firstNode = tour[j]; … … 130 130 } 131 131 if (singleRealization != -1) 132 estimatedSum += data. TSPData.GetDistance(singleRealization, firstNode);132 estimatedSum += data.GetDistance(singleRealization, firstNode); 133 133 count++; 134 134 } … … 153 153 var pSum = 0.0; 154 154 int singleRealization = -1, firstNode = -1; 155 for (var j = 0; j < data. TSPData.Cities; j++) {155 for (var j = 0; j < data.Cities; j++) { 156 156 if (r[tour[j]]) { 157 157 if (singleRealization != -1) { 158 pSum += data. TSPData.GetDistance(singleRealization, tour[j]);158 pSum += data.GetDistance(singleRealization, tour[j]); 159 159 } else { 160 160 firstNode = tour[j]; … … 164 164 } 165 165 if (singleRealization != -1) { 166 pSum += data. TSPData.GetDistance(singleRealization, firstNode);166 pSum += data.GetDistance(singleRealization, firstNode); 167 167 } 168 168 estimatedSum += pSum; … … 201 201 var data = new List<BoolArray>(Realizations); 202 202 var rng = new MersenneTwister((uint)RealizationsSeed); 203 if (Enumerable.Range(0, ProbabilisticTSPData. TSPData.Cities).All(c => ProbabilisticTSPData.GetProbability(c) <= 0))203 if (Enumerable.Range(0, ProbabilisticTSPData.Cities).All(c => ProbabilisticTSPData.GetProbability(c) <= 0)) 204 204 throw new InvalidOperationException("All probabilities are zero."); 205 205 while (data.Count < Realizations) { 206 206 var cities = 0; 207 var r = new bool[ProbabilisticTSPData. TSPData.Cities];208 for (var j = 0; j < ProbabilisticTSPData. TSPData.Cities; j++) {207 var r = new bool[ProbabilisticTSPData.Cities]; 208 for (var j = 0; j < ProbabilisticTSPData.Cities; j++) { 209 209 if (rng.NextDouble() < ProbabilisticTSPData.GetProbability(j)) { 210 210 r[j] = true; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Moves/OneShift/PTSPEstimatedInsertionMoveEvaluator.cs
r17335 r17533 126 126 !(aPosteriori[2] == aPosteriori[4] && aPosteriori[3] == aPosteriori[5])) { 127 127 // compute cost difference between the two a posteriori solutions 128 moveQuality = moveQuality + data. TSPData.GetDistance(aPosteriori[6], aPosteriori[7]) + data.TSPData.GetDistance(aPosteriori[8], aPosteriori[9]) + data.TSPData.GetDistance(aPosteriori[10], aPosteriori[11]);129 moveQuality = moveQuality - data. TSPData.GetDistance(aPosteriori[0], aPosteriori[1]) - data.TSPData.GetDistance(aPosteriori[2], aPosteriori[3]) - data.TSPData.GetDistance(aPosteriori[4], aPosteriori[5]);128 moveQuality = moveQuality + data.GetDistance(aPosteriori[6], aPosteriori[7]) + data.GetDistance(aPosteriori[8], aPosteriori[9]) + data.GetDistance(aPosteriori[10], aPosteriori[11]); 129 moveQuality = moveQuality - data.GetDistance(aPosteriori[0], aPosteriori[1]) - data.GetDistance(aPosteriori[2], aPosteriori[3]) - data.GetDistance(aPosteriori[4], aPosteriori[5]); 130 130 } 131 131 Array.Clear(aPosteriori, 0, aPosteriori.Length); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Moves/TwoOpt/PTSPEstimatedInversionMoveEvaluator.cs
r17335 r17533 89 89 // compute cost difference between the two a posteriori solutions 90 90 if (!(aPosteriori[0] == aPosteriori[2] && aPosteriori[1] == aPosteriori[3])) { 91 moveQuality = moveQuality + data. TSPData.GetDistance(aPosteriori[0], aPosteriori[2]) + data.TSPData.GetDistance(aPosteriori[1], aPosteriori[3])92 - data. TSPData.GetDistance(aPosteriori[0], aPosteriori[1]) - data.TSPData.GetDistance(aPosteriori[2], aPosteriori[3]);91 moveQuality = moveQuality + data.GetDistance(aPosteriori[0], aPosteriori[2]) + data.GetDistance(aPosteriori[1], aPosteriori[3]) 92 - data.GetDistance(aPosteriori[0], aPosteriori[1]) - data.GetDistance(aPosteriori[2], aPosteriori[3]); 93 93 } 94 94 Array.Clear(aPosteriori, 0, aPosteriori.Length); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/ProbabilisticTSP.cs
r17382 r17533 42 42 43 43 #region Parameter Properties 44 [Storable] public ValueParameter<IProbabilisticTSPData> PTSPDataParameter { get; private set;}45 [Storable] public OptionalValueParameter<IProbabilisticTSPSolution> BestKnownSolutionParameter { get; private set;}44 [Storable] public ValueParameter<IProbabilisticTSPData> PTSPDataParameter { get; } 45 [Storable] public OptionalValueParameter<IProbabilisticTSPSolution> BestKnownSolutionParameter { get; } 46 46 #endregion 47 47 … … 70 70 71 71 ProbabilisticTSPData = new ProbabilisticTSPData(); 72 Encoding.Length = ProbabilisticTSPData. TSPData.Cities;72 Encoding.Length = ProbabilisticTSPData.Cities; 73 73 } 74 74 75 75 protected override void OnEncodingChanged() { 76 76 base.OnEncodingChanged(); 77 Encoding.Length = ProbabilisticTSPData. TSPData.Cities;77 Encoding.Length = ProbabilisticTSPData.Cities; 78 78 } 79 79 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/ProbabilisticTSPData.cs
r17525 r17533 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using HEAL.Attic; … … 32 33 namespace HeuristicLab.Problems.PTSP { 33 34 [StorableType("dd2d0ecc-372e-46f1-846f-fb4ca2afa124")] 34 public interface IProbabilisticTSPData : INamedItem { 35 ITSPData TSPData { get; } 36 35 public interface IProbabilisticTSPData : ITSPData { 37 36 double GetProbability(int city); 38 IProbabilisticTSPSolution GetSolution(Permutation tspTour, double tourLength);39 PTSPData Export();37 new IProbabilisticTSPSolution GetSolution(Permutation tspTour, double tourLength); 38 new PTSPData Export(); 40 39 } 41 40 … … 89 88 }; 90 89 } 90 91 #region ITSPData members 92 int ITSPData.Cities => TSPData.Cities; 93 double ITSPData.GetDistance(int fromCity, int toCity) => TSPData.GetDistance(fromCity, toCity); 94 double ITSPData.GetPathDistance(IEnumerable<int> path, bool closed) => TSPData.GetPathDistance(path, closed); 95 ITSPSolution ITSPData.GetSolution(Permutation tspTour, double tourLength) => TSPData.GetSolution(tspTour, tourLength); 96 TSPData ITSPData.Export() => TSPData.Export(); 97 DoubleMatrix ITSPData.GetCoordinatesOrDefault() => TSPData.GetCoordinatesOrDefault(); 98 #endregion 91 99 } 92 100 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/ProbabilisticTSPSolution.cs
r17335 r17533 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.PermutationEncoding; 28 29 using HeuristicLab.Problems.TravelingSalesman; 29 30 30 31 namespace HeuristicLab.Problems.PTSP { 31 32 [StorableType("596f52b5-b2c8-45a0-a7bd-e5b9c787c960")] 32 public interface IProbabilisticTSPSolution : IItem, INotifyPropertyChanged { 33 ITSPSolution TSPSolution { get; } 34 DoubleArray Probabilities { get; } 33 public interface IProbabilisticTSPSolution : ITSPSolution { 34 PercentArray Probabilities { get; } 35 35 } 36 36 … … 57 57 58 58 [Storable] 59 private DoubleArray probabilities;60 public DoubleArray Probabilities {59 private PercentArray probabilities; 60 public PercentArray Probabilities { 61 61 get { return probabilities; } 62 62 set { … … 66 66 } 67 67 } 68 69 ITSPData ITSPSolution.Data => tspSolution.Data; 70 71 Permutation ITSPSolution.Tour => tspSolution.Tour; 72 73 DoubleValue ITSPSolution.TourLength => tspSolution.TourLength; 68 74 69 75 [StorableConstructor] -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman.Views/3.3/HeuristicLab.Problems.TravelingSalesman.Views-3.3.csproj
r17361 r17533 135 135 <DependentUpon>EuclideanTSPDataView.cs</DependentUpon> 136 136 </Compile> 137 <Compile Include="ITSPDataView.cs" /> 137 <Compile Include="ITSPDataView.cs"> 138 <SubType>UserControl</SubType> 139 </Compile> 140 <Compile Include="ITSPDataView.Designer.cs"> 141 <DependentUpon>ITSPDataView.cs</DependentUpon> 142 </Compile> 138 143 <Compile Include="MatrixTSPDataView.cs"> 139 144 <SubType>UserControl</SubType> -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman.Views/3.3/ITSPDataView.cs
r17335 r17533 20 20 #endregion 21 21 22 using HeuristicLab.Core.Views; 23 using HeuristicLab.MainForm; 24 22 25 namespace HeuristicLab.Problems.TravelingSalesman.Views { 23 26 public interface ITSPVisualizerView { 24 27 TSPVisualizer Visualizer { get; set; } 25 28 } 29 30 [View("TSP Data View")] 31 [Content(typeof(ITSPData), IsDefaultView = true)] 32 public partial class ITSPDataView : ItemView { 33 public TSPVisualizer Visualizer { get; set; } = new TSPVisualizer(); 34 35 public new ITSPData Content { 36 get { return (ITSPData)base.Content; } 37 set { base.Content = value; } 38 } 39 40 public ITSPDataView() { 41 InitializeComponent(); 42 } 43 44 protected override void OnContentChanged() { 45 base.OnContentChanged(); 46 viewHost.Content = Content; 47 if (viewHost.ActiveView is ITSPVisualizerView view) 48 view.Visualizer = Visualizer; 49 } 50 51 } 26 52 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman.Views/3.3/TSPSolutionView.Designer.cs
r17526 r17533 121 121 // distanceView 122 122 // 123 this.distanceView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 124 | System.Windows.Forms.AnchorStyles.Right))); 123 125 this.distanceView.Caption = "StringConvertibleValue View"; 124 126 this.distanceView.Content = null; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman.Views/3.3/TSPSolutionView.cs
r17526 r17533 67 67 } else { 68 68 distanceView.Content = Content.TourLength; 69 if (Content.TSPData is CoordinatesTSPData coordTsp) 70 Visualizer.Coordinates = coordTsp.Coordinates; 71 else if (Content.TSPData is MatrixTSPData matrixTsp) 72 Visualizer.Coordinates = matrixTsp.DisplayCoordinates; 69 Visualizer.Coordinates = Content.Data.GetCoordinatesOrDefault(); 73 70 Visualizer.Tour = Content.Tour; 74 71 GenerateImage(); … … 98 95 else { 99 96 switch (e.PropertyName) { 100 case nameof(Content. TSPData):101 if (Content. TSPData is CoordinatesTSPData coordTsp)97 case nameof(Content.Data): 98 if (Content.Data is CoordinatesTSPData coordTsp) 102 99 Visualizer.Coordinates = coordTsp.Coordinates; 103 else if (Content. TSPData is MatrixTSPData matrixTsp)100 else if (Content.Data is MatrixTSPData matrixTsp) 104 101 Visualizer.Coordinates = matrixTsp.DisplayCoordinates; 105 102 GenerateImage(); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/TSPData.cs
r17529 r17533 38 38 ITSPSolution GetSolution(Permutation tspTour, double tourLength); 39 39 TSPData Export(); 40 41 DoubleMatrix GetCoordinatesOrDefault(); 40 42 } 41 43 … … 111 113 }; 112 114 } 115 116 public DoubleMatrix GetCoordinatesOrDefault() { 117 return DisplayCoordinates; 118 } 113 119 } 114 120 … … 178 184 179 185 public abstract TSPData Export(); 186 187 public DoubleMatrix GetCoordinatesOrDefault() { 188 return Coordinates; 189 } 180 190 } 181 191 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/TSPSolution.cs
r17356 r17533 31 31 [StorableType("f08a63d9-0b83-4944-9251-42925baeb872")] 32 32 public interface ITSPSolution : IItem, INotifyPropertyChanged { 33 ITSPData TSPData { get; }33 ITSPData Data { get; } 34 34 Permutation Tour { get; } 35 35 DoubleValue TourLength { get; } … … 47 47 48 48 [Storable] private ITSPData tspData; 49 public ITSPData TSPData {49 public ITSPData Data { 50 50 get { return tspData; } 51 51 set { 52 52 if (tspData == value) return; 53 53 tspData = value; 54 OnPropertyChanged(nameof( TSPData));54 OnPropertyChanged(nameof(Data)); 55 55 } 56 56 }
Note: See TracChangeset
for help on using the changeset viewer.