Changeset 15172 for trunk/sources/HeuristicLab.Problems.Instances.DIMACS/3.3/GcolInstanceProvider.cs
- Timestamp:
- 07/09/17 13:59:36 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.Instances.DIMACS/3.3/GcolInstanceProvider.cs
r15050 r15172 69 69 70 70 using (var stream = entry.Open()) { 71 var parser = new Parser();71 var parser = new GcolParser(); 72 72 parser.Parse(stream); 73 73 var instance = Load(parser); 74 74 instance.Name = id.Name; 75 instance.Description =id.Description;75 instance.Description += Environment.NewLine + id.Description; 76 76 int bestknown; 77 77 if (bkq.TryGetValue(instance.Name, out bestknown)) … … 86 86 } 87 87 public override GCPData ImportData(string path) { 88 var parser = new Parser();88 var parser = new GcolParser(); 89 89 parser.Parse(path); 90 90 var instance = Load(parser); 91 91 instance.Name = Path.GetFileName(path); 92 instance.Description ="Loaded from file \"" + path + "\" on " + DateTime.Now.ToString();92 instance.Description += Environment.NewLine + "Loaded from file \"" + path + "\" on " + DateTime.Now.ToString(); 93 93 return instance; 94 94 } 95 95 96 private GCPData Load( Parser parser) {96 private GCPData Load(GcolParser parser) { 97 97 var instance = new GCPData(); 98 instance.Description = parser.Comments; 98 99 instance.Nodes = parser.Nodes; 99 100 var adjacencies = new int[parser.Edges, 2]; 100 101 var i = 0; 101 102 foreach (var a in parser.AdjacencyList) { 102 adjacencies[i, 0] = a.Item1 - 1;103 adjacencies[i, 1] = a.Item2 - 1;103 adjacencies[i, 0] = a.Item1; 104 adjacencies[i, 1] = a.Item2; 104 105 i++; 105 106 } 106 107 instance.Adjacencies = adjacencies; 107 108 return instance; 109 } 110 111 public override bool CanExportData { get { return true; } } 112 public override void ExportData(GCPData instance, string path) { 113 using (var stream = new StreamWriter(File.Create(path)) { AutoFlush = true }) { 114 stream.WriteLine("c " + instance.Name); 115 foreach (var comment in instance.Description.Split(new[] { Environment.NewLine }, StringSplitOptions.None)) { 116 var c = comment; 117 if (!c.StartsWith("c ")) c = "c " + comment; 118 stream.WriteLine(c); 119 } 120 var edges = instance.Adjacencies.GetLength(0); 121 stream.WriteLine("p edge " + instance.Nodes + " " + edges); 122 for (var i = 0; i < edges; i++) { 123 stream.WriteLine("e " + (instance.Adjacencies[i, 0]+1) + " " + (instance.Adjacencies[i, 1]+1)); 124 } 125 } 108 126 } 109 127
Note: See TracChangeset
for help on using the changeset viewer.