Changeset 13412 for branches/PTSP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBHeterogeneousPTSPInstanceProvider.cs
- Timestamp:
- 11/28/15 23:38:51 (9 years ago)
- Location:
- branches/PTSP/HeuristicLab.Problems.Instances.TSPLIB
- Files:
-
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/PTSP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBHeterogeneousPTSPInstanceProvider.cs
r13408 r13412 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.IO; 24 25 using System.Linq; 25 26 26 27 namespace HeuristicLab.Problems.Instances.TSPLIB { 27 public class TSPLIB TSPInstanceProvider : TSPLIBInstanceProvider<TSPData> {28 public class TSPLIBHeterogeneousPTSPInstanceProvider : TSPLIBInstanceProvider<PTSPData> { 28 29 29 30 public override string Name { 30 get { return "TSPLIB ( symmetricTSP)"; }31 get { return "TSPLIB (heterogeneous symmetric PTSP)"; } 31 32 } 32 33 … … 37 38 protected override string FileExtension { get { return "tsp"; } } 38 39 39 protected override TSPData LoadInstance(TSPLIBParser parser) { 40 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 41 foreach (var desc in base.GetDataDescriptors().OfType<TSPLIBDataDescriptor>()) { 42 desc.Name += " [0.1;0.9]"; 43 desc.SolutionIdentifier = null; 44 yield return desc; 45 } 46 } 47 48 protected override PTSPData LoadInstance(TSPLIBParser parser, IDataDescriptor descriptor = null) { 40 49 parser.Parse(); 41 50 if (parser.FixedEdges != null) throw new InvalidDataException("TSP instance " + parser.Name + " contains fixed edges which are not supported by HeuristicLab."); 42 var instance = new TSPData();51 var instance = new PTSPData(); 43 52 instance.Dimension = parser.Dimension; 44 53 instance.Coordinates = parser.Vertices != null ? parser.Vertices : parser.DisplayVertices; … … 73 82 + Environment.NewLine + Environment.NewLine 74 83 + GetInstanceDescription(); 84 85 var random = new MarsagliaRandom((uint)(descriptor != null ? descriptor.Name : instance.Name).GetHashCode()); 86 instance.Probabilities = Enumerable.Range(0, instance.Dimension).Select(_ => 0.1 + 0.9 * random.NextDouble()).ToArray(); 87 75 88 return instance; 76 89 } 77 90 78 protected override void LoadSolution(TSPLIBParser parser, TSPData instance) {91 protected override void LoadSolution(TSPLIBParser parser, PTSPData instance) { 79 92 parser.Parse(); 80 93 instance.BestKnownTour = parser.Tour.FirstOrDefault(); 81 94 } 82 95 83 public TSPData LoadData(string tspFile, string tourFile, double? bestQuality) {96 public PTSPData LoadData(string tspFile, string tourFile, double? bestQuality) { 84 97 var data = LoadInstance(new TSPLIBParser(tspFile)); 85 98 if (!String.IsNullOrEmpty(tourFile)) {
Note: See TracChangeset
for help on using the changeset viewer.