# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1238014516 -3600
# Node ID 780ce5fdf189edce2e8b78454ddfd003a88cceb3
# Parent 6a17a722b50e1b22187f5a4cb99a7de28aada418
Accept negative values as unbounded capacity in dimacs readers (#243)
diff --git a/lemon/dimacs.h b/lemon/dimacs.h
a
|
b
|
|
142 | 142 | typename CapacityMap::Value low; |
143 | 143 | typename CapacityMap::Value cap; |
144 | 144 | typename CostMap::Value co; |
| 145 | typedef typename CapacityMap::Value Capacity; |
| 146 | Capacity MAX = std::numeric_limits<Capacity>::has_infinity ? |
| 147 | std::numeric_limits<Capacity>::infinity() : |
| 148 | std::numeric_limits<Capacity>::max(); |
| 149 | |
145 | 150 | while (is >> c) { |
146 | 151 | switch (c) { |
147 | 152 | case 'c': // comment line |
… |
… |
|
152 | 157 | getline(is, str); |
153 | 158 | supply.set(nodes[i], sup); |
154 | 159 | break; |
155 | | case 'a': // arc (arc) definition line |
| 160 | case 'a': // arc definition line |
156 | 161 | is >> i >> j >> low >> cap >> co; |
157 | 162 | getline(is, str); |
158 | 163 | e = g.addArc(nodes[i], nodes[j]); |
159 | 164 | lower.set(e, low); |
160 | | if (cap >= 0) |
| 165 | if (cap >= low) |
161 | 166 | capacity.set(e, cap); |
162 | 167 | else |
163 | | capacity.set(e, -1); |
| 168 | capacity.set(e, MAX); |
164 | 169 | cost.set(e, co); |
165 | 170 | break; |
166 | 171 | } |
… |
… |
|
186 | 191 | for (int k = 1; k <= desc.nodeNum; ++k) { |
187 | 192 | nodes[k] = g.addNode(); |
188 | 193 | } |
| 194 | typedef typename CapacityMap::Value Capacity; |
| 195 | Capacity MAX = std::numeric_limits<Capacity>::has_infinity ? |
| 196 | std::numeric_limits<Capacity>::infinity() : |
| 197 | std::numeric_limits<Capacity>::max(); |
189 | 198 | |
190 | 199 | while (is >> c) { |
191 | 200 | switch (c) { |
… |
… |
|
205 | 214 | if (d == 't') t = nodes[i]; |
206 | 215 | } |
207 | 216 | break; |
208 | | case 'a': // arc (arc) definition line |
209 | | if (desc.type==DimacsDescriptor::SP || |
210 | | desc.type==DimacsDescriptor::MAX) { |
| 217 | case 'a': // arc definition line |
| 218 | if (desc.type==DimacsDescriptor::SP) { |
211 | 219 | is >> i >> j >> _cap; |
212 | 220 | getline(is, str); |
213 | 221 | e = g.addArc(nodes[i], nodes[j]); |
214 | 222 | capacity.set(e, _cap); |
215 | | } else { |
| 223 | } |
| 224 | else if (desc.type==DimacsDescriptor::MAX) { |
| 225 | is >> i >> j >> _cap; |
| 226 | getline(is, str); |
| 227 | e = g.addArc(nodes[i], nodes[j]); |
| 228 | if (_cap >= 0) |
| 229 | capacity.set(e, _cap); |
| 230 | else |
| 231 | capacity.set(e, MAX); |
| 232 | } |
| 233 | else { |
216 | 234 | is >> i >> j; |
217 | 235 | getline(is, str); |
218 | 236 | g.addArc(nodes[i], nodes[j]); |