[Lemon-commits] [lemon_svn] jacint: r751 - hugo/trunk/src/hugo
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:41:18 CET 2006
Author: jacint
Date: Fri May 7 12:34:36 2004
New Revision: 751
Modified:
hugo/trunk/src/hugo/dimacs.h
Log:
Docs added
Modified: hugo/trunk/src/hugo/dimacs.h
==============================================================================
--- hugo/trunk/src/hugo/dimacs.h (original)
+++ hugo/trunk/src/hugo/dimacs.h Fri May 7 12:34:36 2004
@@ -7,27 +7,33 @@
#include <vector>
#include <hugo/maps.h>
+/// \ingroup misc
/// \file
/// \brief Dimacs file format reader.
namespace hugo {
- /// Dimacs flow file format reader function.
- /// This function reads a flow instance from dimacs flow format.
- /// At the beginning \c g is cleared by \c g.clear().
- /// If the data coming from \c is is a max flow problem instance, then
- /// \c s and \c t will be respectively the source and target nodes
- /// and \c capacity will contain the edge capacities.
- /// If the data is a shortest path problem instance then \c s will be the
- /// source node and \c capacity will contain the edge lengths.
+ /// \addtogroup misc
+ /// @{
+
+ /// Dimacs min cost flow reader function.
+
+ /// This function reads a min cost flow instance from dimacs format,
+ /// i.e. from dimacs files having a line starting with \c p \c "min".
+ /// At the beginning \c g is cleared by \c g.clear(). The edge
+ /// capacities are written to \c capacity, \c s and \c t are set to
+ /// the source and the target nodes resp. and the cost of the edges
+ /// are written to \c cost.
///
- ///\author Marton Makai
- template<typename Graph, typename CapacityMap>
- void readDimacsMaxFlow(std::istream& is, Graph &g,
- typename Graph::Node &s, typename Graph::Node &t, CapacityMap& capacity) {
+ /// \author Marton Makai
+ template<typename Graph, typename CapacityMap, typename CostMap>
+ void readDimacs(std::istream& is, Graph &g, CapacityMap& capacity,
+ typename Graph::Node &s, typename Graph::Node &t,
+ CostMap& cost) {
g.clear();
- int cap;
+ typename CapacityMap::ValueType _cap;
+ typename CostMap::ValueType _cost;
char d;
std::string problem;
char c;
@@ -53,7 +59,7 @@
getline(is, str);
s=nodes[i];
}
- if (problem=="max") { //max flow problem
+ if (problem=="max" || problem=="min") { //((max) or (min cost)) flow problem
is >> i >> d;
getline(is, str);
if (d=='s') s=nodes[i];
@@ -61,33 +67,59 @@
}
break;
case 'a':
- is >> i >> j >> cap;
- getline(is, str);
- e=g.addEdge(nodes[i], nodes[j]);
- capacity.update();
- capacity.set(e, cap);
+ if ( problem == "max" || problem == "sp") {
+ is >> i >> j >> _cap;
+ getline(is, str);
+ e=g.addEdge(nodes[i], nodes[j]);
+ capacity.update();
+ capacity.set(e, _cap);
+ } else {
+ if ( problem == "min" ) {
+ is >> i >> j >> _cap >> _cost;
+ getline(is, str);
+ e=g.addEdge(nodes[i], nodes[j]);
+ capacity.update();
+ capacity.set(e, _cap);
+ cost.update();
+ cost.set(e, _cost);
+ } else {
+ is >> i >> j;
+ getline(is, str);
+ g.addEdge(nodes[i], nodes[j]);
+ }
+ }
break;
}
}
}
- /// matching problem
- template<typename Graph>
- void readDimacs(std::istream& is, Graph &g) {
- typename Graph::Node u;
- NullMap<typename Graph::Edge, int> n;
- readDimacs(is, g, n, u, u, n);
- }
- /// sg problem
+ /// Dimacs max flow reader function.
+
+ /// This function reads a max flow instance from dimacs format,
+ /// i.e. from dimacs files having a line starting with \c p \c
+ /// "max". At the beginning \c g is cleared by \c g.clear(). The
+ /// edge capacities are written to \c capacity and \c s and \c t are
+ /// set to the source and the target nodes.
+ ///
+ /// \author Marton Makai
template<typename Graph, typename CapacityMap>
- void readDimacs(std::istream& is, Graph &g, CapacityMap& capacity) {
- typename Graph::Node u;
+ void readDimacs(std::istream& is, Graph &g, CapacityMap& capacity,
+ typename Graph::Node &s, typename Graph::Node &t) {
NullMap<typename Graph::Edge, int> n;
- readDimacs(is, g, capacity, u, u, n);
+ readDimacs(is, g, capacity, s, t, n);
}
- /// shortest path problem
+
+ /// Dimacs shortest path reader function.
+
+ /// This function reads a shortest path instance from dimacs format,
+ /// i.e. from dimacs files having a line starting with \c p \c "sp".
+ /// At the beginning \c g is cleared by \c g.clear(). The edge
+ /// capacities are written to \c capacity and \c s is set to the
+ /// source node.
+ ///
+ /// \author Marton Makai
template<typename Graph, typename CapacityMap>
void readDimacs(std::istream& is, Graph &g, CapacityMap& capacity,
typename Graph::Node &s) {
@@ -95,80 +127,37 @@
readDimacs(is, g, capacity, s, s, n);
}
- /// max flow problem
+
+ /// Dimacs capacitated graph reader function.
+
+ /// This function reads an edge capacitated graph instance from
+ /// dimacs format. At the beginning \c g is cleared by \c g.clear()
+ /// and the edge capacities are written to \c capacity.
+ ///
+ /// \author Marton Makai
template<typename Graph, typename CapacityMap>
- void readDimacs(std::istream& is, Graph &g, CapacityMap& capacity,
- typename Graph::Node &s, typename Graph::Node &t) {
+ void readDimacs(std::istream& is, Graph &g, CapacityMap& capacity) {
+ typename Graph::Node u;
NullMap<typename Graph::Edge, int> n;
- readDimacs(is, g, capacity, s, t, n);
+ readDimacs(is, g, capacity, u, u, n);
}
- /// min cost flow problem
- template<typename Graph, typename CapacityMap, typename CostMap>
- void readDimacs(std::istream& is, Graph &g, CapacityMap& capacity,
- typename Graph::Node &s, typename Graph::Node &t,
- CostMap& cost) {
- g.clear();
- typename CapacityMap::ValueType _cap;
- typename CostMap::ValueType _cost;
- char d;
- std::string problem;
- char c;
- int i, j;
- std::string str;
- int n, m;
- typename Graph::Edge e;
- std::vector<typename Graph::Node> nodes;
- while (is>>c) {
- switch (c) {
- case 'c': //comment
- getline(is, str);
- break;
- case 'p': //problem definition
- is >> problem >> n >> m;
- getline(is, str);
- nodes.resize(n+1);
- for (int k=1; k<=n; ++k) nodes[k]=g.addNode();
- break;
- case 'n': //node definition
- if (problem=="sp") { //shortest path problem
- is >> i;
- getline(is, str);
- s=nodes[i];
- }
- if (problem=="max" || problem=="min") { //((max) or (min cost)) flow problem
- is >> i >> d;
- getline(is, str);
- if (d=='s') s=nodes[i];
- if (d=='t') t=nodes[i];
- }
- break;
- case 'a':
- if ( problem == "mat" ) {
- is >> i >> j;
- getline(is, str);
- g.addEdge(nodes[i], nodes[j]);
- }
- if ( problem == "max" || problem == "sp") {
- is >> i >> j >> _cap;
- getline(is, str);
- e=g.addEdge(nodes[i], nodes[j]);
- capacity.update();
- capacity.set(e, _cap);
- }
- if ( problem == "min" ) {
- is >> i >> j >> _cap >> _cost;
- getline(is, str);
- e=g.addEdge(nodes[i], nodes[j]);
- capacity.update();
- capacity.set(e, _cap);
- cost.update();
- cost.set(e, _cost);
- }
- break;
- }
- }
+
+ /// Dimacs plain graph reader function.
+
+ /// This function reads a graph without any designated nodes and
+ /// maps from dimacs format, i.e. from dimacs files having a line
+ /// starting with \c p \c "mat". At the beginning \c g is cleared
+ /// by \c g.clear().
+ ///
+ /// \author Marton Makai
+ template<typename Graph>
+ void readDimacs(std::istream& is, Graph &g) {
+ typename Graph::Node u;
+ NullMap<typename Graph::Edge, int> n;
+ readDimacs(is, g, n, u, u, n);
}
+
@@ -199,7 +188,56 @@
}
+ /// @}
} //namespace hugo
#endif //HUGO_DIMACS_H
+
+// template<typename Graph, typename CapacityMap>
+// void readDimacsMaxFlow(std::istream& is, Graph &g,
+// typename Graph::Node &s, typename Graph::Node &t, CapacityMap& capacity) {
+// g.clear();
+// int cap;
+// char d;
+// std::string problem;
+// char c;
+// int i, j;
+// std::string str;
+// int n, m;
+// typename Graph::Edge e;
+// std::vector<typename Graph::Node> nodes;
+// while (is>>c) {
+// switch (c) {
+// case 'c': //comment
+// getline(is, str);
+// break;
+// case 'p': //problem definition
+// is >> problem >> n >> m;
+// getline(is, str);
+// nodes.resize(n+1);
+// for (int k=1; k<=n; ++k) nodes[k]=g.addNode();
+// break;
+// case 'n': //node definition
+// if (problem=="sp") { //shortest path problem
+// is >> i;
+// getline(is, str);
+// s=nodes[i];
+// }
+// if (problem=="max") { //max flow problem
+// is >> i >> d;
+// getline(is, str);
+// if (d=='s') s=nodes[i];
+// if (d=='t') t=nodes[i];
+// }
+// break;
+// case 'a':
+// is >> i >> j >> cap;
+// getline(is, str);
+// e=g.addEdge(nodes[i], nodes[j]);
+// capacity.update();
+// capacity.set(e, cap);
+// break;
+// }
+// }
+// }
More information about the Lemon-commits
mailing list