Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/04/11 21:22:06 (14 years ago)
Author:
abeham
Message:

#1330

  • simplified parser
  • correctly reading first matrix as weights (accessed by index of permutation) and second matrix as distances (accessed by value of permutation)
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  
    6262        Distances = new double[Size, Size];
    6363        Weights = new double[Size, Size];
    64         string valLine = reader.ReadLine();
     64        string valLine = null;
    6565        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();
    8466        int read = 0;
    8567        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();
    8972          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) {
    9276              read = 0;
    9377              k++;
    9478            }
    95             Weights[k, read + j] = double.Parse(vals[j]);
    9679          }
    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          }
    9897        }
    9998        return true;
  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs

    r5933 r5947  
    333333          .GetManifestResourceStream(InstancePrefix + instance + ".sln")) {
    334334          QAPLIBSolutionParser solParser = new QAPLIBSolutionParser();
    335           solParser.Parse(solStream, false); // most sln's seem to be of the type index = location => value = facility
     335          solParser.Parse(solStream, true); // most sln's seem to be of the type index = facility => value = location
    336336          if (solParser.Error != null) throw solParser.Error;
    337337          if (!solParser.Quality.IsAlmost(QAPEvaluator.Apply(new Permutation(PermutationTypes.Absolute, solParser.Assignment), Weights, Distances))) {
Note: See TracChangeset for help on using the changeset viewer.