0
2
0
12
11
| ... | ... |
@@ -51,13 +51,13 @@ |
| 51 | 51 |
/// amount of the nodes are written to \c supply (signed). The |
| 52 | 52 |
/// lower bounds, capacities and costs of the arcs are written to |
| 53 | 53 |
/// \c lower, \c capacity and \c cost. |
| 54 | 54 |
template <typename Digraph, typename LowerMap, |
| 55 | 55 |
typename CapacityMap, typename CostMap, |
| 56 | 56 |
typename SupplyMap> |
| 57 |
void |
|
| 57 |
void readDimacsMin( std::istream& is, |
|
| 58 | 58 |
Digraph &g, |
| 59 | 59 |
LowerMap& lower, |
| 60 | 60 |
CapacityMap& capacity, |
| 61 | 61 |
CostMap& cost, |
| 62 | 62 |
SupplyMap& supply ) |
| 63 | 63 |
{
|
| ... | ... |
@@ -115,13 +115,13 @@ |
| 115 | 115 |
/// p max |
| 116 | 116 |
/// \endcode |
| 117 | 117 |
/// At the beginning \c g is cleared by \c g.clear(). The arc |
| 118 | 118 |
/// capacities are written to \c capacity and \c s and \c t are |
| 119 | 119 |
/// set to the source and the target nodes. |
| 120 | 120 |
template<typename Digraph, typename CapacityMap> |
| 121 |
void |
|
| 121 |
void readDimacsMax(std::istream& is, Digraph &g, CapacityMap& capacity, |
|
| 122 | 122 |
typename Digraph::Node &s, typename Digraph::Node &t) {
|
| 123 | 123 |
g.clear(); |
| 124 | 124 |
std::vector<typename Digraph::Node> nodes; |
| 125 | 125 |
typename Digraph::Arc e; |
| 126 | 126 |
std::string problem; |
| 127 | 127 |
char c, d; |
| ... | ... |
@@ -178,54 +178,55 @@ |
| 178 | 178 |
/// p sp |
| 179 | 179 |
/// \endcode |
| 180 | 180 |
/// At the beginning \c g is cleared by \c g.clear(). The arc |
| 181 | 181 |
/// capacities are written to \c capacity and \c s is set to the |
| 182 | 182 |
/// source node. |
| 183 | 183 |
template<typename Digraph, typename CapacityMap> |
| 184 |
void |
|
| 184 |
void readDimacsSp(std::istream& is, Digraph &g, CapacityMap& capacity, |
|
| 185 | 185 |
typename Digraph::Node &s) {
|
| 186 |
|
|
| 186 |
typename Digraph::Node t; |
|
| 187 |
readDimacsMax(is, g, capacity, s, t); |
|
| 187 | 188 |
} |
| 188 | 189 |
|
| 189 | 190 |
/// DIMACS capacitated digraph reader function. |
| 190 | 191 |
/// |
| 191 | 192 |
/// This function reads an arc capacitated digraph instance from |
| 192 | 193 |
/// DIMACS format. At the beginning \c g is cleared by \c g.clear() |
| 193 | 194 |
/// and the arc capacities are written to \c capacity. |
| 194 | 195 |
template<typename Digraph, typename CapacityMap> |
| 195 |
void readDimacs(std::istream& is, Digraph &g, CapacityMap& capacity) {
|
|
| 196 |
typename Digraph::Node u; |
|
| 197 |
|
|
| 196 |
void readDimacsMax(std::istream& is, Digraph &g, CapacityMap& capacity) {
|
|
| 197 |
typename Digraph::Node u,v; |
|
| 198 |
readDimacsMax(is, g, capacity, u, v); |
|
| 198 | 199 |
} |
| 199 | 200 |
|
| 200 | 201 |
/// DIMACS plain digraph reader function. |
| 201 | 202 |
/// |
| 202 | 203 |
/// This function reads a digraph without any designated nodes and |
| 203 | 204 |
/// maps from DIMACS format, i.e. from DIMACS files having a line |
| 204 | 205 |
/// starting with |
| 205 | 206 |
/// \code |
| 206 | 207 |
/// p mat |
| 207 | 208 |
/// \endcode |
| 208 | 209 |
/// At the beginning \c g is cleared by \c g.clear(). |
| 209 | 210 |
template<typename Digraph> |
| 210 |
void readDimacs(std::istream& is, Digraph &g) {
|
|
| 211 |
typename Digraph::Node u; |
|
| 211 |
void readDimacsMat(std::istream& is, Digraph &g) {
|
|
| 212 |
typename Digraph::Node u,v; |
|
| 212 | 213 |
NullMap<typename Digraph::Arc, int> n; |
| 213 |
|
|
| 214 |
readDimacsMax(is, g, n, u, v); |
|
| 214 | 215 |
} |
| 215 | 216 |
|
| 216 | 217 |
/// DIMACS plain digraph writer function. |
| 217 | 218 |
/// |
| 218 | 219 |
/// This function writes a digraph without any designated nodes and |
| 219 | 220 |
/// maps into DIMACS format, i.e. into DIMACS file having a line |
| 220 | 221 |
/// starting with |
| 221 | 222 |
/// \code |
| 222 | 223 |
/// p mat |
| 223 | 224 |
/// \endcode |
| 224 | 225 |
template<typename Digraph> |
| 225 |
void |
|
| 226 |
void writeDimacsMat(std::ostream& os, const Digraph &g) {
|
|
| 226 | 227 |
typedef typename Digraph::NodeIt NodeIt; |
| 227 | 228 |
typedef typename Digraph::ArcIt ArcIt; |
| 228 | 229 |
|
| 229 | 230 |
os << "c matching problem" << std::endl; |
| 230 | 231 |
os << "p mat " << g.nodeNum() << " " << g.arcNum() << std::endl; |
| 231 | 232 |
| ... | ... |
@@ -120,48 +120,48 @@ |
| 120 | 120 |
ostream& os = (outputName.empty() ? cout : output); |
| 121 | 121 |
|
| 122 | 122 |
if (mincostflow) {
|
| 123 | 123 |
Digraph digraph; |
| 124 | 124 |
DoubleArcMap lower(digraph), capacity(digraph), cost(digraph); |
| 125 | 125 |
DoubleNodeMap supply(digraph); |
| 126 |
|
|
| 126 |
readDimacsMin(is, digraph, lower, capacity, cost, supply); |
|
| 127 | 127 |
DigraphWriter<Digraph>(digraph, os). |
| 128 | 128 |
nodeMap("supply", supply).
|
| 129 | 129 |
arcMap("lower", lower).
|
| 130 | 130 |
arcMap("capacity", capacity).
|
| 131 | 131 |
arcMap("cost", cost).
|
| 132 | 132 |
run(); |
| 133 | 133 |
} else if (maxflow) {
|
| 134 | 134 |
Digraph digraph; |
| 135 | 135 |
Node s, t; |
| 136 | 136 |
DoubleArcMap capacity(digraph); |
| 137 |
|
|
| 137 |
readDimacsMax(is, digraph, capacity, s, t); |
|
| 138 | 138 |
DigraphWriter<Digraph>(digraph, os). |
| 139 | 139 |
arcMap("capacity", capacity).
|
| 140 | 140 |
node("source", s).
|
| 141 | 141 |
node("target", t).
|
| 142 | 142 |
run(); |
| 143 | 143 |
} else if (shortestpath) {
|
| 144 | 144 |
Digraph digraph; |
| 145 | 145 |
Node s; |
| 146 | 146 |
DoubleArcMap capacity(digraph); |
| 147 |
|
|
| 147 |
readDimacsSp(is, digraph, capacity, s); |
|
| 148 | 148 |
DigraphWriter<Digraph>(digraph, os). |
| 149 | 149 |
arcMap("capacity", capacity).
|
| 150 | 150 |
node("source", s).
|
| 151 | 151 |
run(); |
| 152 | 152 |
} else if (capacitated) {
|
| 153 | 153 |
Digraph digraph; |
| 154 | 154 |
DoubleArcMap capacity(digraph); |
| 155 |
|
|
| 155 |
readDimacsMax(is, digraph, capacity); |
|
| 156 | 156 |
DigraphWriter<Digraph>(digraph, os). |
| 157 | 157 |
arcMap("capacity", capacity).
|
| 158 | 158 |
run(); |
| 159 | 159 |
} else if (plain) {
|
| 160 | 160 |
Digraph digraph; |
| 161 |
|
|
| 161 |
readDimacsMat(is, digraph); |
|
| 162 | 162 |
DigraphWriter<Digraph>(digraph, os).run(); |
| 163 | 163 |
} else {
|
| 164 | 164 |
cerr << "Invalid type error" << endl; |
| 165 | 165 |
return -1; |
| 166 | 166 |
} |
| 167 | 167 |
return 0; |
0 comments (0 inline)