[4315] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using System.IO;
|
---|
[4317] | 27 | using System.Globalization;
|
---|
[4315] | 28 |
|
---|
| 29 | namespace HeuristicLab.Problems.VehicleRouting {
|
---|
| 30 | class ORLIBParser {
|
---|
| 31 | private StreamReader source;
|
---|
[4317] | 32 | CultureInfo culture = new CultureInfo("en-US");
|
---|
[4315] | 33 |
|
---|
| 34 | private string name;
|
---|
| 35 | public string Name {
|
---|
| 36 | get {
|
---|
| 37 | return name;
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | private double[,] vertices;
|
---|
| 42 | public double[,] Vertices {
|
---|
| 43 | get {
|
---|
| 44 | return vertices;
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | private double capacity;
|
---|
| 49 | public double Capacity {
|
---|
| 50 | get {
|
---|
| 51 | return capacity;
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | private double maxRouteTime;
|
---|
| 56 | public double MaxRouteTime {
|
---|
| 57 | get {
|
---|
| 58 | return maxRouteTime;
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | private double serviceTime;
|
---|
| 63 | public double ServiceTime {
|
---|
| 64 | get {
|
---|
| 65 | return serviceTime;
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | private double[] demands;
|
---|
| 70 | public double[] Demands {
|
---|
| 71 | get {
|
---|
| 72 | return demands;
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | public ORLIBParser(String path) {
|
---|
| 77 | source = null;
|
---|
| 78 |
|
---|
| 79 | name = path;
|
---|
| 80 | vertices = null;
|
---|
| 81 | capacity = -1;
|
---|
| 82 | maxRouteTime = -1;
|
---|
| 83 | serviceTime = -1;
|
---|
| 84 | demands = null;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | public void Parse() {
|
---|
| 88 | using (source = new StreamReader(name)) {
|
---|
| 89 | //Read header
|
---|
| 90 | string line = source.ReadLine();
|
---|
| 91 | string[] tokens = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
|
---|
| 92 |
|
---|
| 93 | int customers = int.Parse(tokens[0]);
|
---|
| 94 | demands = new double[customers + 1];
|
---|
| 95 | demands[0] = 0;
|
---|
| 96 | vertices = new double[customers + 1, 2];
|
---|
| 97 |
|
---|
| 98 | capacity = int.Parse(tokens[1]);
|
---|
| 99 | maxRouteTime = int.Parse(tokens[2]);
|
---|
| 100 | serviceTime = int.Parse(tokens[3]);
|
---|
| 101 |
|
---|
| 102 | //Read depot
|
---|
| 103 | line = source.ReadLine();
|
---|
| 104 | tokens = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
|
---|
[4317] | 105 | vertices[0, 0] = double.Parse(tokens[0], culture.NumberFormat);
|
---|
| 106 | vertices[0, 1] = double.Parse(tokens[1], culture.NumberFormat);
|
---|
[4315] | 107 |
|
---|
| 108 | for (int i = 0; i < customers; i++) {
|
---|
| 109 | line = source.ReadLine();
|
---|
| 110 | tokens = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
|
---|
[4317] | 111 | vertices[i + 1, 0] = double.Parse(tokens[0], culture.NumberFormat);
|
---|
| 112 | vertices[i + 1, 1] = double.Parse(tokens[1], culture.NumberFormat);
|
---|
| 113 | demands[i + 1] = double.Parse(tokens[2], culture.NumberFormat);
|
---|
[4315] | 114 | }
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | source = null;
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | }
|
---|