[Lemon-commits] Balazs Dezso: Add bipartite graph concepts (#69)
Lemon HG
hg at lemon.cs.elte.hu
Fri Mar 1 17:49:45 CET 2013
details: http://lemon.cs.elte.hu/hg/lemon/rev/2e959a5a0c2d
changeset: 1186:2e959a5a0c2d
user: Balazs Dezso <deba [at] inf.elte.hu>
date: Sun Nov 14 16:35:31 2010 +0100
description:
Add bipartite graph concepts (#69)
diffstat:
lemon/concepts/bpgraph.h | 1020 +++++++++++++++++++++++++++++++++++++
lemon/concepts/graph.h | 4 +-
lemon/concepts/graph_components.h | 610 +++++++++++++++++++++-
test/CMakeLists.txt | 1 +
test/bpgraph_test.cc | 70 ++
5 files changed, 1680 insertions(+), 25 deletions(-)
diffs (truncated from 1832 to 300 lines):
diff --git a/lemon/concepts/bpgraph.h b/lemon/concepts/bpgraph.h
new file mode 100644
--- /dev/null
+++ b/lemon/concepts/bpgraph.h
@@ -0,0 +1,1020 @@
+/* -*- mode: C++; indent-tabs-mode: nil; -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library.
+ *
+ * Copyright (C) 2003-2010
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+///\ingroup graph_concepts
+///\file
+///\brief The concept of undirected graphs.
+
+#ifndef LEMON_CONCEPTS_BPGRAPH_H
+#define LEMON_CONCEPTS_BPGRAPH_H
+
+#include <lemon/concepts/graph_components.h>
+#include <lemon/concepts/maps.h>
+#include <lemon/concept_check.h>
+#include <lemon/core.h>
+
+namespace lemon {
+ namespace concepts {
+
+ /// \ingroup graph_concepts
+ ///
+ /// \brief Class describing the concept of undirected bipartite graphs.
+ ///
+ /// This class describes the common interface of all undirected
+ /// bipartite graphs.
+ ///
+ /// Like all concept classes, it only provides an interface
+ /// without any sensible implementation. So any general algorithm for
+ /// undirected bipartite graphs should compile with this class,
+ /// but it will not run properly, of course.
+ /// An actual graph implementation like \ref ListBpGraph or
+ /// \ref SmartBpGraph may have additional functionality.
+ ///
+ /// The bipartite graphs also fulfill the concept of \ref Graph
+ /// "undirected graphs". Bipartite graphs provide a bipartition of
+ /// the node set, namely a red and blue set of the nodes. The
+ /// nodes can be iterated with the RedIt and BlueIt in the two
+ /// node sets. With RedMap and BlueMap values can be assigned to
+ /// the nodes in the two sets.
+ ///
+ /// The edges of the graph cannot connect two nodes of the same
+ /// set. The edges inherent orientation is from the red nodes to
+ /// the blue nodes.
+ ///
+ /// \sa Graph
+ class BpGraph {
+ private:
+ /// BpGraphs are \e not copy constructible. Use bpGraphCopy instead.
+ BpGraph(const BpGraph&) {}
+ /// \brief Assignment of a graph to another one is \e not allowed.
+ /// Use bpGraphCopy instead.
+ void operator=(const BpGraph&) {}
+
+ public:
+ /// Default constructor.
+ BpGraph() {}
+
+ /// \brief Undirected graphs should be tagged with \c UndirectedTag.
+ ///
+ /// Undirected graphs should be tagged with \c UndirectedTag.
+ ///
+ /// This tag helps the \c enable_if technics to make compile time
+ /// specializations for undirected graphs.
+ typedef True UndirectedTag;
+
+ /// The node type of the graph
+
+ /// This class identifies a node of the graph. It also serves
+ /// as a base class of the node iterators,
+ /// thus they convert to this type.
+ class Node {
+ public:
+ /// Default constructor
+
+ /// Default constructor.
+ /// \warning It sets the object to an undefined value.
+ Node() { }
+ /// Copy constructor.
+
+ /// Copy constructor.
+ ///
+ Node(const Node&) { }
+
+ /// %Invalid constructor \& conversion.
+
+ /// Initializes the object to be invalid.
+ /// \sa Invalid for more details.
+ Node(Invalid) { }
+ /// Equality operator
+
+ /// Equality operator.
+ ///
+ /// Two iterators are equal if and only if they point to the
+ /// same object or both are \c INVALID.
+ bool operator==(Node) const { return true; }
+
+ /// Inequality operator
+
+ /// Inequality operator.
+ bool operator!=(Node) const { return true; }
+
+ /// Artificial ordering operator.
+
+ /// Artificial ordering operator.
+ ///
+ /// \note This operator only has to define some strict ordering of
+ /// the items; this order has nothing to do with the iteration
+ /// ordering of the items.
+ bool operator<(Node) const { return false; }
+
+ };
+
+ /// Class to represent red nodes.
+
+ /// This class represents the red nodes of the graph. It does
+ /// not supposed to be used directly, because the nodes can be
+ /// represented as Node instances. This class can be used as
+ /// template parameter for special map classes.
+ class RedNode : public Node {
+ public:
+ /// Default constructor
+
+ /// Default constructor.
+ /// \warning It sets the object to an undefined value.
+ RedNode() { }
+ /// Copy constructor.
+
+ /// Copy constructor.
+ ///
+ RedNode(const RedNode&) : Node() { }
+
+ /// %Invalid constructor \& conversion.
+
+ /// Initializes the object to be invalid.
+ /// \sa Invalid for more details.
+ RedNode(Invalid) { }
+
+ /// Constructor for conversion from a node.
+
+ /// Constructor for conversion from a node. The conversion can
+ /// be invalid, since the Node can be member of the blue
+ /// set.
+ RedNode(const Node&) {}
+ };
+
+ /// Class to represent blue nodes.
+
+ /// This class represents the blue nodes of the graph. It does
+ /// not supposed to be used directly, because the nodes can be
+ /// represented as Node instances. This class can be used as
+ /// template parameter for special map classes.
+ class BlueNode : public Node {
+ public:
+ /// Default constructor
+
+ /// Default constructor.
+ /// \warning It sets the object to an undefined value.
+ BlueNode() { }
+ /// Copy constructor.
+
+ /// Copy constructor.
+ ///
+ BlueNode(const BlueNode&) : Node() { }
+
+ /// %Invalid constructor \& conversion.
+
+ /// Initializes the object to be invalid.
+ /// \sa Invalid for more details.
+ BlueNode(Invalid) { }
+
+ /// Constructor for conversion from a node.
+
+ /// Constructor for conversion from a node. The conversion can
+ /// be invalid, since the Node can be member of the red
+ /// set.
+ BlueNode(const Node&) {}
+ };
+
+ /// Iterator class for the red nodes.
+
+ /// This iterator goes through each red node of the graph.
+ /// Its usage is quite simple, for example, you can count the number
+ /// of red nodes in a graph \c g of type \c %BpGraph like this:
+ ///\code
+ /// int count=0;
+ /// for (BpGraph::RedNodeIt n(g); n!=INVALID; ++n) ++count;
+ ///\endcode
+ class RedIt : public Node {
+ public:
+ /// Default constructor
+
+ /// Default constructor.
+ /// \warning It sets the iterator to an undefined value.
+ RedIt() { }
+ /// Copy constructor.
+
+ /// Copy constructor.
+ ///
+ RedIt(const RedIt& n) : Node(n) { }
+ /// %Invalid constructor \& conversion.
+
+ /// Initializes the iterator to be invalid.
+ /// \sa Invalid for more details.
+ RedIt(Invalid) { }
+ /// Sets the iterator to the first red node.
+
+ /// Sets the iterator to the first red node of the given
+ /// digraph.
+ explicit RedIt(const BpGraph&) { }
+ /// Sets the iterator to the given red node.
+
+ /// Sets the iterator to the given red node of the given
+ /// digraph.
+ RedIt(const BpGraph&, const Node&) { }
+ /// Next node.
+
+ /// Assign the iterator to the next red node.
+ ///
+ RedIt& operator++() { return *this; }
+ };
+
+ /// Iterator class for the blue nodes.
+
+ /// This iterator goes through each blue node of the graph.
+ /// Its usage is quite simple, for example, you can count the number
+ /// of blue nodes in a graph \c g of type \c %BpGraph like this:
+ ///\code
+ /// int count=0;
+ /// for (BpGraph::BlueNodeIt n(g); n!=INVALID; ++n) ++count;
+ ///\endcode
+ class BlueIt : public Node {
+ public:
+ /// Default constructor
+
+ /// Default constructor.
+ /// \warning It sets the iterator to an undefined value.
+ BlueIt() { }
+ /// Copy constructor.
+
+ /// Copy constructor.
+ ///
+ BlueIt(const BlueIt& n) : Node(n) { }
+ /// %Invalid constructor \& conversion.
+
+ /// Initializes the iterator to be invalid.
+ /// \sa Invalid for more details.
+ BlueIt(Invalid) { }
+ /// Sets the iterator to the first blue node.
+
+ /// Sets the iterator to the first blue node of the given
+ /// digraph.
+ explicit BlueIt(const BpGraph&) { }
+ /// Sets the iterator to the given blue node.
+
+ /// Sets the iterator to the given blue node of the given
+ /// digraph.
+ BlueIt(const BpGraph&, const Node&) { }
+ /// Next node.
+
+ /// Assign the iterator to the next blue node.
+ ///
+ BlueIt& operator++() { return *this; }
+ };
+
+ /// Iterator class for the nodes.
+
+ /// This iterator goes through each node of the graph.
+ /// Its usage is quite simple, for example, you can count the number
+ /// of nodes in a graph \c g of type \c %BpGraph like this:
+ ///\code
+ /// int count=0;
+ /// for (BpGraph::NodeIt n(g); n!=INVALID; ++n) ++count;
+ ///\endcode
+ class NodeIt : public Node {
+ public:
+ /// Default constructor
+
+ /// Default constructor.
+ /// \warning It sets the iterator to an undefined value.
+ NodeIt() { }
+ /// Copy constructor.
More information about the Lemon-commits
mailing list