[15661] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16003] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[15661] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Globalization;
|
---|
| 24 | using System.IO;
|
---|
| 25 | using System.Linq;
|
---|
| 26 | using System.Text;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Problems.Instances.PermutationProblems.PFSP {
|
---|
| 29 | public class FSSPTAILIBParser {
|
---|
| 30 | public string Name { get; set; }
|
---|
| 31 | public string Description { get; set; }
|
---|
| 32 | public int Jobs { get; set; }
|
---|
| 33 | public int Machines { get; set; }
|
---|
| 34 | public double[,] ProcessingTimes { get; set; }
|
---|
| 35 |
|
---|
| 36 | public int[] BestKnownSchedule { get; set; }
|
---|
| 37 | public int BestKnownQuality { get; set; }
|
---|
| 38 |
|
---|
| 39 | public FSSPTAILIBParser() {
|
---|
| 40 | Reset();
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | public void Reset() {
|
---|
| 44 | Name = Description = String.Empty;
|
---|
| 45 | Jobs = Machines = BestKnownQuality = 0;
|
---|
| 46 | ProcessingTimes = null;
|
---|
| 47 | BestKnownSchedule = null;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | public void Parse(string file) {
|
---|
| 51 | using (Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read)) {
|
---|
| 52 | Parse(stream);
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public void Export(string file) {
|
---|
| 57 | using (Stream stream = new FileStream(file, FileMode.Create, FileAccess.Write)) {
|
---|
| 58 | Export(stream);
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | public void Parse(Stream stream) {
|
---|
| 63 | using (var reader = new StreamReader(stream, Encoding.UTF8, true, 4092, true)) {
|
---|
| 64 | Name = reader.ReadLine().Trim();
|
---|
| 65 | Description = reader.ReadLine().Trim();
|
---|
| 66 | var delim = new char[] { ' ', '\t' };
|
---|
| 67 |
|
---|
| 68 | var info = reader.ReadLine().Split(delim, StringSplitOptions.RemoveEmptyEntries);
|
---|
| 69 | Jobs = int.Parse(info[0]);
|
---|
| 70 | Machines = int.Parse(info[1]);
|
---|
| 71 | var bestKnownQuality = reader.ReadLine().Trim();
|
---|
| 72 | BestKnownQuality = int.Parse(bestKnownQuality);
|
---|
| 73 | ProcessingTimes = new double[Machines, Jobs];
|
---|
| 74 |
|
---|
| 75 | for (int k = 0; k < Machines; k++) {
|
---|
| 76 | if (reader.EndOfStream) throw new InvalidDataException("Unexpected End of Stream.");
|
---|
| 77 | var valLine = reader.ReadLine();
|
---|
| 78 | while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine();
|
---|
| 79 | var vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries);
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | for (int i = 0; i < Jobs; i++) {
|
---|
| 83 | ProcessingTimes[k, i] = double.Parse(vals[i], CultureInfo.InvariantCulture.NumberFormat);
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | while (!reader.EndOfStream) {
|
---|
| 88 | var vals = reader.ReadLine().Split(delim, StringSplitOptions.RemoveEmptyEntries);
|
---|
| 89 | if (vals.Count() == Jobs) { BestKnownSchedule = vals.Select(val => Int32.Parse(val)).ToArray(); }
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | public void Export(Stream stream) {
|
---|
| 95 | using (var writer = new StreamWriter(stream, Encoding.UTF8, 4092, true)) {
|
---|
| 96 | writer.WriteLine(Name);
|
---|
| 97 | writer.WriteLine(Description);
|
---|
| 98 | writer.WriteLine(Jobs + '\t' + Machines);
|
---|
| 99 | writer.WriteLine(BestKnownQuality);
|
---|
| 100 |
|
---|
| 101 | for (int k = 0; k < Machines; k++) {
|
---|
| 102 | for (int i = 0; i < Jobs; i++) {
|
---|
| 103 | writer.Write(ProcessingTimes[k, i] + "\t");
|
---|
| 104 | }
|
---|
| 105 | writer.WriteLine();
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | if (BestKnownSchedule != null) {
|
---|
| 109 | writer.WriteLine(BestKnownSchedule);
|
---|
| 110 | }
|
---|
| 111 | writer.Flush();
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | }
|
---|