Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Scheduling.JSSP/JSSPParser.cs @ 106

Last change on this file since 106 was 2, checked in by swagner, 17 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.Text;
25using System.IO;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28
29namespace HeuristicLab.Scheduling.JSSP {
30  public class JSSPParser {
31    private StreamReader source;
32    private int nrOfJobs;
33    public int NrOfJobs {
34      get { return nrOfJobs; }
35    }
36
37    private int nrOfMachines;
38    public int NrOfMachines {
39      get { return nrOfMachines; }
40    }
41
42    private int[,] machineSequence; // each row: machine sequence per job
43    public int[,] MachineSequence {
44      get { return machineSequence; }
45    }
46
47    private int[,] processingTime;  // each row: processing time per job and machine
48    public int[,] ProcessingTime {
49      get { return processingTime; }
50    }
51
52    private ItemList operations;
53    public ItemList Operations {
54      get { return operations; }
55    }
56
57    public JSSPParser(String path) {
58      if(!path.EndsWith(".jssp"))
59        throw new ArgumentException("Input file name has to be in JSSP format (*.jssp)");
60      source = new StreamReader(path);
61    }
62
63    private ItemList getOperations() {
64      ItemList ops = new ItemList();
65      for(int i = 0; i < NrOfJobs; i++) {
66        for(int j = 0; j < NrOfMachines; j++) {
67          List<int> opMachines = new List<int>();
68          opMachines.Add(MachineSequence[i, j]);
69          List<int> opPredecessors = new List<int>();
70          if(j > 0) {
71            opPredecessors.Add(j - 1);
72          }
73          Operation op = new Operation(i, 0, ProcessingTime[i, MachineSequence[i, j]], j, opMachines.ToArray(), opPredecessors.ToArray());
74          ops.Add(op);
75        }
76      }
77      return ops;
78    }
79
80    // File structure of *.jssp files:
81    // #jobs #machines
82    // one line for each job; start count from zero
83    // machineNumber processingTime machineNumber processingTime ....
84    public void Parse() {
85      string str = source.ReadLine();
86      string[] tokens = str.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
87      if(tokens.Length != 2)
88        throw new InvalidDataException("Invalid problem specification!");
89      nrOfJobs = Int32.Parse(tokens[0]);
90      nrOfMachines = Int32.Parse(tokens[1]);
91      // Console.WriteLine("nrOfMachines: {0}, nrOfJobs: {1}", nrOfMachines, nrOfJobs);
92      machineSequence = new int[nrOfJobs, nrOfMachines];
93      processingTime = new int[nrOfJobs, nrOfMachines];
94      for(int i = 0; i < nrOfJobs; i++) {
95        str = source.ReadLine();
96        tokens = str.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
97        for(int j = 0; j < nrOfMachines; j++) {
98          machineSequence[i, j] = Int32.Parse(tokens[2 * j]);
99          processingTime[i, machineSequence[i, j]] = Int32.Parse(tokens[2 * j + 1]);
100        }
101      }
102      operations = getOperations();
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.