- Timestamp:
- 03/28/12 15:47:26 (13 years ago)
- Location:
- branches/HeuristicLab.Hive.Azure
- Files:
-
- 2 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive.Azure
- Property svn:ignore
-
old new 3 3 *.resharper 4 4 *.suo 5 *.user 5 6 *.vsp 6 7 Doxygen 8 FxCopResults.txt 7 9 Google.ProtocolBuffers-0.9.1.dll 8 10 HeuristicLab 3.3.5.1.ReSharper.user
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.QuadraticAssignment
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.QuadraticAssignment merged: 7351,7416,7558,7626,7641,7646
- Property svn:mergeinfo changed
-
branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.QuadraticAssignment/3.3/HeuristicLab.Problems.QuadraticAssignment-3.3.csproj
r6952 r7669 125 125 <Compile Include="Interfaces\IQAPMoveEvaluator.cs" /> 126 126 <Compile Include="LocalImprovement\QAPExhaustiveSwap2LocalImprovement.cs" /> 127 <Compile Include="Parsers\QAPLIBSolutionParser.cs" />128 <Compile Include="Parsers\QAPLIBParser.cs" />129 127 <Compile Include="QAPAssignment.cs" /> 130 128 <Compile Include="QAPPermutationProximityCalculator.cs" /> 131 129 <Compile Include="QuadraticAssignmentProblem.cs" /> 132 <EmbeddedResource Include="Data\bur26a.dat" />133 <EmbeddedResource Include="Data\bur26b.dat" />134 <EmbeddedResource Include="Data\bur26c.dat" />135 <EmbeddedResource Include="Data\bur26d.dat" />136 <EmbeddedResource Include="Data\bur26e.dat" />137 <EmbeddedResource Include="Data\bur26f.dat" />138 <EmbeddedResource Include="Data\bur26g.dat" />139 <EmbeddedResource Include="Data\bur26h.dat" />140 <EmbeddedResource Include="Data\chr12a.dat" />141 <EmbeddedResource Include="Data\chr12b.dat" />142 <EmbeddedResource Include="Data\chr12c.dat" />143 <EmbeddedResource Include="Data\chr15a.dat" />144 <EmbeddedResource Include="Data\chr15b.dat" />145 <EmbeddedResource Include="Data\chr15c.dat" />146 <EmbeddedResource Include="Data\chr18a.dat" />147 <EmbeddedResource Include="Data\chr18b.dat" />148 <EmbeddedResource Include="Data\chr20a.dat" />149 <EmbeddedResource Include="Data\chr20b.dat" />150 <EmbeddedResource Include="Data\chr20c.dat" />151 <EmbeddedResource Include="Data\chr22a.dat" />152 <EmbeddedResource Include="Data\chr22b.dat" />153 <EmbeddedResource Include="Data\chr25a.dat" />154 <EmbeddedResource Include="Data\els19.dat" />155 <EmbeddedResource Include="Data\esc128.dat" />156 <EmbeddedResource Include="Data\esc16a.dat" />157 <EmbeddedResource Include="Data\esc16b.dat" />158 <EmbeddedResource Include="Data\esc16c.dat" />159 <EmbeddedResource Include="Data\esc16d.dat" />160 <EmbeddedResource Include="Data\esc16e.dat" />161 <EmbeddedResource Include="Data\esc16f.dat" />162 <EmbeddedResource Include="Data\esc16g.dat" />163 <EmbeddedResource Include="Data\esc16h.dat" />164 <EmbeddedResource Include="Data\esc16i.dat" />165 <EmbeddedResource Include="Data\esc16j.dat" />166 <EmbeddedResource Include="Data\esc32a.dat" />167 <EmbeddedResource Include="Data\esc32b.dat" />168 <EmbeddedResource Include="Data\esc32c.dat" />169 <EmbeddedResource Include="Data\esc32d.dat" />170 <EmbeddedResource Include="Data\esc32e.dat" />171 <EmbeddedResource Include="Data\esc32f.dat" />172 <EmbeddedResource Include="Data\esc32g.dat" />173 <EmbeddedResource Include="Data\esc32h.dat" />174 <EmbeddedResource Include="Data\esc64a.dat" />175 <EmbeddedResource Include="Data\had12.dat" />176 <EmbeddedResource Include="Data\had14.dat" />177 <EmbeddedResource Include="Data\had16.dat" />178 <EmbeddedResource Include="Data\had18.dat" />179 <EmbeddedResource Include="Data\had20.dat" />180 <EmbeddedResource Include="Data\kra30a.dat" />181 <EmbeddedResource Include="Data\kra30b.dat" />182 <EmbeddedResource Include="Data\kra32.dat" />183 <EmbeddedResource Include="Data\lipa20a.dat" />184 <EmbeddedResource Include="Data\lipa20b.dat" />185 <EmbeddedResource Include="Data\lipa30a.dat" />186 <EmbeddedResource Include="Data\lipa30b.dat" />187 <EmbeddedResource Include="Data\lipa40a.dat" />188 <EmbeddedResource Include="Data\lipa40b.dat" />189 <EmbeddedResource Include="Data\lipa50a.dat" />190 <EmbeddedResource Include="Data\lipa50b.dat" />191 <EmbeddedResource Include="Data\lipa60a.dat" />192 <EmbeddedResource Include="Data\lipa60b.dat" />193 <EmbeddedResource Include="Data\lipa70a.dat" />194 <EmbeddedResource Include="Data\lipa70b.dat" />195 <EmbeddedResource Include="Data\lipa80a.dat" />196 <EmbeddedResource Include="Data\lipa80b.dat" />197 <EmbeddedResource Include="Data\lipa90a.dat" />198 <EmbeddedResource Include="Data\lipa90b.dat" />199 <EmbeddedResource Include="Data\nug12.dat" />200 <EmbeddedResource Include="Data\nug14.dat" />201 <EmbeddedResource Include="Data\nug15.dat" />202 <EmbeddedResource Include="Data\nug16a.dat" />203 <EmbeddedResource Include="Data\nug16b.dat" />204 <EmbeddedResource Include="Data\nug17.dat" />205 <EmbeddedResource Include="Data\nug18.dat" />206 <EmbeddedResource Include="Data\nug20.dat" />207 <EmbeddedResource Include="Data\nug21.dat" />208 <EmbeddedResource Include="Data\nug22.dat" />209 <EmbeddedResource Include="Data\nug24.dat" />210 <EmbeddedResource Include="Data\nug25.dat" />211 <EmbeddedResource Include="Data\nug27.dat" />212 <EmbeddedResource Include="Data\nug28.dat" />213 <EmbeddedResource Include="Data\nug30.dat" />214 <EmbeddedResource Include="Data\rou12.dat" />215 <EmbeddedResource Include="Data\rou15.dat" />216 <EmbeddedResource Include="Data\rou20.dat" />217 <EmbeddedResource Include="Data\scr12.dat" />218 <EmbeddedResource Include="Data\scr15.dat" />219 <EmbeddedResource Include="Data\scr20.dat" />220 <EmbeddedResource Include="Data\sko100a.dat" />221 <EmbeddedResource Include="Data\sko100b.dat" />222 <EmbeddedResource Include="Data\sko100c.dat" />223 <EmbeddedResource Include="Data\sko100d.dat" />224 <EmbeddedResource Include="Data\sko100e.dat" />225 <EmbeddedResource Include="Data\sko100f.dat" />226 <EmbeddedResource Include="Data\sko42.dat" />227 <EmbeddedResource Include="Data\sko49.dat" />228 <EmbeddedResource Include="Data\sko56.dat" />229 <EmbeddedResource Include="Data\sko64.dat" />230 <EmbeddedResource Include="Data\sko72.dat" />231 <EmbeddedResource Include="Data\sko81.dat" />232 <EmbeddedResource Include="Data\sko90.dat" />233 <EmbeddedResource Include="Data\ste36a.dat" />234 <EmbeddedResource Include="Data\ste36b.dat" />235 <EmbeddedResource Include="Data\ste36c.dat" />236 <EmbeddedResource Include="Data\tai100a.dat" />237 <EmbeddedResource Include="Data\tai100b.dat" />238 <EmbeddedResource Include="Data\tai10a.dat" />239 <EmbeddedResource Include="Data\tai10b.dat" />240 <EmbeddedResource Include="Data\tai12a.dat" />241 <EmbeddedResource Include="Data\tai12b.dat" />242 <EmbeddedResource Include="Data\tai150b.dat" />243 <EmbeddedResource Include="Data\tai15a.dat" />244 <EmbeddedResource Include="Data\tai15b.dat" />245 <EmbeddedResource Include="Data\tai17a.dat" />246 <EmbeddedResource Include="Data\tai20a.dat" />247 <EmbeddedResource Include="Data\tai20b.dat" />248 <EmbeddedResource Include="Data\tai256c.dat" />249 <EmbeddedResource Include="Data\tai25a.dat" />250 <EmbeddedResource Include="Data\tai25b.dat" />251 <EmbeddedResource Include="Data\tai30a.dat" />252 <EmbeddedResource Include="Data\tai30b.dat" />253 <EmbeddedResource Include="Data\tai35a.dat" />254 <EmbeddedResource Include="Data\tai35b.dat" />255 <EmbeddedResource Include="Data\tai40a.dat" />256 <EmbeddedResource Include="Data\tai40b.dat" />257 <EmbeddedResource Include="Data\tai50a.dat" />258 <EmbeddedResource Include="Data\tai50b.dat" />259 <EmbeddedResource Include="Data\tai60a.dat" />260 <EmbeddedResource Include="Data\tai60b.dat" />261 <EmbeddedResource Include="Data\tai64c.dat" />262 <EmbeddedResource Include="Data\tai80a.dat" />263 <EmbeddedResource Include="Data\tai80b.dat" />264 <EmbeddedResource Include="Data\tho150.dat" />265 <EmbeddedResource Include="Data\tho30.dat" />266 <EmbeddedResource Include="Data\tho40.dat" />267 <EmbeddedResource Include="Data\wil100.dat" />268 <EmbeddedResource Include="Data\wil50.dat" />269 130 <None Include="Plugin.cs.frame" /> 270 131 <Compile Include="Plugin.cs" /> … … 336 197 <Private>False</Private> 337 198 </ProjectReference> 338 </ItemGroup> 339 <ItemGroup> 340 <EmbeddedResource Include="Data\bur26a.sln" /> 341 <EmbeddedResource Include="Data\bur26b.sln" /> 342 <EmbeddedResource Include="Data\bur26c.sln" /> 343 <EmbeddedResource Include="Data\bur26d.sln" /> 344 <EmbeddedResource Include="Data\bur26e.sln" /> 345 <EmbeddedResource Include="Data\bur26f.sln" /> 346 <EmbeddedResource Include="Data\bur26g.sln" /> 347 <EmbeddedResource Include="Data\bur26h.sln" /> 348 <EmbeddedResource Include="Data\chr12a.sln" /> 349 <EmbeddedResource Include="Data\chr12b.sln" /> 350 <EmbeddedResource Include="Data\chr12c.sln" /> 351 <EmbeddedResource Include="Data\chr15a.sln" /> 352 <EmbeddedResource Include="Data\chr15b.sln" /> 353 <EmbeddedResource Include="Data\chr15c.sln" /> 354 <EmbeddedResource Include="Data\chr18a.sln" /> 355 <EmbeddedResource Include="Data\chr18b.sln" /> 356 <EmbeddedResource Include="Data\chr20a.sln" /> 357 <EmbeddedResource Include="Data\chr20b.sln" /> 358 <EmbeddedResource Include="Data\chr20c.sln" /> 359 <EmbeddedResource Include="Data\chr22a.sln" /> 360 <EmbeddedResource Include="Data\chr22b.sln" /> 361 <EmbeddedResource Include="Data\chr25a.sln" /> 362 <EmbeddedResource Include="Data\els19.sln" /> 363 <EmbeddedResource Include="Data\esc128.sln" /> 364 <EmbeddedResource Include="Data\esc16a.sln" /> 365 <EmbeddedResource Include="Data\esc16b.sln" /> 366 <EmbeddedResource Include="Data\esc16c.sln" /> 367 <EmbeddedResource Include="Data\esc16d.sln" /> 368 <EmbeddedResource Include="Data\esc16e.sln" /> 369 <EmbeddedResource Include="Data\esc16f.sln" /> 370 <EmbeddedResource Include="Data\esc16g.sln" /> 371 <EmbeddedResource Include="Data\esc16h.sln" /> 372 <EmbeddedResource Include="Data\esc16i.sln" /> 373 <EmbeddedResource Include="Data\esc16j.sln" /> 374 <EmbeddedResource Include="Data\esc32a.sln" /> 375 <EmbeddedResource Include="Data\esc32e.sln" /> 376 <EmbeddedResource Include="Data\esc32f.sln" /> 377 <EmbeddedResource Include="Data\esc32g.sln" /> 378 <EmbeddedResource Include="Data\had12.sln" /> 379 <EmbeddedResource Include="Data\had14.sln" /> 380 <EmbeddedResource Include="Data\had16.sln" /> 381 <EmbeddedResource Include="Data\had18.sln" /> 382 <EmbeddedResource Include="Data\had20.sln" /> 383 <EmbeddedResource Include="Data\kra30a.sln" /> 384 <EmbeddedResource Include="Data\kra30b.sln" /> 385 <EmbeddedResource Include="Data\kra32.sln" /> 386 <EmbeddedResource Include="Data\lipa20a.sln" /> 387 <EmbeddedResource Include="Data\lipa20b.sln" /> 388 <EmbeddedResource Include="Data\lipa30a.sln" /> 389 <EmbeddedResource Include="Data\lipa30b.sln" /> 390 <EmbeddedResource Include="Data\lipa40a.sln" /> 391 <EmbeddedResource Include="Data\lipa40b.sln" /> 392 <EmbeddedResource Include="Data\lipa50a.sln" /> 393 <EmbeddedResource Include="Data\lipa50b.sln" /> 394 <EmbeddedResource Include="Data\lipa60a.sln" /> 395 <EmbeddedResource Include="Data\lipa60b.sln" /> 396 <EmbeddedResource Include="Data\lipa70a.sln" /> 397 <EmbeddedResource Include="Data\lipa70b.sln" /> 398 <EmbeddedResource Include="Data\lipa80a.sln" /> 399 <EmbeddedResource Include="Data\lipa80b.sln" /> 400 <EmbeddedResource Include="Data\lipa90a.sln" /> 401 <EmbeddedResource Include="Data\lipa90b.sln" /> 402 <EmbeddedResource Include="Data\nug12.sln" /> 403 <EmbeddedResource Include="Data\nug14.sln" /> 404 <EmbeddedResource Include="Data\nug15.sln" /> 405 <EmbeddedResource Include="Data\nug16a.sln" /> 406 <EmbeddedResource Include="Data\nug16b.sln" /> 407 <EmbeddedResource Include="Data\nug17.sln" /> 408 <EmbeddedResource Include="Data\nug18.sln" /> 409 <EmbeddedResource Include="Data\nug20.sln" /> 410 <EmbeddedResource Include="Data\nug21.sln" /> 411 <EmbeddedResource Include="Data\nug22.sln" /> 412 <EmbeddedResource Include="Data\nug24.sln" /> 413 <EmbeddedResource Include="Data\nug25.sln" /> 414 <EmbeddedResource Include="Data\nug27.sln" /> 415 <EmbeddedResource Include="Data\nug28.sln" /> 416 <EmbeddedResource Include="Data\nug30.sln" /> 417 <EmbeddedResource Include="Data\rou12.sln" /> 418 <EmbeddedResource Include="Data\rou15.sln" /> 419 <EmbeddedResource Include="Data\rou20.sln" /> 420 <EmbeddedResource Include="Data\scr12.sln" /> 421 <EmbeddedResource Include="Data\scr15.sln" /> 422 <EmbeddedResource Include="Data\scr20.sln" /> 423 <EmbeddedResource Include="Data\sko100a.sln" /> 424 <EmbeddedResource Include="Data\sko100b.sln" /> 425 <EmbeddedResource Include="Data\sko100c.sln" /> 426 <EmbeddedResource Include="Data\sko100d.sln" /> 427 <EmbeddedResource Include="Data\sko100e.sln" /> 428 <EmbeddedResource Include="Data\sko100f.sln" /> 429 <EmbeddedResource Include="Data\sko49.sln" /> 430 <EmbeddedResource Include="Data\sko81.sln" /> 431 <EmbeddedResource Include="Data\sko90.sln" /> 432 <EmbeddedResource Include="Data\ste36a.sln" /> 433 <EmbeddedResource Include="Data\ste36b.sln" /> 434 <EmbeddedResource Include="Data\ste36c.sln" /> 435 <EmbeddedResource Include="Data\tai100a.sln" /> 436 <EmbeddedResource Include="Data\tai100b.sln" /> 437 <EmbeddedResource Include="Data\tai12a.sln" /> 438 <EmbeddedResource Include="Data\tai12b.sln" /> 439 <EmbeddedResource Include="Data\tai150b.sln" /> 440 <EmbeddedResource Include="Data\tai15a.sln" /> 441 <EmbeddedResource Include="Data\tai15b.sln" /> 442 <EmbeddedResource Include="Data\tai17a.sln" /> 443 <EmbeddedResource Include="Data\tai20a.sln" /> 444 <EmbeddedResource Include="Data\tai20b.sln" /> 445 <EmbeddedResource Include="Data\tai256c.sln" /> 446 <EmbeddedResource Include="Data\tai25a.sln" /> 447 <EmbeddedResource Include="Data\tai25b.sln" /> 448 <EmbeddedResource Include="Data\tai30b.sln" /> 449 <EmbeddedResource Include="Data\tai35b.sln" /> 450 <EmbeddedResource Include="Data\tai40b.sln" /> 451 <EmbeddedResource Include="Data\tai50a.sln" /> 452 <EmbeddedResource Include="Data\tai50b.sln" /> 453 <EmbeddedResource Include="Data\tai60a.sln" /> 454 <EmbeddedResource Include="Data\tai60b.sln" /> 455 <EmbeddedResource Include="Data\tai64c.sln" /> 456 <EmbeddedResource Include="Data\tai80a.sln" /> 457 <EmbeddedResource Include="Data\tai80b.sln" /> 458 <EmbeddedResource Include="Data\tho150.sln" /> 459 <EmbeddedResource Include="Data\tho30.sln" /> 460 <EmbeddedResource Include="Data\wil100.sln" /> 199 <ProjectReference Include="..\..\HeuristicLab.Problems.Instances\3.3\HeuristicLab.Problems.Instances-3.3.csproj"> 200 <Project>{3540E29E-4793-49E7-8EE2-FEA7F61C3994}</Project> 201 <Name>HeuristicLab.Problems.Instances-3.3</Name> 202 <Private>False</Private> 203 </ProjectReference> 461 204 </ItemGroup> 462 205 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.QuadraticAssignment/3.3/Plugin.cs.frame
r7270 r7669 36 36 [PluginDependency("HeuristicLab.Parameters", "3.3")] 37 37 [PluginDependency("HeuristicLab.Persistence", "3.3")] 38 [PluginDependency("HeuristicLab.Problems.Instances", "3.3")] 38 39 public class HeuristicLabProblemsQuadraticAssignmentPlugin : PluginBase { } 39 40 } -
branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
r7270 r7669 23 23 using System.Collections.Generic; 24 24 using System.Drawing; 25 using System.IO;26 25 using System.Linq; 27 using System.Reflection;28 26 using HeuristicLab.Common; 29 27 using HeuristicLab.Core; … … 34 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 35 33 using HeuristicLab.PluginInfrastructure; 34 using HeuristicLab.Problems.Instances; 36 35 37 36 namespace HeuristicLab.Problems.QuadraticAssignment { … … 39 38 [Creatable("Problems")] 40 39 [StorableClass] 41 public sealed class QuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IQAPEvaluator, IPermutationCreator>, IStorableContent {42 private static string InstancePrefix = "HeuristicLab.Problems.QuadraticAssignment.Data.";43 40 public sealed class QuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IQAPEvaluator, IPermutationCreator>, IStorableContent, 41 IProblemInstanceConsumer<QAPData>, 42 IProblemInstanceConsumer<TSPData> { 44 43 public string Filename { get; set; } 45 44 … … 92 91 get { return Operators.OfType<QAPPopulationDiversityAnalyzer>().FirstOrDefault(); } 93 92 } 94 95 public IEnumerable<string> Instances {96 get {97 return Assembly.GetExecutingAssembly()98 .GetManifestResourceNames()99 .Where(x => x.EndsWith(".dat"))100 .OrderBy(x => x)101 .Select(x => x.Replace(".dat", String.Empty))102 .Select(x => x.Replace(InstancePrefix, String.Empty));103 }104 }105 93 #endregion 106 94 … … 109 97 private QuadraticAssignmentProblem(QuadraticAssignmentProblem original, Cloner cloner) 110 98 : base(original, cloner) { 111 AttachEventHandlers();99 RegisterEventHandlers(); 112 100 } 113 101 public QuadraticAssignmentProblem() … … 142 130 143 131 InitializeOperators(); 144 AttachEventHandlers();132 RegisterEventHandlers(); 145 133 } 146 134 … … 165 153 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.", d)); 166 154 } 167 AttachEventHandlers();155 RegisterEventHandlers(); 168 156 #endregion 169 157 } … … 254 242 255 243 #region Helpers 256 private void AttachEventHandlers() {244 private void RegisterEventHandlers() { 257 245 SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged); 258 246 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); … … 266 254 267 255 private void InitializeOperators() { 268 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPermutationOperator>()); 256 var defaultOperators = new HashSet<IPermutationOperator>(new IPermutationOperator[] { 257 new PartiallyMatchedCrossover(), 258 new Swap2Manipulator(), 259 new ExhaustiveSwap2MoveGenerator() 260 }); 261 Operators.AddRange(defaultOperators); 262 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPermutationOperator>().Except(defaultOperators, new TypeEqualityComparer<IPermutationOperator>())); 269 263 Operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator); 270 264 Operators.AddRange(ApplicationManager.Manager.GetInstances<IQAPMoveEvaluator>()); … … 365 359 #endregion 366 360 367 public void LoadInstanceFromFile(string filename) { 368 QAPLIBParser parser = new QAPLIBParser(); 369 parser.Parse(filename); 370 if (parser.Error != null) throw parser.Error; 371 Distances = new DoubleMatrix(parser.Distances); 372 Weights = new DoubleMatrix(parser.Weights); 373 Name = "Quadratic Assignment Problem (imported from " + Path.GetFileNameWithoutExtension(filename) + ")"; 374 Description = "Imported problem data using QAPLIBParser " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().FirstOrDefault().Version + "."; 361 public void Load(QAPData data) { 362 var weights = new DoubleMatrix(data.Weights); 363 var distances = new DoubleMatrix(data.Distances); 364 Name = data.Name; 365 Description = data.Description; 366 Load(weights, distances); 367 EvaluateAndLoadAssignment(data.BestKnownAssignment); 368 OnReset(); 369 } 370 371 public void Load(TSPData data) { 372 if (data.Dimension > 1000) 373 throw new System.IO.InvalidDataException("Instances with more than 1000 customers are not supported by the QAP."); 374 var weights = new DoubleMatrix(data.Dimension, data.Dimension); 375 for (int i = 0; i < data.Dimension; i++) 376 weights[i, (i + 1) % data.Dimension] = 1; 377 var distances = new DoubleMatrix(data.GetDistanceMatrix()); 378 Name = data.Name; 379 Description = data.Description; 380 Load(weights, distances); 381 EvaluateAndLoadAssignment(data.BestKnownTour); 382 OnReset(); 383 } 384 385 public void Load(DoubleMatrix weights, DoubleMatrix distances) { 386 if (weights == null || weights.Rows == 0) 387 throw new System.IO.InvalidDataException("The given instance does not contain weights!"); 388 if (weights.Rows != weights.Columns) 389 throw new System.IO.InvalidDataException("The weights matrix is not a square matrix!"); 390 if (distances == null || distances.Rows == 0) 391 throw new System.IO.InvalidDataException("The given instance does not contain distances!"); 392 if (distances.Rows != distances.Columns) 393 throw new System.IO.InvalidDataException("The distances matrix is not a square matrix!"); 394 if (weights.Rows != distances.Columns) 395 throw new System.IO.InvalidDataException("The weights matrix and the distance matrix are not of equal size!"); 396 397 Weights = weights; 398 Distances = distances; 399 375 400 BestKnownQuality = null; 376 401 BestKnownSolution = null; 377 402 BestKnownSolutions = null; 378 OnReset(); 379 } 380 381 public void LoadInstanceFromFile(string datFilename, string slnFilename) { 382 QAPLIBParser datParser = new QAPLIBParser(); 383 datParser.Parse(datFilename); 384 if (datParser.Error != null) throw datParser.Error; 385 Distances = new DoubleMatrix(datParser.Distances); 386 Weights = new DoubleMatrix(datParser.Weights); 387 Name = "Quadratic Assignment Problem (imported from " + Path.GetFileNameWithoutExtension(datFilename) + ")"; 388 Description = "Imported problem data using QAPLIBParser " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().FirstOrDefault().Version + "."; 389 390 QAPLIBSolutionParser slnParser = new QAPLIBSolutionParser(); 391 slnParser.Parse(slnFilename, true); 392 if (slnParser.Error != null) throw slnParser.Error; 393 394 BestKnownQuality = new DoubleValue(slnParser.Quality); 395 BestKnownSolution = new Permutation(PermutationTypes.Absolute, slnParser.Assignment); 396 BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer()); 397 BestKnownSolutions.Add((Permutation)BestKnownSolution.Clone()); 398 399 if (!BestKnownQuality.Value.IsAlmost(QAPEvaluator.Apply(BestKnownSolution, Weights, Distances))) { 400 // the solution doesn't result in the given quality, maybe indices and values are inverted 401 // try parsing again, this time inverting them 402 slnParser.Reset(); 403 slnParser.Parse(slnFilename, false); 404 if (slnParser.Error != null) throw slnParser.Error; 405 406 BestKnownQuality = new DoubleValue(slnParser.Quality); 407 BestKnownSolution = new Permutation(PermutationTypes.Absolute, slnParser.Assignment); 408 BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer()); 409 BestKnownSolutions.Add((Permutation)BestKnownSolution.Clone()); 410 411 if (!BestKnownQuality.Value.IsAlmost(QAPEvaluator.Apply(BestKnownSolution, Weights, Distances))) { 412 // if the solution still doesn't result in the given quality, remove it and only take the quality 413 BestKnownSolution = null; 414 BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer()); 415 } 416 } 417 OnReset(); 418 } 419 420 public void LoadInstanceFromEmbeddedResource(string instance) { 421 using (Stream stream = Assembly.GetExecutingAssembly() 422 .GetManifestResourceStream(InstancePrefix + instance + ".dat")) { 423 QAPLIBParser datParser = new QAPLIBParser(); 424 datParser.Parse(stream); 425 if (datParser.Error != null) throw datParser.Error; 426 Distances = new DoubleMatrix(datParser.Distances); 427 Weights = new DoubleMatrix(datParser.Weights); 428 Name = instance; 429 Description = "Loaded embedded instance " + instance + " of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().FirstOrDefault().Version + "."; 430 431 bool solutionExists = Assembly.GetExecutingAssembly() 432 .GetManifestResourceNames() 433 .Where(x => x.EndsWith(instance + ".sln")) 434 .Any(); 435 436 if (solutionExists) { 437 using (Stream solStream = Assembly.GetExecutingAssembly() 438 .GetManifestResourceStream(InstancePrefix + instance + ".sln")) { 439 QAPLIBSolutionParser slnParser = new QAPLIBSolutionParser(); 440 slnParser.Parse(solStream, true); 441 if (slnParser.Error != null) throw slnParser.Error; 442 443 BestKnownQuality = new DoubleValue(slnParser.Quality); 444 BestKnownSolution = new Permutation(PermutationTypes.Absolute, slnParser.Assignment); 445 BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer()); 446 BestKnownSolutions.Add((Permutation)BestKnownSolution.Clone()); 447 448 if (!BestKnownQuality.Value.IsAlmost(QAPEvaluator.Apply(BestKnownSolution, Weights, Distances))) { 449 // the solution doesn't result in the given quality, maybe indices and values are inverted 450 // try parsing again, this time inverting them 451 solStream.Seek(0, SeekOrigin.Begin); 452 slnParser.Reset(); 453 slnParser.Parse(solStream, false); 454 if (slnParser.Error != null) throw slnParser.Error; 455 456 BestKnownQuality = new DoubleValue(slnParser.Quality); 457 BestKnownSolution = new Permutation(PermutationTypes.Absolute, slnParser.Assignment); 458 BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer()); 459 BestKnownSolutions.Add((Permutation)BestKnownSolution.Clone()); 460 461 if (!BestKnownQuality.Value.IsAlmost(QAPEvaluator.Apply(BestKnownSolution, Weights, Distances))) { 462 // if the solution still doesn't result in the given quality, remove it and only take the quality 463 BestKnownSolution = null; 464 BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer()); 465 } 466 } 467 } 468 } else { // no solution exists 469 BestKnownSolution = null; 470 BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer()); 471 BestKnownQuality = null; 472 } 473 } 474 OnReset(); 403 } 404 405 public void EvaluateAndLoadAssignment(int[] assignment) { 406 if (assignment == null || assignment.Length == 0) return; 407 var vector = new Permutation(PermutationTypes.Absolute, assignment); 408 var result = QAPEvaluator.Apply(vector, Weights, Distances); 409 BestKnownQuality = new DoubleValue(result); 410 BestKnownSolution = vector; 411 BestKnownSolutions = new ItemSet<Permutation>(); 412 BestKnownSolutions.Add((Permutation)vector.Clone()); 475 413 } 476 414 }
Note: See TracChangeset
for help on using the changeset viewer.