Changeset 7538 for branches/GeneralizedQAP/HeuristicLab.Problems.Instances.CordeauGQAP/3.3/CordeauGQAPParser.cs
- Timestamp:
- 03/01/12 15:15:22 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.CordeauGQAP/3.3/CordeauGQAPParser.cs
r7505 r7538 34 34 public double[] Demands { get; private set; } 35 35 public double[] Capacities { get; private set; } 36 public Exception Error { get; private set; }37 36 38 37 public CordeauGQAPParser() { … … 48 47 Demands = null; 49 48 Capacities = null; 50 Error = null;51 49 } 52 50 53 public boolParse(string file) {51 public void Parse(string file) { 54 52 using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read)) { 55 returnParse(stream);53 Parse(stream); 56 54 } 57 55 } … … 64 62 /// </remarks> 65 63 /// <param name="stream">The stream to read data from.</param> 66 /// <returns>True if the file was successfully read or false otherwise.</returns> 67 public bool Parse(Stream stream) { 68 Error = null; 64 public void Parse(Stream stream) { 69 65 var separator = new char[] { ' ', '\t' }; 70 try { 71 StreamReader reader = new StreamReader(stream); 72 string line = Continue(reader); 66 var reader = new StreamReader(stream); 67 string line = Continue(reader); 73 68 74 75 76 77 69 var info = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 70 Equipments = int.Parse(info[0]); 71 Locations = int.Parse(info[1]); 72 TransportationCosts = double.Parse(info[2]); 78 73 74 line = Continue(reader); 75 76 Weights = new double[Equipments, Equipments]; 77 for (int i = 0; i < Equipments; i++) { 78 var weightsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 79 for (int j = 0; j < Equipments; j++) { 80 Weights[i, j] = double.Parse(weightsPerEquipment[j], CultureInfo.InvariantCulture.NumberFormat); 81 } 79 82 line = Continue(reader); 83 } 80 84 81 Weights = new double[Equipments, Equipments]; 82 for (int i = 0; i < Equipments; i++) { 83 var weightsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 84 for (int j = 0; j < Equipments; j++) { 85 Weights[i, j] = double.Parse(weightsPerEquipment[j], CultureInfo.InvariantCulture.NumberFormat); 86 } 87 line = Continue(reader); 85 Distances = new double[Locations, Locations]; 86 for (int i = 0; i < Locations; i++) { 87 var distancePerLocation = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 88 for (int j = 0; j < Locations; j++) { 89 Distances[i, j] = double.Parse(distancePerLocation[j], CultureInfo.InvariantCulture.NumberFormat); 88 90 } 91 line = Continue(reader); 92 } 89 93 90 Distances = new double[Locations, Locations]; 91 for (int i = 0; i < Locations; i++) { 92 var distancePerLocation = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 93 for (int j = 0; j < Locations; j++) { 94 Distances[i, j] = double.Parse(distancePerLocation[j], CultureInfo.InvariantCulture.NumberFormat); 95 } 96 line = Continue(reader); 97 } 94 InstallationCosts = new double[Equipments, Locations]; 95 for (int i = 0; i < Equipments; i++) { 96 var costsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 97 for (int j = 0; j < Locations; j++) 98 InstallationCosts[i, j] = double.Parse(costsPerEquipment[j], CultureInfo.InvariantCulture.NumberFormat); 99 line = Continue(reader); 100 } 98 101 99 InstallationCosts = new double[Equipments, Locations]; 100 for (int i = 0; i < Equipments; i++) { 101 var costsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 102 for (int j = 0; j < Locations; j++) 103 InstallationCosts[i, j] = double.Parse(costsPerEquipment[j], CultureInfo.InvariantCulture.NumberFormat); 104 line = Continue(reader); 105 } 102 Demands = new double[Equipments]; 103 var demandsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 104 for (int i = 0; i < Equipments; i++) 105 Demands[i] = double.Parse(demandsPerEquipment[i], CultureInfo.InvariantCulture.NumberFormat); 106 106 107 Demands = new double[Equipments]; 108 var demandsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 109 for (int i = 0; i < Equipments; i++) 110 Demands[i] = double.Parse(demandsPerEquipment[i], CultureInfo.InvariantCulture.NumberFormat); 107 line = Continue(reader); 111 108 112 line = Continue(reader); 113 114 Capacities = new double[Locations]; 115 string[] capacityPerLocation = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 116 for (int i = 0; i < Locations; i++) 117 Capacities[i] = double.Parse(capacityPerLocation[i], CultureInfo.InvariantCulture.NumberFormat); 118 119 return true; 120 } catch (Exception e) { 121 Error = e; 122 return false; 123 } 109 Capacities = new double[Locations]; 110 string[] capacityPerLocation = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 111 for (int i = 0; i < Locations; i++) 112 Capacities[i] = double.Parse(capacityPerLocation[i], CultureInfo.InvariantCulture.NumberFormat); 124 113 } 125 114
Note: See TracChangeset
for help on using the changeset viewer.