60 for (int i=0; i<m; ++i) |
60 for (int i=0; i<m; ++i) |
61 g.addEdge(s_nodes[random(a)], t_nodes[random(b)]); |
61 g.addEdge(s_nodes[random(a)], t_nodes[random(b)]); |
62 } |
62 } |
63 |
63 |
64 /// Generates a complete graph in the undirected sense |
64 /// Generates a complete graph in the undirected sense |
65 /// with n nodes and m edges. |
65 /// with n nodes. |
66 /// Before generating the random graph, \c g.clear() is called. |
66 /// Before generating the random graph, \c g.clear() is called. |
67 template<typename Graph> |
67 template<typename Graph> |
68 void completeGraph(Graph& g, int n) { |
68 void completeGraph(Graph& g, int n) { |
69 g.clear(); |
69 g.clear(); |
70 std::vector<typename Graph::Node> nodes; |
70 std::vector<typename Graph::Node> nodes; |
72 nodes.push_back(g.addNode()); |
72 nodes.push_back(g.addNode()); |
73 for (int i=0; i<n; ++i) |
73 for (int i=0; i<n; ++i) |
74 for (int j=i+1; j<n; ++j) |
74 for (int j=i+1; j<n; ++j) |
75 g.addEdge(nodes[i], nodes[j]); |
75 g.addEdge(nodes[i], nodes[j]); |
76 } |
76 } |
|
77 |
|
78 /// Generates a complete bidirected graph on n nodes. |
|
79 /// Before generating the random graph, \c g.clear() is called. |
|
80 template<typename Graph> |
|
81 void completeBidirectedGraph(Graph& g, int n) { |
|
82 g.clear(); |
|
83 std::vector<typename Graph::Node> nodes; |
|
84 for (int i=0; i<n; ++i) |
|
85 nodes.push_back(g.addNode()); |
|
86 for (int i=0; i<n; ++i) |
|
87 for (int j=i+1; j<n; ++j) { |
|
88 g.addEdge(nodes[i], nodes[j]); |
|
89 g.addEdge(nodes[j], nodes[i]); |
|
90 } |
|
91 } |
|
92 |
|
93 /// Generates a complete bipartite graph with a and b nodes |
|
94 /// in the color classes. |
|
95 /// Before generating the random graph, \c g.clear() is called. |
|
96 template<typename Graph> |
|
97 void completeBipartiteGraph(Graph& g, int a, int b) { |
|
98 g.clear(); |
|
99 std::vector<typename Graph::Node> s_nodes; |
|
100 std::vector<typename Graph::Node> t_nodes; |
|
101 for (int i=0; i<a; ++i) |
|
102 ///\bug g.addNode(g.S_CLASS) would be better. |
|
103 s_nodes.push_back(g.addNode(false)); |
|
104 for (int i=0; i<b; ++i) |
|
105 ///\bug g.addNode(g.T_CLASS) would be better. |
|
106 t_nodes.push_back(g.addNode(true)); |
|
107 for (int i=0; i<a; ++i) |
|
108 for (int j=0; j<b; ++j) |
|
109 g.addEdge(s_nodes[i], t_nodes[j]); |
|
110 } |
77 |
111 |
78 } //namespace hugo |
112 } //namespace hugo |