Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/01/12 15:15:22 (12 years ago)
Author:
abeham
Message:

#1614

  • Fixed plugin dependencies
  • Updated GQAP view
  • Changed instances infrastructure
    • Changed interface types into classes
    • Removed the library specific instance classes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.CordeauGQAP/3.3/CordeauGQAPParser.cs

    r7505 r7538  
    3434    public double[] Demands { get; private set; }
    3535    public double[] Capacities { get; private set; }
    36     public Exception Error { get; private set; }
    3736
    3837    public CordeauGQAPParser() {
     
    4847      Demands = null;
    4948      Capacities = null;
    50       Error = null;
    5149    }
    5250
    53     public bool Parse(string file) {
     51    public void Parse(string file) {
    5452      using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read)) {
    55         return Parse(stream);
     53        Parse(stream);
    5654      }
    5755    }
     
    6462    /// </remarks>
    6563    /// <param name="stream">The stream to read data from.</param>
    66     /// <returns>True if the file was successfully read or false otherwise.</returns>
    67     public bool Parse(Stream stream) {
    68       Error = null;
     64    public void Parse(Stream stream) {
    6965      var separator = new char[] { ' ', '\t' };
    70       try {
    71         StreamReader reader = new StreamReader(stream);
    72         string line = Continue(reader);
     66      var reader = new StreamReader(stream);
     67      string line = Continue(reader);
    7368
    74         var info = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
    75         Equipments = int.Parse(info[0]);
    76         Locations = int.Parse(info[1]);
    77         TransportationCosts = double.Parse(info[2]);
     69      var info = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
     70      Equipments = int.Parse(info[0]);
     71      Locations = int.Parse(info[1]);
     72      TransportationCosts = double.Parse(info[2]);
    7873
     74      line = Continue(reader);
     75
     76      Weights = new double[Equipments, Equipments];
     77      for (int i = 0; i < Equipments; i++) {
     78        var weightsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
     79        for (int j = 0; j < Equipments; j++) {
     80          Weights[i, j] = double.Parse(weightsPerEquipment[j], CultureInfo.InvariantCulture.NumberFormat);
     81        }
    7982        line = Continue(reader);
     83      }
    8084
    81         Weights = new double[Equipments, Equipments];
    82         for (int i = 0; i < Equipments; i++) {
    83           var weightsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
    84           for (int j = 0; j < Equipments; j++) {
    85             Weights[i, j] = double.Parse(weightsPerEquipment[j], CultureInfo.InvariantCulture.NumberFormat);
    86           }
    87           line = Continue(reader);
     85      Distances = new double[Locations, Locations];
     86      for (int i = 0; i < Locations; i++) {
     87        var distancePerLocation = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
     88        for (int j = 0; j < Locations; j++) {
     89          Distances[i, j] = double.Parse(distancePerLocation[j], CultureInfo.InvariantCulture.NumberFormat);
    8890        }
     91        line = Continue(reader);
     92      }
    8993
    90         Distances = new double[Locations, Locations];
    91         for (int i = 0; i < Locations; i++) {
    92           var distancePerLocation = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
    93           for (int j = 0; j < Locations; j++) {
    94             Distances[i, j] = double.Parse(distancePerLocation[j], CultureInfo.InvariantCulture.NumberFormat);
    95           }
    96           line = Continue(reader);
    97         }
     94      InstallationCosts = new double[Equipments, Locations];
     95      for (int i = 0; i < Equipments; i++) {
     96        var costsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
     97        for (int j = 0; j < Locations; j++)
     98          InstallationCosts[i, j] = double.Parse(costsPerEquipment[j], CultureInfo.InvariantCulture.NumberFormat);
     99        line = Continue(reader);
     100      }
    98101
    99         InstallationCosts = new double[Equipments, Locations];
    100         for (int i = 0; i < Equipments; i++) {
    101           var costsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
    102           for (int j = 0; j < Locations; j++)
    103             InstallationCosts[i, j] = double.Parse(costsPerEquipment[j], CultureInfo.InvariantCulture.NumberFormat);
    104           line = Continue(reader);
    105         }
     102      Demands = new double[Equipments];
     103      var demandsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
     104      for (int i = 0; i < Equipments; i++)
     105        Demands[i] = double.Parse(demandsPerEquipment[i], CultureInfo.InvariantCulture.NumberFormat);
    106106
    107         Demands = new double[Equipments];
    108         var demandsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
    109         for (int i = 0; i < Equipments; i++)
    110           Demands[i] = double.Parse(demandsPerEquipment[i], CultureInfo.InvariantCulture.NumberFormat);
     107      line = Continue(reader);
    111108
    112         line = Continue(reader);
    113 
    114         Capacities = new double[Locations];
    115         string[] capacityPerLocation = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
    116         for (int i = 0; i < Locations; i++)
    117           Capacities[i] = double.Parse(capacityPerLocation[i], CultureInfo.InvariantCulture.NumberFormat);
    118 
    119         return true;
    120       } catch (Exception e) {
    121         Error = e;
    122         return false;
    123       }
     109      Capacities = new double[Locations];
     110      string[] capacityPerLocation = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
     111      for (int i = 0; i < Locations; i++)
     112        Capacities[i] = double.Parse(capacityPerLocation[i], CultureInfo.InvariantCulture.NumberFormat);
    124113    }
    125114
Note: See TracChangeset for help on using the changeset viewer.