0
3
0
| ... | ... |
@@ -274,49 +274,49 @@ |
| 274 | 274 |
DfsVisit<RDigraph, RVisitor> rdfs(rdigraph, rvisitor); |
| 275 | 275 |
rdfs.init(); |
| 276 | 276 |
rdfs.addSource(source); |
| 277 | 277 |
rdfs.start(); |
| 278 | 278 |
|
| 279 | 279 |
for (RNodeIt it(rdigraph); it != INVALID; ++it) {
|
| 280 | 280 |
if (!rdfs.reached(it)) {
|
| 281 | 281 |
return false; |
| 282 | 282 |
} |
| 283 | 283 |
} |
| 284 | 284 |
|
| 285 | 285 |
return true; |
| 286 | 286 |
} |
| 287 | 287 |
|
| 288 | 288 |
/// \ingroup connectivity |
| 289 | 289 |
/// |
| 290 | 290 |
/// \brief Count the strongly connected components of a directed graph |
| 291 | 291 |
/// |
| 292 | 292 |
/// Count the strongly connected components of a directed graph. |
| 293 | 293 |
/// The strongly connected components are the classes of an |
| 294 | 294 |
/// equivalence relation on the nodes of the graph. Two nodes are in |
| 295 | 295 |
/// the same class if they are connected with directed paths in both |
| 296 | 296 |
/// direction. |
| 297 | 297 |
/// |
| 298 |
/// \param |
|
| 298 |
/// \param digraph The graph. |
|
| 299 | 299 |
/// \return The number of components |
| 300 | 300 |
/// \note By definition, the empty graph has zero |
| 301 | 301 |
/// strongly connected components. |
| 302 | 302 |
template <typename Digraph> |
| 303 | 303 |
int countStronglyConnectedComponents(const Digraph& digraph) {
|
| 304 | 304 |
checkConcept<concepts::Digraph, Digraph>(); |
| 305 | 305 |
|
| 306 | 306 |
using namespace _connectivity_bits; |
| 307 | 307 |
|
| 308 | 308 |
typedef typename Digraph::Node Node; |
| 309 | 309 |
typedef typename Digraph::Arc Arc; |
| 310 | 310 |
typedef typename Digraph::NodeIt NodeIt; |
| 311 | 311 |
typedef typename Digraph::ArcIt ArcIt; |
| 312 | 312 |
|
| 313 | 313 |
typedef std::vector<Node> Container; |
| 314 | 314 |
typedef typename Container::iterator Iterator; |
| 315 | 315 |
|
| 316 | 316 |
Container nodes(countNodes(digraph)); |
| 317 | 317 |
typedef LeaveOrderVisitor<Digraph, Iterator> Visitor; |
| 318 | 318 |
Visitor visitor(nodes.begin()); |
| 319 | 319 |
|
| 320 | 320 |
DfsVisit<Digraph, Visitor> dfs(digraph, visitor); |
| 321 | 321 |
dfs.init(); |
| 322 | 322 |
for (NodeIt it(digraph); it != INVALID; ++it) {
|
| ... | ... |
@@ -1204,49 +1204,49 @@ |
| 1204 | 1204 |
typedef typename Digraph::Arc Arc; |
| 1205 | 1205 |
|
| 1206 | 1206 |
TopologicalSortVisitor<Digraph, NodeMap> |
| 1207 | 1207 |
visitor(order, countNodes(graph)); |
| 1208 | 1208 |
|
| 1209 | 1209 |
DfsVisit<Digraph, TopologicalSortVisitor<Digraph, NodeMap> > |
| 1210 | 1210 |
dfs(graph, visitor); |
| 1211 | 1211 |
|
| 1212 | 1212 |
dfs.init(); |
| 1213 | 1213 |
for (NodeIt it(graph); it != INVALID; ++it) {
|
| 1214 | 1214 |
if (!dfs.reached(it)) {
|
| 1215 | 1215 |
dfs.addSource(it); |
| 1216 | 1216 |
dfs.start(); |
| 1217 | 1217 |
} |
| 1218 | 1218 |
} |
| 1219 | 1219 |
} |
| 1220 | 1220 |
|
| 1221 | 1221 |
/// \ingroup connectivity |
| 1222 | 1222 |
/// |
| 1223 | 1223 |
/// \brief Sort the nodes of a DAG into topolgical order. |
| 1224 | 1224 |
/// |
| 1225 | 1225 |
/// Sort the nodes of a DAG into topolgical order. It also checks |
| 1226 | 1226 |
/// that the given graph is DAG. |
| 1227 | 1227 |
/// |
| 1228 |
/// \param |
|
| 1228 |
/// \param digraph The graph. It must be directed and acyclic. |
|
| 1229 | 1229 |
/// \retval order A readable - writable node map. The values will be set |
| 1230 | 1230 |
/// from 0 to the number of the nodes in the graph minus one. Each values |
| 1231 | 1231 |
/// of the map will be set exactly once, the values will be set descending |
| 1232 | 1232 |
/// order. |
| 1233 | 1233 |
/// \return %False when the graph is not DAG. |
| 1234 | 1234 |
/// |
| 1235 | 1235 |
/// \see topologicalSort |
| 1236 | 1236 |
/// \see dag |
| 1237 | 1237 |
template <typename Digraph, typename NodeMap> |
| 1238 | 1238 |
bool checkedTopologicalSort(const Digraph& digraph, NodeMap& order) {
|
| 1239 | 1239 |
using namespace _connectivity_bits; |
| 1240 | 1240 |
|
| 1241 | 1241 |
checkConcept<concepts::Digraph, Digraph>(); |
| 1242 | 1242 |
checkConcept<concepts::ReadWriteMap<typename Digraph::Node, int>, |
| 1243 | 1243 |
NodeMap>(); |
| 1244 | 1244 |
|
| 1245 | 1245 |
typedef typename Digraph::Node Node; |
| 1246 | 1246 |
typedef typename Digraph::NodeIt NodeIt; |
| 1247 | 1247 |
typedef typename Digraph::Arc Arc; |
| 1248 | 1248 |
|
| 1249 | 1249 |
for (NodeIt it(digraph); it != INVALID; ++it) {
|
| 1250 | 1250 |
order.set(it, -1); |
| 1251 | 1251 |
} |
| 1252 | 1252 |
| ... | ... |
@@ -395,49 +395,49 @@ |
| 395 | 395 |
} |
| 396 | 396 |
|
| 397 | 397 |
public: |
| 398 | 398 |
|
| 399 | 399 |
/// \brief Constructor |
| 400 | 400 |
/// |
| 401 | 401 |
/// Constructor. |
| 402 | 402 |
MaxMatching(const Graph& graph) |
| 403 | 403 |
: _graph(graph), _matching(0), _status(0), _ear(0), |
| 404 | 404 |
_blossom_set_index(0), _blossom_set(0), _blossom_rep(0), |
| 405 | 405 |
_tree_set_index(0), _tree_set(0) {}
|
| 406 | 406 |
|
| 407 | 407 |
~MaxMatching() {
|
| 408 | 408 |
destroyStructures(); |
| 409 | 409 |
} |
| 410 | 410 |
|
| 411 | 411 |
/// \name Execution control |
| 412 | 412 |
/// The simplest way to execute the algorithm is to use the |
| 413 | 413 |
/// \c run() member function. |
| 414 | 414 |
/// \n |
| 415 | 415 |
|
| 416 | 416 |
/// If you need better control on the execution, you must call |
| 417 | 417 |
/// \ref init(), \ref greedyInit() or \ref matchingInit() |
| 418 | 418 |
/// functions first, then you can start the algorithm with the \ref |
| 419 |
/// |
|
| 419 |
/// startSparse() or startDense() functions. |
|
| 420 | 420 |
|
| 421 | 421 |
///@{
|
| 422 | 422 |
|
| 423 | 423 |
/// \brief Sets the actual matching to the empty matching. |
| 424 | 424 |
/// |
| 425 | 425 |
/// Sets the actual matching to the empty matching. |
| 426 | 426 |
/// |
| 427 | 427 |
void init() {
|
| 428 | 428 |
createStructures(); |
| 429 | 429 |
for(NodeIt n(_graph); n != INVALID; ++n) {
|
| 430 | 430 |
_matching->set(n, INVALID); |
| 431 | 431 |
_status->set(n, UNMATCHED); |
| 432 | 432 |
} |
| 433 | 433 |
} |
| 434 | 434 |
|
| 435 | 435 |
///\brief Finds an initial matching in a greedy way |
| 436 | 436 |
/// |
| 437 | 437 |
///It finds an initial matching in a greedy way. |
| 438 | 438 |
void greedyInit() {
|
| 439 | 439 |
createStructures(); |
| 440 | 440 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 441 | 441 |
_matching->set(n, INVALID); |
| 442 | 442 |
_status->set(n, UNMATCHED); |
| 443 | 443 |
} |
| ... | ... |
@@ -30,49 +30,49 @@ |
| 30 | 30 |
|
| 31 | 31 |
namespace lemon {
|
| 32 | 32 |
|
| 33 | 33 |
/// \addtogroup shortest_path |
| 34 | 34 |
/// @{
|
| 35 | 35 |
|
| 36 | 36 |
/// \brief Algorithm for finding arc-disjoint paths between two nodes |
| 37 | 37 |
/// having minimum total length. |
| 38 | 38 |
/// |
| 39 | 39 |
/// \ref lemon::Suurballe "Suurballe" implements an algorithm for |
| 40 | 40 |
/// finding arc-disjoint paths having minimum total length (cost) |
| 41 | 41 |
/// from a given source node to a given target node in a digraph. |
| 42 | 42 |
/// |
| 43 | 43 |
/// In fact, this implementation is the specialization of the |
| 44 | 44 |
/// \ref CapacityScaling "successive shortest path" algorithm. |
| 45 | 45 |
/// |
| 46 | 46 |
/// \tparam Digraph The digraph type the algorithm runs on. |
| 47 | 47 |
/// The default value is \c ListDigraph. |
| 48 | 48 |
/// \tparam LengthMap The type of the length (cost) map. |
| 49 | 49 |
/// The default value is <tt>Digraph::ArcMap<int></tt>. |
| 50 | 50 |
/// |
| 51 | 51 |
/// \warning Length values should be \e non-negative \e integers. |
| 52 | 52 |
/// |
| 53 | 53 |
/// \note For finding node-disjoint paths this algorithm can be used |
| 54 |
/// with \ref |
|
| 54 |
/// with \ref SplitNodes. |
|
| 55 | 55 |
#ifdef DOXYGEN |
| 56 | 56 |
template <typename Digraph, typename LengthMap> |
| 57 | 57 |
#else |
| 58 | 58 |
template < typename Digraph = ListDigraph, |
| 59 | 59 |
typename LengthMap = typename Digraph::template ArcMap<int> > |
| 60 | 60 |
#endif |
| 61 | 61 |
class Suurballe |
| 62 | 62 |
{
|
| 63 | 63 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
| 64 | 64 |
|
| 65 | 65 |
typedef typename LengthMap::Value Length; |
| 66 | 66 |
typedef ConstMap<Arc, int> ConstArcMap; |
| 67 | 67 |
typedef typename Digraph::template NodeMap<Arc> PredMap; |
| 68 | 68 |
|
| 69 | 69 |
public: |
| 70 | 70 |
|
| 71 | 71 |
/// The type of the flow map. |
| 72 | 72 |
typedef typename Digraph::template ArcMap<int> FlowMap; |
| 73 | 73 |
/// The type of the potential map. |
| 74 | 74 |
typedef typename Digraph::template NodeMap<Length> PotentialMap; |
| 75 | 75 |
/// The type of the path structures. |
| 76 | 76 |
typedef SimplePath<Digraph> Path; |
| 77 | 77 |
|
| 78 | 78 |
private: |
0 comments (0 inline)