Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/23/12 13:27:08 (12 years ago)
Author:
svonolfe
Message:

Adapted the parser to read the distance matrix (#1955)

Location:
branches/DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/Parsers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/Parsers/DynPDPParser.cs

    r8670 r8839  
    5050    }
    5151
     52    public struct DistanceMatrixInformation {
     53      public bool useDistanceMatrix;
     54      public int[,] coordinates;
     55      public double[,] matrix;
     56    }
     57
    5258    protected string file;
    5359    protected string problemName;
    5460    protected List<Vehicle> vehicles;
    5561    protected List<Order> orders;
     62    protected DistanceMatrixInformation distanceMatrix;
    5663
    5764    public string ProblemName {
     
    7380    }
    7481
     82    public DistanceMatrixInformation DistanceMatrix {
     83      get {
     84        return distanceMatrix;
     85      }
     86    }
     87
    7588    public DynPDPParser(string file) {
    7689      this.file = file;
    7790      vehicles = new List<Vehicle>();
    7891      orders = new List<Order>();
     92      distanceMatrix = new DistanceMatrixInformation();
     93      distanceMatrix.useDistanceMatrix = false;
     94      distanceMatrix.coordinates = null;
     95      distanceMatrix.matrix = null;
    7996    }
    8097
  • branches/DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/Parsers/TSPLibDynPDPParser.cs

    r8795 r8839  
    2323using System.IO;
    2424using System.Text.RegularExpressions;
     25using System;
    2526
    2627namespace HeuristicLab.PDPSimulation {
     
    5253        int dueTime = int.Parse(dueTimeLine);
    5354
    54         List<double> xCoord = new List<double>();
    55         List<double> yCoord = new List<double>();
     55        List<int> xCoord = new List<int>();
     56        List<int> yCoord = new List<int>();
    5657
    5758        line = reader.ReadLine();
     
    5960        m = reg.Matches(line);
    6061        while (m.Count == 3) {
    61           xCoord.Add(double.Parse(m[1].Value, System.Globalization.CultureInfo.InvariantCulture));
    62           yCoord.Add(double.Parse(m[2].Value, System.Globalization.CultureInfo.InvariantCulture));
     62          xCoord.Add(int.Parse(m[1].Value, System.Globalization.CultureInfo.InvariantCulture));
     63          yCoord.Add(int.Parse(m[2].Value, System.Globalization.CultureInfo.InvariantCulture));
    6364
    6465          line = reader.ReadLine();
     
    7677
    7778          vehicles.Add(v);
     79        }
     80
     81        if (line.Contains("EDGE_WEIGHT_TYPE: EXPLICIT")) {
     82          line = reader.ReadLine();
     83
     84          int count = xCoord.Count;
     85
     86          distanceMatrix.useDistanceMatrix = true;
     87          distanceMatrix.coordinates = new int[count, 2];
     88          for (int i = 0; i < count; i++) {
     89            distanceMatrix.coordinates[i, 0] = xCoord[i];
     90            distanceMatrix.coordinates[i, 1] = yCoord[i];
     91          }
     92
     93          distanceMatrix.matrix = new double[count, count];
     94
     95          line = reader.ReadLine();
     96          m = reg.Matches(line);
     97
     98          int j = 0;
     99          while (m.Count == count) {
     100            for (int i = 0; i < count; i++) {
     101              distanceMatrix.matrix[i, j] = double.Parse(m[i].Value, System.Globalization.CultureInfo.InvariantCulture);             
     102            }
     103
     104            line = reader.ReadLine();
     105            m = reg.Matches(line);
     106            j++;
     107          }
     108
     109          if (j != count)
     110            throw new Exception("Invalid distance matrix definition");
    78111        }
    79112
Note: See TracChangeset for help on using the changeset viewer.