Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/13/17 12:55:06 (8 years ago)
Author:
abeham
Message:

#2701: Updated branch to trunk

Location:
branches/MemPRAlgorithm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/MemPRAlgorithm

  • branches/MemPRAlgorithm/HeuristicLab.Problems.Instances.Scheduling/3.3/JSSPORLIBInstanceProvider.cs

    r14185 r14562  
    6767          var parser = new JSSPORLIBParser();
    6868          parser.Parse(stream);
    69           var instance = Load(parser);
    70           instance.Name = id.Name;
    71           instance.Description = id.Description;
    72 
    73           return instance;
     69          return Load(parser);
    7470        }
    7571      }
     
    8278      var parser = new JSSPORLIBParser();
    8379      parser.Parse(path);
    84       var instance = Load(parser);
    85       instance.Name = Path.GetFileName(path);
    86       instance.Description = "Loaded from file \"" + path + "\" on " + DateTime.Now.ToString();
    87       return instance;
     80      return Load(parser);
    8881    }
    8982
    9083    private JSSPData Load(JSSPORLIBParser parser) {
    9184      var instance = new JSSPData {
     85        Name = parser.Name,
     86        Description = parser.Description,
    9287        Jobs = parser.Jobs,
    9388        Resources = parser.Resources,
  • branches/MemPRAlgorithm/HeuristicLab.Problems.Instances.Scheduling/3.3/JSSPORLIBParser.cs

    r14185 r14562  
    2424using System.IO;
    2525using System.Linq;
     26using System.Text;
    2627
    2728namespace HeuristicLab.Problems.Instances.Scheduling {
     
    5354
    5455    public void Export(string file) {
    55       using (Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read)) {
     56      using (Stream stream = new FileStream(file, FileMode.Create, FileAccess.ReadWrite)) {
    5657        Export(stream);
    5758      }
     
    6566    /// </remarks>
    6667    /// <param name="stream">The stream to read data from.</param>
    67     /// <returns>True if the file was successfully read or false otherwise.</returns>
    6868    public void Parse(Stream stream) {
    69       var reader = new StreamReader(stream);
    70       Name = reader.ReadLine().Trim();
    71       Description = reader.ReadLine().Trim();
    72       var delim = new char[] { ' ', '\t' };
     69      using (var reader = new StreamReader(stream, Encoding.UTF8, true, 4092, true)) {
     70        Name = reader.ReadLine().Trim();
     71        Description = reader.ReadLine().Trim();
     72        var delim = new char[] {' ', '\t'};
    7373
    74       var info = reader.ReadLine().Split(delim, StringSplitOptions.RemoveEmptyEntries);
    75       Jobs = int.Parse(info[0]);
    76       Resources = int.Parse(info[1]);
    77       ProcessingTimes = new double[Jobs, Resources];
    78       Demands = new int[Jobs, Resources];
     74        var info = reader.ReadLine().Split(delim, StringSplitOptions.RemoveEmptyEntries);
     75        Jobs = int.Parse(info[0]);
     76        Resources = int.Parse(info[1]);
     77        ProcessingTimes = new double[Jobs, Resources];
     78        Demands = new int[Jobs, Resources];
    7979
    80       for (int k = 0; k < Jobs; k++) {
    81         if (reader.EndOfStream) throw new InvalidDataException("Unexpected End of Stream.");
    82         var valLine = reader.ReadLine();
    83         while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine();
    84         var vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries);
    85         if (vals.Length > 2 * Resources) {
    86           if (DueDates == null) DueDates = new double[Jobs];
    87           DueDates[k] = double.Parse(vals.Last(), CultureInfo.InvariantCulture.NumberFormat);
    88         }
     80        for (int k = 0; k < Jobs; k++) {
     81          if (reader.EndOfStream) throw new InvalidDataException("Unexpected End of Stream.");
     82          var valLine = reader.ReadLine();
     83          while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine();
     84          var vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries);
     85          if (vals.Length > 2 * Resources) {
     86            if (DueDates == null) DueDates = new double[Jobs];
     87            DueDates[k] = double.Parse(vals.Last(), CultureInfo.InvariantCulture.NumberFormat);
     88          }
    8989
    90         for (int i = 0; i < Resources; i++) {
    91           Demands[k, i] = int.Parse(vals[2 * i]);
    92           ProcessingTimes[k, i] = double.Parse(vals[2 * i + 1], CultureInfo.InvariantCulture.NumberFormat);
     90          for (int i = 0; i < Resources; i++) {
     91            Demands[k, i] = int.Parse(vals[2 * i]);
     92            ProcessingTimes[k, i] = double.Parse(vals[2 * i + 1], CultureInfo.InvariantCulture.NumberFormat);
     93          }
    9394        }
    9495      }
    95 
    9696    }
    9797
     98    /// <summary>
     99    /// Writes to the given stream data which is expected to be in the JSSP ORLIB format.
     100    /// </summary>
     101    /// <remarks>
     102    /// The stream is not closed or disposed. The caller has to take care of that.
     103    /// </remarks>
     104    /// <param name="stream">The stream to write data to.</param>
    98105    public void Export(Stream stream) {
    99       var writer = new StreamWriter(stream);
    100       writer.WriteLine(Name);
    101       writer.WriteLine(Description);
    102       writer.WriteLine(Jobs.ToString(CultureInfo.InvariantCulture.NumberFormat) + " " + Resources.ToString(CultureInfo.InvariantCulture.NumberFormat));
    103       for (int i = 0; i < Jobs; i++) {
    104         for (int j = 0; j < Resources; j++) {
    105           writer.Write(Demands[i, j] + " " + ProcessingTimes[i, j] + " ");
     106      using (var writer = new StreamWriter(stream, Encoding.UTF8, 4092, true)) {
     107        writer.WriteLine(Name);
     108        writer.WriteLine(Description);
     109        writer.WriteLine(Jobs.ToString(CultureInfo.InvariantCulture.NumberFormat) + " " + Resources.ToString(CultureInfo.InvariantCulture.NumberFormat));
     110        for (int i = 0; i < Jobs; i++) {
     111          for (int j = 0; j < Resources; j++) {
     112            writer.Write(Demands[i, j] + " " + ProcessingTimes[i, j] + " ");
     113          }
     114          if (DueDates != null) writer.Write(DueDates[i].ToString("r", CultureInfo.InvariantCulture.NumberFormat));
     115          writer.WriteLine();
    106116        }
    107         if (DueDates != null) writer.Write(DueDates[i].ToString(CultureInfo.InvariantCulture.NumberFormat));
    108         writer.WriteLine();
     117        writer.Flush();
    109118      }
    110       writer.Flush();
    111119    }
    112120
Note: See TracChangeset for help on using the changeset viewer.