Changeset 5947
- Timestamp:
- 04/04/11 21:22:06 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/Parsers/QAPLIBParser.cs
r5838 r5947 62 62 Distances = new double[Size, Size]; 63 63 Weights = new double[Size, Size]; 64 string valLine = reader.ReadLine();64 string valLine = null; 65 65 char[] delim = new char[] { ' ' }; 66 for (int i = 0; i < Size; i++) {67 if (i > 0 || String.IsNullOrWhiteSpace(valLine))68 valLine = reader.ReadLine();69 string[] vals = new string[Size];70 string[] partVals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries);71 partVals.CopyTo(vals, 0);72 int index = partVals.Length;73 while (index < Size) {74 valLine = reader.ReadLine();75 partVals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries);76 partVals.CopyTo(vals, index);77 index += partVals.Length;78 }79 for (int j = 0; j < Size; j++) {80 Distances[i, j] = double.Parse(vals[j]);81 }82 }83 valLine = reader.ReadLine();84 66 int read = 0; 85 67 int k = 0; 86 while (!reader.EndOfStream) { 87 if (read > 0 || String.IsNullOrWhiteSpace(valLine)) 88 valLine = reader.ReadLine(); 68 while (k < Size) { 69 if (reader.EndOfStream) throw new InvalidDataException("Reached end of stream while reading first matrix."); 70 valLine = reader.ReadLine(); 71 while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine(); 89 72 string[] vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries); 90 for (int j = 0; j < vals.Length; j++) { 91 if (read + j == Size) { 73 foreach (string val in vals) { 74 Weights[k, read++] = double.Parse(val); 75 if (read == Size) { 92 76 read = 0; 93 77 k++; 94 78 } 95 Weights[k, read + j] = double.Parse(vals[j]);96 79 } 97 read += vals.Length; 80 } 81 82 read = 0; 83 k = 0; 84 85 while (k < Size) { 86 if (reader.EndOfStream) throw new InvalidDataException("Reached end of stream while reading second matrix."); 87 valLine = reader.ReadLine(); 88 while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine(); 89 string[] vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries); 90 foreach (string val in vals) { 91 Distances[k, read++] = double.Parse(val); 92 if (read == Size) { 93 read = 0; 94 k++; 95 } 96 } 98 97 } 99 98 return true; -
trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
r5933 r5947 333 333 .GetManifestResourceStream(InstancePrefix + instance + ".sln")) { 334 334 QAPLIBSolutionParser solParser = new QAPLIBSolutionParser(); 335 solParser.Parse(solStream, false); // most sln's seem to be of the type index = location => value = facility335 solParser.Parse(solStream, true); // most sln's seem to be of the type index = facility => value = location 336 336 if (solParser.Error != null) throw solParser.Error; 337 337 if (!solParser.Quality.IsAlmost(QAPEvaluator.Apply(new Permutation(PermutationTypes.Absolute, solParser.Assignment), Weights, Distances))) {
Note: See TracChangeset
for help on using the changeset viewer.