Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/19/12 13:17:29 (12 years ago)
Author:
ascheibe
Message:

#1722 fixed more licensing information and source formatting

Location:
trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/CordeauFormat/CordeauParser.cs

    r7891 r8053  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    118118    }
    119119
    120      public CordeauParser(string file): this() {
     120    public CordeauParser(string file)
     121      : this() {
    121122      this.file = file;
    122123    }
    123124
    124      public CordeauParser(Stream stream)
    125        : this() {
     125    public CordeauParser(Stream stream)
     126      : this() {
    126127      this.stream = stream;
    127128    }
    128129
    129      public void Parse() {
    130        string line;
    131        Regex reg = new Regex(@"-?\d+(\.\d+)?");
    132        MatchCollection m;
    133 
    134        StreamReader reader;
    135        if (stream != null) {
    136          reader = new StreamReader(stream);
    137        } else {
    138          reader = new StreamReader(file);
    139          problemName = Path.GetFileNameWithoutExtension(file);
    140        }
    141 
    142        using (reader) {
    143          List<double> depotXcoord = new List<double>();
    144          List<double> depotYcoord = new List<double>();
    145          List<double> depotReadyTime = new List<double>();
    146          List<double> depotDueTime = new List<double>();
    147          
    148          List<double> routeDueTime = new List<double>();
    149 
    150          line = reader.ReadLine();
    151 
    152          m = reg.Matches(line);
    153          if (m.Count != 4)
    154            throw new InvalidDataException("File has wrong format!");
    155 
    156          int type = int.Parse(m[0].Value);
    157          if(type != 2 && type != 6)
    158            throw new InvalidDataException("Unsupported instance type");
    159 
    160          bool timeWindows = type == 6;
    161          vehicles = int.Parse(m[1].Value);
    162          cities = int.Parse(m[2].Value);
    163          depots = int.Parse(m[3].Value);
    164          line = reader.ReadLine();
    165 
    166          for (int i = 0; i < depots; i++) {
    167            m = reg.Matches(line);
    168            if (m.Count != 2) { continue; }
    169 
    170            routeDueTime.Add(double.Parse(m[0].Value, System.Globalization.CultureInfo.InvariantCulture));
    171            capacity.Add(double.Parse(m[1].Value, System.Globalization.CultureInfo.InvariantCulture));
    172 
    173            line = reader.ReadLine();
    174          }
    175 
    176          while ((line != null)) {
    177            m = reg.Matches(line);
    178 
    179            if (demand.Count < cities) {
    180              xCoord.Add(double.Parse(m[1].Value, System.Globalization.CultureInfo.InvariantCulture));
    181              yCoord.Add(double.Parse(m[2].Value, System.Globalization.CultureInfo.InvariantCulture));
    182              demand.Add((double)int.Parse(m[4].Value, System.Globalization.CultureInfo.InvariantCulture));
    183              serviceTime.Add(int.Parse(m[3].Value));
    184 
    185              if (timeWindows) {
    186                readyTime.Add(int.Parse(m[m.Count - 2].Value));
    187                dueTime.Add(int.Parse(m[m.Count - 1].Value));
    188              } else {
    189                readyTime.Add(0);
    190                dueTime.Add(double.MaxValue);
    191              }
    192            } else {
    193              depotXcoord.Add(double.Parse(m[1].Value, System.Globalization.CultureInfo.InvariantCulture));
    194              depotYcoord.Add(double.Parse(m[2].Value, System.Globalization.CultureInfo.InvariantCulture));
    195 
    196              if (timeWindows) {
    197                depotReadyTime.Add(int.Parse(m[m.Count - 2].Value));
    198                depotDueTime.Add(int.Parse(m[m.Count - 1].Value));
    199              } else {
    200                depotReadyTime.Add(0);
    201                depotDueTime.Add(double.MaxValue);
    202              }
    203            }
    204 
    205            line = reader.ReadLine();
    206          }
    207 
    208          for (int i = 0; i < depotDueTime.Count; i++) {
    209            if (!timeWindows) {
    210              depotDueTime[i] = routeDueTime[i];
    211            }
    212            if (depotDueTime[i] < double.Epsilon)
    213              depotDueTime[i] = double.MaxValue;
    214          }
    215 
    216          xCoord.InsertRange(0, depotXcoord);
    217          yCoord.InsertRange(0, depotYcoord);
    218          readyTime.InsertRange(0, depotReadyTime);
    219          dueTime.InsertRange(0, depotDueTime);
    220 
    221          List<double> originalCapacities = new List<double>(capacity);
    222          capacity.Clear();
    223          for (int i = 0; i < depots; i++) {
    224            for (int j = 0; j < vehicles; j++) {
    225              capacity.Add(originalCapacities[i]);
    226            }
    227          }
    228          vehicles *= depots;
    229        }
    230      }
     130    public void Parse() {
     131      string line;
     132      Regex reg = new Regex(@"-?\d+(\.\d+)?");
     133      MatchCollection m;
     134
     135      StreamReader reader;
     136      if (stream != null) {
     137        reader = new StreamReader(stream);
     138      } else {
     139        reader = new StreamReader(file);
     140        problemName = Path.GetFileNameWithoutExtension(file);
     141      }
     142
     143      using (reader) {
     144        List<double> depotXcoord = new List<double>();
     145        List<double> depotYcoord = new List<double>();
     146        List<double> depotReadyTime = new List<double>();
     147        List<double> depotDueTime = new List<double>();
     148
     149        List<double> routeDueTime = new List<double>();
     150
     151        line = reader.ReadLine();
     152
     153        m = reg.Matches(line);
     154        if (m.Count != 4)
     155          throw new InvalidDataException("File has wrong format!");
     156
     157        int type = int.Parse(m[0].Value);
     158        if (type != 2 && type != 6)
     159          throw new InvalidDataException("Unsupported instance type");
     160
     161        bool timeWindows = type == 6;
     162        vehicles = int.Parse(m[1].Value);
     163        cities = int.Parse(m[2].Value);
     164        depots = int.Parse(m[3].Value);
     165        line = reader.ReadLine();
     166
     167        for (int i = 0; i < depots; i++) {
     168          m = reg.Matches(line);
     169          if (m.Count != 2) { continue; }
     170
     171          routeDueTime.Add(double.Parse(m[0].Value, System.Globalization.CultureInfo.InvariantCulture));
     172          capacity.Add(double.Parse(m[1].Value, System.Globalization.CultureInfo.InvariantCulture));
     173
     174          line = reader.ReadLine();
     175        }
     176
     177        while ((line != null)) {
     178          m = reg.Matches(line);
     179
     180          if (demand.Count < cities) {
     181            xCoord.Add(double.Parse(m[1].Value, System.Globalization.CultureInfo.InvariantCulture));
     182            yCoord.Add(double.Parse(m[2].Value, System.Globalization.CultureInfo.InvariantCulture));
     183            demand.Add((double)int.Parse(m[4].Value, System.Globalization.CultureInfo.InvariantCulture));
     184            serviceTime.Add(int.Parse(m[3].Value));
     185
     186            if (timeWindows) {
     187              readyTime.Add(int.Parse(m[m.Count - 2].Value));
     188              dueTime.Add(int.Parse(m[m.Count - 1].Value));
     189            } else {
     190              readyTime.Add(0);
     191              dueTime.Add(double.MaxValue);
     192            }
     193          } else {
     194            depotXcoord.Add(double.Parse(m[1].Value, System.Globalization.CultureInfo.InvariantCulture));
     195            depotYcoord.Add(double.Parse(m[2].Value, System.Globalization.CultureInfo.InvariantCulture));
     196
     197            if (timeWindows) {
     198              depotReadyTime.Add(int.Parse(m[m.Count - 2].Value));
     199              depotDueTime.Add(int.Parse(m[m.Count - 1].Value));
     200            } else {
     201              depotReadyTime.Add(0);
     202              depotDueTime.Add(double.MaxValue);
     203            }
     204          }
     205
     206          line = reader.ReadLine();
     207        }
     208
     209        for (int i = 0; i < depotDueTime.Count; i++) {
     210          if (!timeWindows) {
     211            depotDueTime[i] = routeDueTime[i];
     212          }
     213          if (depotDueTime[i] < double.Epsilon)
     214            depotDueTime[i] = double.MaxValue;
     215        }
     216
     217        xCoord.InsertRange(0, depotXcoord);
     218        yCoord.InsertRange(0, depotYcoord);
     219        readyTime.InsertRange(0, depotReadyTime);
     220        dueTime.InsertRange(0, depotDueTime);
     221
     222        List<double> originalCapacities = new List<double>(capacity);
     223        capacity.Clear();
     224        for (int i = 0; i < depots; i++) {
     225          for (int j = 0; j < vehicles; j++) {
     226            capacity.Add(originalCapacities[i]);
     227          }
     228        }
     229        vehicles *= depots;
     230      }
     231    }
    231232  }
    232233}
  • trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/GoldenFormat/GoldenParser.cs

    r7887 r8053  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Globalization;
    2423using System.IO;
    2524
     
    2928    private Stream stream;
    3029    private string problemName;
    31    
     30
    3231    #region Inner Enum TSPLIBEdgeWeightType
    3332    public enum GoldenEdgeWeightType {
     
    125124    }
    126125
    127     public GoldenParser(string file): this() {
     126    public GoldenParser(string file)
     127      : this() {
    128128      this.file = file;
    129129    }
    130130
    131131    public GoldenParser(Stream stream)
    132        : this() {
     132      : this() {
    133133      this.stream = stream;
    134134    }
  • trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/LiLimFormat/LiLimParser.cs

    r7882 r8053  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    118118    }
    119119
    120      public LiLimParser(string file): this() {
     120    public LiLimParser(string file)
     121      : this() {
    121122      this.file = file;
    122123    }
    123124
    124      public LiLimParser(Stream stream): this() {
     125    public LiLimParser(Stream stream)
     126      : this() {
    125127      this.stream = stream;
    126128    }
    127129
    128      public void Parse() {
    129        string line;
    130        Regex reg = new Regex(@"-?\d+");
    131        MatchCollection m;
     130    public void Parse() {
     131      string line;
     132      Regex reg = new Regex(@"-?\d+");
     133      MatchCollection m;
    132134
    133        StreamReader reader;
    134        if (stream != null) {
    135          reader = new StreamReader(stream);   
    136        }
    137        else {
    138          reader = new StreamReader(file);
    139          problemName = Path.GetFileNameWithoutExtension(file);
    140        }
     135      StreamReader reader;
     136      if (stream != null) {
     137        reader = new StreamReader(stream);
     138      } else {
     139        reader = new StreamReader(file);
     140        problemName = Path.GetFileNameWithoutExtension(file);
     141      }
    141142
    142        using (reader) {
    143          line = reader.ReadLine();
     143      using (reader) {
     144        line = reader.ReadLine();
    144145
    145          m = reg.Matches(line);
    146          if (m.Count != 3)
    147            throw new InvalidDataException("File has wrong format!");
     146        m = reg.Matches(line);
     147        if (m.Count != 3)
     148          throw new InvalidDataException("File has wrong format!");
    148149
    149          vehicles = int.Parse(m[0].Value);
    150          capacity = double.Parse(m[1].Value);
     150        vehicles = int.Parse(m[0].Value);
     151        capacity = double.Parse(m[1].Value);
    151152
    152          line = reader.ReadLine();
    153          while ((line != null) && (line.Length > 5)) {
    154            m = reg.Matches(line);
    155            if (m.Count != 9) { continue; }
    156            xCoord.Add((double)int.Parse(m[1].Value));
    157            yCoord.Add((double)int.Parse(m[2].Value));
    158            demand.Add((double)int.Parse(m[3].Value));
    159            readyTime.Add((double)int.Parse(m[4].Value));
    160            double st = (double)int.Parse(m[6].Value);
    161            dueTime.Add((double)int.Parse(m[5].Value));
    162            serviceTime.Add(st);
     153        line = reader.ReadLine();
     154        while ((line != null) && (line.Length > 5)) {
     155          m = reg.Matches(line);
     156          if (m.Count != 9) { continue; }
     157          xCoord.Add((double)int.Parse(m[1].Value));
     158          yCoord.Add((double)int.Parse(m[2].Value));
     159          demand.Add((double)int.Parse(m[3].Value));
     160          readyTime.Add((double)int.Parse(m[4].Value));
     161          double st = (double)int.Parse(m[6].Value);
     162          dueTime.Add((double)int.Parse(m[5].Value));
     163          serviceTime.Add(st);
    163164
    164            int location = int.Parse(m[7].Value);
    165            if (location == 0)
    166              location = int.Parse(m[8].Value);
    167            pickipDeliveryLocation.Add(location);
     165          int location = int.Parse(m[7].Value);
     166          if (location == 0)
     167            location = int.Parse(m[8].Value);
     168          pickipDeliveryLocation.Add(location);
    168169
    169            line = reader.ReadLine();
    170          }
    171          cities = serviceTime.Count;
    172        }
    173      }
     170          line = reader.ReadLine();
     171        }
     172        cities = serviceTime.Count;
     173      }
     174    }
    174175  }
    175176}
  • trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/SolomonFormat/SolomonParser.cs

    r7882 r8053  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    110110    }
    111111
    112     public SolomonParser(string file): this() {
     112    public SolomonParser(string file)
     113      : this() {
    113114      this.file = file;
    114115    }
    115116
    116     public SolomonParser(Stream stream): this() {
     117    public SolomonParser(Stream stream)
     118      : this() {
    117119      this.stream = stream;
    118120    }
  • trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/TaillardFormat/TaillardParser.cs

    r7888 r8053  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    7979    }
    8080
    81     public TaillardParser(string file): this() {
     81    public TaillardParser(string file)
     82      : this() {
    8283      this.file = file;
    8384    }
Note: See TracChangeset for help on using the changeset viewer.