1 #include <dai/bipgraph.h>
3 using namespace std;
4 using namespace dai;
6 int main() {
7 vector<BipartiteGraph::Edge> edges;
8 edges.reserve( 5 );
9 edges.push_back( BipartiteGraph::Edge(0, 0) );
10 edges.push_back( BipartiteGraph::Edge(1, 0) );
11 edges.push_back( BipartiteGraph::Edge(2, 0) );
12 edges.push_back( BipartiteGraph::Edge(1, 1) );
13 edges.push_back( BipartiteGraph::Edge(2, 1) );
14 BipartiteGraph G( 3, 2, edges.begin(), edges.end() );
16 cout << "G has " << G.nr1() << " nodes of type 1, " << G.nr2() << " nodes of type 2 and " << G.nrEdges() << " edges." << endl << endl;
18 for( size_t n1 = 0; n1 < G.nr1(); n1++ ) {
19 cout << "Node " << n1 << " of type 1 has " << G.nb1(n1).size() << " neighbors:" << endl;
20 foreach( const BipartiteGraph::Neighbor &n2, G.nb1(n1) ) {
21 size_t _n2 = n2.iter;
22 size_t _n1 = n2.dual;
23 cout << " the " << n2.iter << "'th neighbor is node " << n2 << " of type 2" << endl;
25 // The _n2'th neighbor of n1 is n2:
26 assert( G.nb1(n1)[_n2] == n2 );
27 // The _n1'th neighbor of n2 is n1:
28 assert( G.nb2(n2)[_n1] == n1 );
29 // n2 can be used as an abbreviation of n2.node:
30 assert( static_cast<size_t>(n2) == n2.node );
31 }
32 cout << endl;
33 }
34 }