Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2747_CFSAP/HeuristicLab.Problems.Instances.CFSAP/3.3/BozejkoCFSAPParser.cs @ 17945

Last change on this file since 17945 was 15460, checked in by abeham, 7 years ago

#2747: worked on the CFSAP

  • Added problem definition that defines both sequence and assignment for a single nest
  • Added problem definition that would optimizes both sequence and assignment for multiple nests
  • Added interface
  • Added solving strategy that would use multiple instances of a template algorithm to optimize the worst nest
  • Fixed bug in parser regarding setup times
File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.IO;
25using System.Linq;
26using System.Text;
27
28namespace HeuristicLab.Problems.Instances.CFSAP {
29  public class BozejkoCFSAPParser {
30    public int Jobs { get; private set; }
31    public int[] Machines { get; private set; }
32    public int Nests { get; private set; }
33    public List<int[][]> ProcessingTimes { get; private set; }
34    public List<int[][][]> SetupTimes { get; private set; }
35
36    public void Parse(Stream stream) {
37      using (var reader = new StreamReader(stream)) {
38        Nests = GetNextInteger(reader);
39        Jobs = GetNextInteger(reader);
40        Machines = Enumerable.Range(0, Nests).Select(x => GetNextInteger(reader)).ToArray();
41        ProcessingTimes = new List<int[][]>(Nests);
42        SetupTimes = new List<int[][][]>(Nests);
43
44        for (var n = 0; n < Nests; n++) {
45          var machines = Machines[n];
46          var pr = new int[machines][];
47          for (var m = 0; m < machines; m++) {
48            pr[m] = new int[Jobs];
49            for (var j = 0; j < Jobs; j++) {
50              pr[m][j] = GetNextInteger(reader);
51            }
52          }
53          ProcessingTimes.Add(pr);
54        }
55        for (var n = 0; n < Nests; n++) {
56          var machines = Machines[n];
57          var sp = new int[machines][][];
58          for (var m = 0; m < machines; m++) {
59            sp[m] = new int[Jobs][];
60            for (var j = 0; j < Jobs; j++) {
61              sp[m][j] = new int[Jobs];
62              for (var i = 0; i < Jobs; i++) {
63                sp[m][j][i] = GetNextInteger(reader);
64              }
65            }
66          }
67          SetupTimes.Add(sp);
68        }
69        reader.Close();
70        stream.Close();
71      }
72    }
73
74    private int GetNextInteger(StreamReader reader) {
75      var builder = new StringBuilder();
76      int r = reader.Read();
77      while (r >= 0) {
78        var c = (char)r;
79        if ((c == ' ' || c == '\t' || c == '\r' || c == '\n') && builder.Length > 0)
80          return int.Parse(builder.ToString());
81        if (c == 'N' || c == 'M') {
82          // consume the whole line
83          reader.ReadLine();
84          r = reader.Read();
85          continue;
86        }
87        if (char.IsNumber(c)) builder.Append(c);
88        r = reader.Read();
89        if (r == -1 && builder.Length > 0) return int.Parse(builder.ToString());
90      }
91      throw new InvalidOperationException("Stream does not contain more numbers");
92    }
93  }
94}
Note: See TracBrowser for help on using the repository browser.