- Timestamp:
- 10/17/19 21:40:30 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP.Views/3.3
- Files:
-
- 3 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP.Views/3.3/HeuristicLab.Problems.PTSP.Views-3.3.csproj
r17320 r17335 172 172 </ItemGroup> 173 173 <ItemGroup> 174 <Compile Include=" CoordinatesPTSPDataView.cs">174 <Compile Include="ProbabilisticTSPDataView.cs"> 175 175 <SubType>UserControl</SubType> 176 176 </Compile> 177 <Compile Include="CoordinatesPTSPDataView.Designer.cs"> 178 <DependentUpon>CoordinatesPTSPDataView.cs</DependentUpon> 179 </Compile> 180 <Compile Include="EuclideanPTSPDataView.cs"> 181 <SubType>UserControl</SubType> 182 </Compile> 183 <Compile Include="EuclideanPTSPDataView.Designer.cs"> 184 <DependentUpon>EuclideanPTSPDataView.cs</DependentUpon> 185 </Compile> 186 <Compile Include="MatrixPTSPDataView.cs"> 187 <SubType>UserControl</SubType> 188 </Compile> 189 <Compile Include="MatrixPTSPDataView.Designer.cs"> 190 <DependentUpon>MatrixPTSPDataView.cs</DependentUpon> 177 <Compile Include="ProbabilisticTSPDataView.Designer.cs"> 178 <DependentUpon>ProbabilisticTSPDataView.cs</DependentUpon> 191 179 </Compile> 192 180 <Compile Include="ProbabilisticTSPSolutionView.cs"> … … 198 186 <Compile Include="Plugin.cs" /> 199 187 <Compile Include="Properties\AssemblyInfo.cs" /> 188 <Compile Include="ProbabilisticTSPVisualizer.cs" /> 200 189 </ItemGroup> 201 190 <ItemGroup> -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP.Views/3.3/ProbabilisticTSPSolutionView.cs
r17260 r17335 22 22 using System; 23 23 using System.Drawing; 24 using HeuristicLab.Core.Views; 24 25 using HeuristicLab.Data; 25 26 using HeuristicLab.Encodings.PermutationEncoding; … … 31 32 /// The base class for visual representations of a path tour for a PTSP. 32 33 /// </summary> 33 [View(" PathPTSPTourView")]34 [View("pTSP Solution View")] 34 35 [Content(typeof(IProbabilisticTSPSolution), true)] 35 public sealed partial class ProbabilisticTSPSolutionView : TSPSolutionView { 36 public sealed partial class ProbabilisticTSPSolutionView : ItemView { 37 public TSPVisualizer Visualizer { get; set; } 38 36 39 public new IProbabilisticTSPSolution Content { 37 40 get { return (IProbabilisticTSPSolution)base.Content; } … … 44 47 public ProbabilisticTSPSolutionView() { 45 48 InitializeComponent(); 46 } 47 48 protected override void GenerateImage() { 49 if ((pictureBox.Width > 0) && (pictureBox.Height > 0)) { 50 if (Content == null) { 51 pictureBox.Image = null; 52 } else { 53 DoubleMatrix coordinates = Content.Coordinates; 54 Permutation permutation = Content.Tour; 55 DoubleArray probabilities = Content.Probabilities; 56 Bitmap bitmap = new Bitmap(pictureBox.Width, pictureBox.Height); 57 58 if ((coordinates != null) && (coordinates.Rows > 0) && (coordinates.Columns == 2) && (probabilities.Length == coordinates.Rows)) { 59 double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue; 60 for (int i = 0; i < coordinates.Rows; i++) { 61 if (xMin > coordinates[i, 0]) xMin = coordinates[i, 0]; 62 if (yMin > coordinates[i, 1]) yMin = coordinates[i, 1]; 63 if (xMax < coordinates[i, 0]) xMax = coordinates[i, 0]; 64 if (yMax < coordinates[i, 1]) yMax = coordinates[i, 1]; 65 } 66 67 int border = 20; 68 double xStep = xMax != xMin ? (pictureBox.Width - 2 * border) / (xMax - xMin) : 1; 69 double yStep = yMax != yMin ? (pictureBox.Height - 2 * border) / (yMax - yMin) : 1; 70 71 Point[] points = new Point[coordinates.Rows]; 72 for (int i = 0; i < coordinates.Rows; i++) 73 points[i] = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)), 74 bitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep)))); 75 76 using (Graphics graphics = Graphics.FromImage(bitmap)) { 77 if (permutation != null && permutation.Length > 1) { 78 Point[] tour = new Point[permutation.Length]; 79 for (int i = 0; i < permutation.Length; i++) { 80 if (permutation[i] >= 0 && permutation[i] < points.Length) 81 tour[i] = points[permutation[i]]; 82 } 83 graphics.DrawPolygon(Pens.Black, tour); 84 } 85 for (int i = 0; i < points.Length; i++) 86 graphics.FillRectangle(Brushes.Red, points[i].X - 2, points[i].Y - 2, Convert.ToInt32(probabilities[i] * 20), Convert.ToInt32(probabilities[i] * 20)); 87 } 88 } else { 89 using (Graphics graphics = Graphics.FromImage(bitmap)) { 90 graphics.Clear(Color.White); 91 Font font = new Font(FontFamily.GenericSansSerif, 12, FontStyle.Regular); 92 string text = "No coordinates defined or in wrong format."; 93 SizeF strSize = graphics.MeasureString(text, font); 94 graphics.DrawString(text, font, Brushes.Black, (float)(pictureBox.Width - strSize.Width) / 2.0f, (float)(pictureBox.Height - strSize.Height) / 2.0f); 95 } 96 } 97 pictureBox.Image = bitmap; 98 } 99 } 49 Visualizer = new ProbabilisticTSPVisualizer(); 100 50 } 101 51 }
Note: See TracChangeset
for help on using the changeset viewer.