- Timestamp:
- 02/13/12 16:35:13 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GeneralizedQuadraticAssignmentProblem.cs
r7448 r7466 38 38 [Creatable("Problems")] 39 39 [StorableClass] 40 public sealed class GeneralizedQuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IGQAPEvaluator, IGQAPSolutionCreator>, IStorableContent, IProblemInstanceConsumer<IQAPInstance>, IProblemInstanceConsumer<ICTAPInstance> {40 public sealed class GeneralizedQuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IGQAPEvaluator, IGQAPSolutionCreator>, IStorableContent, IProblemInstanceConsumer<IQAPInstance>, IProblemInstanceConsumer<ICTAPInstance>, IProblemInstanceConsumer<ITSPInstance>, IProblemInstanceConsumer<IATSPInstance> { 41 41 42 42 public override Image ItemImage { … … 206 206 } 207 207 208 public void LoadFrom(IQAPInstance instance) { 209 Name = instance.Name; 210 Description = instance.Description; 211 212 Weights = new DoubleMatrix(instance.Weights); 213 Distances = new DoubleMatrix(instance.Distances); 214 InstallationCosts = new DoubleMatrix(Weights.Rows, Distances.Columns); // all zero 215 Capacities = new DoubleArray(Enumerable.Range(0, Distances.Rows).Select(x => 1.0).ToArray()); 216 Demands = new DoubleArray(Enumerable.Range(0, Weights.Rows).Select(x => 1.0).ToArray()); 217 218 TransportationCosts.Value = 1; 219 220 if (instance.BestKnownAssignment != null) { 221 EvaluateAndLoadAssignment(instance.BestKnownAssignment); 222 } else { 223 BestKnownQuality = null; 224 BestKnownSolution = null; 225 BestKnownSolutions = null; 226 } 227 } 228 229 public void LoadFrom(ICTAPInstance instance) { 230 Name = instance.Name; 231 Description = instance.Description; 232 233 Capacities = new DoubleArray(instance.MemoryCapacities); 234 Demands = new DoubleArray(instance.MemoryRequirements); 235 Weights = new DoubleMatrix(instance.CommunicationCosts); 236 InstallationCosts = new DoubleMatrix(instance.ExecutionCosts.Transpose()); 237 Distances = new DoubleMatrix(Capacities.Length, Capacities.Length); // all one, except diagonal 238 for (int i = 0; i < Capacities.Length - 1; i++) 239 for (int j = i + 1; j < Capacities.Length; j++) { 240 Distances[i, j] = 1; 241 Distances[j, i] = 1; 242 } 243 244 TransportationCosts.Value = 1; 245 246 if (instance.BestKnownAssignment != null) { 247 EvaluateAndLoadAssignment(instance.BestKnownAssignment); 248 } else { 249 BestKnownQuality = null; 250 BestKnownSolution = null; 251 BestKnownSolutions = null; 252 } 208 public bool LoadFrom(IQAPInstance instance) { 209 try { 210 Name = instance.Name; 211 Description = instance.Description; 212 213 Weights = new DoubleMatrix(instance.Weights); 214 Distances = new DoubleMatrix(instance.Distances); 215 InstallationCosts = new DoubleMatrix(Weights.Rows, Distances.Columns); // all zero 216 Capacities = new DoubleArray(Enumerable.Range(0, Distances.Rows).Select(x => 1.0).ToArray()); 217 Demands = new DoubleArray(Enumerable.Range(0, Weights.Rows).Select(x => 1.0).ToArray()); 218 219 TransportationCosts.Value = 1; 220 221 if (instance.BestKnownAssignment != null) { 222 EvaluateAndLoadAssignment(instance.BestKnownAssignment); 223 } else { 224 BestKnownQuality = null; 225 BestKnownSolution = null; 226 BestKnownSolutions = null; 227 } 228 } catch { 229 return false; 230 } 231 return true; 232 } 233 234 public bool LoadFrom(ICTAPInstance instance) { 235 try { 236 Name = instance.Name; 237 Description = instance.Description; 238 239 Capacities = new DoubleArray(instance.MemoryCapacities); 240 Demands = new DoubleArray(instance.MemoryRequirements); 241 Weights = new DoubleMatrix(instance.CommunicationCosts); 242 InstallationCosts = new DoubleMatrix(instance.ExecutionCosts.Transpose()); 243 Distances = new DoubleMatrix(Capacities.Length, Capacities.Length); // all one, except diagonal 244 for (int i = 0; i < Capacities.Length - 1; i++) 245 for (int j = i + 1; j < Capacities.Length; j++) { 246 Distances[i, j] = 1; 247 Distances[j, i] = 1; 248 } 249 250 TransportationCosts.Value = 1; 251 252 if (instance.BestKnownAssignment != null) { 253 EvaluateAndLoadAssignment(instance.BestKnownAssignment); 254 } else { 255 BestKnownQuality = null; 256 BestKnownSolution = null; 257 BestKnownSolutions = null; 258 } 259 } catch { 260 return false; 261 } 262 return true; 263 } 264 265 public bool LoadFrom(ITSPInstance instance) { 266 try { 267 if (instance.Dimension > 1000) return false; 268 269 Name = instance.Name; 270 Description = instance.Description; 271 272 Capacities = new DoubleArray(instance.Dimension); 273 Demands = new DoubleArray(instance.Dimension); 274 for (int i = 0; i < instance.Dimension; i++) { 275 Capacities[i] = 1; 276 Demands[i] = 1; 277 } 278 InstallationCosts = new DoubleMatrix(instance.Dimension, instance.Dimension); 279 Weights = new DoubleMatrix(instance.Dimension, instance.Dimension); 280 for (int i = 0; i < instance.Dimension; i++) 281 Weights[i, (i + 1) % instance.Dimension] = 1; 282 Distances = new DoubleMatrix(instance.GetDistanceMatrix()); 283 284 TransportationCosts.Value = 1; 285 286 if (instance.BestKnownTour != null) { 287 EvaluateAndLoadAssignment(instance.BestKnownTour); 288 } else { 289 BestKnownQuality = null; 290 BestKnownSolution = null; 291 BestKnownSolutions = null; 292 } 293 } catch { 294 return false; 295 } 296 return true; 297 } 298 299 public bool LoadFrom(IATSPInstance instance) { 300 try { 301 Name = instance.Name; 302 Description = instance.Description; 303 304 Capacities = new DoubleArray(instance.Dimension); 305 Demands = new DoubleArray(instance.Dimension); 306 for (int i = 0; i < instance.Dimension; i++) { 307 Capacities[i] = 1; 308 Demands[i] = 1; 309 } 310 InstallationCosts = new DoubleMatrix(instance.Dimension, instance.Dimension); 311 Weights = new DoubleMatrix(instance.Dimension, instance.Dimension); 312 for (int i = 0; i < instance.Dimension; i++) 313 Weights[i, (i + 1) % instance.Dimension] = 1; 314 Distances = new DoubleMatrix(instance.Distances); 315 316 TransportationCosts.Value = 1; 317 318 if (instance.BestKnownTour != null) { 319 EvaluateAndLoadAssignment(instance.BestKnownTour); 320 } else { 321 BestKnownQuality = null; 322 BestKnownSolution = null; 323 BestKnownSolutions = null; 324 } 325 } catch { 326 return false; 327 } 328 return true; 253 329 } 254 330
Note: See TracChangeset
for help on using the changeset viewer.