Changeset 5855 for branches/QAP
- Timestamp:
- 03/29/11 01:42:41 (14 years ago)
- Location:
- branches/QAP
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/QAP/HeuristicLab.Analysis/3.3/MultidimensionalScaling/MultidimensionalScaling.cs
r5723 r5855 61 61 double epsf = 0; 62 62 double epsx = 0; 63 int maxits = 100 0;63 int maxits = 100; 64 64 alglib.mincgstate state = null; 65 65 alglib.mincgreport rep; … … 69 69 double[] c = new double[] { coordinates[i, 0], coordinates[i, 1] }; 70 70 71 if (iterations == 0 && i == 0) { 72 alglib.mincgcreate(c, out state); 73 alglib.mincgsetcond(state, epsg, epsf, epsx, maxits); 74 } else { 75 alglib.mincgrestartfrom(state, c); 71 try { 72 if ((iterations == 0 && i == 0)) { 73 alglib.mincgcreate(c, out state); 74 alglib.mincgsetcond(state, epsg, epsf, epsx, maxits); 75 } else { 76 alglib.mincgrestartfrom(state, c); 77 } 78 alglib.mincgoptimize(state, StressGradient, null, new Info(coordinates, distances, i)); 79 alglib.mincgresults(state, out c, out rep); 80 } catch (alglib.alglibexception e) { } 81 if (!double.IsNaN(c[0]) && !double.IsNaN(c[1])) { 82 coordinates[i, 0] = c[0]; 83 coordinates[i, 1] = c[1]; 76 84 } 77 alglib.mincgoptimize(state, StressGradient, null, new Info(coordinates, distances, i));78 alglib.mincgresults(state, out c, out rep);79 80 coordinates[i, 0] = c[0];81 coordinates[i, 1] = c[1];82 85 } 83 86 } … … 112 115 113 116 public static double CalculateNormalizedStress(int dimension, DoubleMatrix distances, DoubleMatrix coordinates) { 114 double stress = 0 ;117 double stress = 0, normalization = 0; 115 118 for (int i = 0; i < dimension - 1; i++) { 116 119 for (int j = i + 1; j < dimension; j++) { 117 120 if (distances[i, j] != 0) { 118 stress += Stress(coordinates[i, 0], coordinates[i, 1], distances[i, j], coordinates[j, 0], coordinates[j, 1]) 119 /(distances[i, j] * distances[i, j]);121 stress += Stress(coordinates[i, 0], coordinates[i, 1], distances[i, j], coordinates[j, 0], coordinates[j, 1]); 122 normalization += (distances[i, j] * distances[i, j]); 120 123 } 121 124 } 122 125 } 123 return stress;126 return Math.Sqrt(stress / normalization); ; 124 127 } 125 128 -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/QAPView.cs
r5820 r5855 155 155 156 156 private void WriteCenteredTextToBitmap(ref Bitmap bitmap, string text) { 157 if (bitmap == null) return; 157 158 using (Graphics g = Graphics.FromImage(bitmap)) { 158 159 g.TextRenderingHint = TextRenderingHint.AntiAlias; -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
r5838 r5855 104 104 : base() { 105 105 Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null)); 106 Parameters.Add(new ValueParameter<DoubleMatrix>("Coordinates", "The coordinates of the locations. If this is changed the distance matrix is calculated automatically using the euclidean distance."));106 Parameters.Add(new OptionalValueParameter<DoubleMatrix>("Coordinates", "The coordinates of the locations. If this is changed the distance matrix is calculated automatically using the euclidean distance.")); 107 107 Parameters.Add(new ValueParameter<DoubleMatrix>("Weights", "The strength of the connection between the facilities.", new DoubleMatrix(5, 5))); 108 108 Parameters.Add(new ValueParameter<DoubleMatrix>("Distances", "The distance matrix which can either be specified directly without the coordinates, or can be calculated automatically from the coordinates.", new DoubleMatrix(5, 5))); … … 178 178 private void WeightsParameter_ValueChanged(object sender, EventArgs e) { 179 179 Weights.RowsChanged += new EventHandler(Weights_RowsChanged); 180 Weights.ColumnsChanged += new EventHandler(Weights_ColumnsChanged); 180 181 ParameterizeSolutionCreator(); 181 182 ParameterizeEvaluator(); 182 183 ParameterizeOperators(); 184 AdjustDistanceMatrix(); 183 185 } 184 186 private void Weights_RowsChanged(object sender, EventArgs e) { 187 if (Weights.Rows != Weights.Columns) 188 ((IStringConvertibleMatrix)Weights).Columns = Weights.Rows; 189 else { 190 ParameterizeSolutionCreator(); 191 ParameterizeEvaluator(); 192 ParameterizeOperators(); 193 AdjustDistanceMatrix(); 194 } 195 } 196 private void Weights_ColumnsChanged(object sender, EventArgs e) { 197 if (Weights.Rows != Weights.Columns) 198 ((IStringConvertibleMatrix)Weights).Rows = Weights.Columns; 199 else { 200 ParameterizeSolutionCreator(); 201 ParameterizeEvaluator(); 202 ParameterizeOperators(); 203 AdjustDistanceMatrix(); 204 } 205 } 206 private void DistancesParameter_ValueChanged(object sender, EventArgs e) { 207 Distances.RowsChanged += new EventHandler(Distances_RowsChanged); 208 Distances.ColumnsChanged += new EventHandler(Distances_ColumnsChanged); 185 209 ParameterizeSolutionCreator(); 186 210 ParameterizeEvaluator(); 187 211 ParameterizeOperators(); 212 AdjustWeightsMatrix(); 213 } 214 private void Distances_RowsChanged(object sender, EventArgs e) { 215 if (Distances.Rows != Distances.Columns) 216 ((IStringConvertibleMatrix)Distances).Columns = Distances.Rows; 217 else { 218 ParameterizeSolutionCreator(); 219 ParameterizeEvaluator(); 220 ParameterizeOperators(); 221 AdjustWeightsMatrix(); 222 } 223 } 224 private void Distances_ColumnsChanged(object sender, EventArgs e) { 225 if (Distances.Rows != Distances.Columns) 226 ((IStringConvertibleMatrix)Distances).Rows = Distances.Columns; 227 else { 228 ParameterizeSolutionCreator(); 229 ParameterizeEvaluator(); 230 ParameterizeOperators(); 231 AdjustWeightsMatrix(); 232 } 188 233 } 189 234 private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) { 190 Coordinates.Reset += new EventHandler(Coordinates_Reset); 191 Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged); 192 UpdateDistanceMatrix(); 235 if (Coordinates != null) { 236 Coordinates.Reset += new EventHandler(Coordinates_Reset); 237 Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged); 238 UpdateDistancesFromCoordinates(); 239 } 193 240 } 194 241 private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) { 195 UpdateDistance Matrix();242 UpdateDistancesFromCoordinates(); 196 243 } 197 244 private void Coordinates_Reset(object sender, EventArgs e) { 198 UpdateDistance Matrix();245 UpdateDistancesFromCoordinates(); 199 246 } 200 247 #endregion … … 211 258 WeightsParameter.ValueChanged += new EventHandler(WeightsParameter_ValueChanged); 212 259 Weights.RowsChanged += new EventHandler(Weights_RowsChanged); 260 Weights.ColumnsChanged += new EventHandler(Weights_ColumnsChanged); 261 DistancesParameter.ValueChanged += new EventHandler(DistancesParameter_ValueChanged); 262 Distances.RowsChanged += new EventHandler(Distances_RowsChanged); 263 Distances.ColumnsChanged += new EventHandler(Distances_ColumnsChanged); 213 264 CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged); 214 265 Coordinates.Reset += new EventHandler(Coordinates_Reset); … … 273 324 } 274 325 275 private void UpdateDistanceMatrix() { 326 private void AdjustDistanceMatrix() { 327 if (Distances.Rows != Weights.Rows || Distances.Columns != Weights.Columns) { 328 ((IStringConvertibleMatrix)Distances).Rows = Weights.Rows; 329 } 330 } 331 332 private void AdjustWeightsMatrix() { 333 if (Weights.Rows != Distances.Rows || Weights.Columns != Distances.Columns) { 334 ((IStringConvertibleMatrix)Weights).Rows = Distances.Rows; 335 } 336 } 337 338 private void UpdateDistancesFromCoordinates() { 276 339 if (Coordinates != null && Coordinates.Columns == 2 && Coordinates.Rows > 1) { 277 340 DoubleMatrix distance = new DoubleMatrix(Coordinates.Rows, Coordinates.Rows);
Note: See TracChangeset
for help on using the changeset viewer.