-
Notifications
You must be signed in to change notification settings - Fork 1
GraphRandomizer
afaji edited this page Mar 21, 2017
·
4 revisions
GraphRandomizer randomly generates a Graph.
To begin, you have to include
#include "tcrand/graph.hpp"
This will enable GraphRandomizer and Graph class. Next, you can create your randomizer object as follow:
tcrand::GraphRandomizer graph_rand;
You may set some parameters for your GraphRandomizer, by calling methods below:
- node_count(N) - generated graph will have N nodes
- edge_count(E) - generated graph will have E edges. If you did not set this, E will be equal to N * 1.1
- directed() - The generated graph will be constructed by assuming it is directed.
- self_loop() - enables a self loop.
- component_count(C) - generated graph will have C components. The number of component is 1 by default.
- scc_count(C) - generated graph will have exactly C [strongly connected components(https://en.wikipedia.org/wiki/Strongly_connected_component). This is only applicable on directed graph. If this parameter is not set, the number of scc can be any.
- multigraph() - enable multigraph. i.e. multiple edges with same end nodes.
- index_base(b) - set your index base to b. Default is 0
You can chain and combine all parameters above as you like, for example:
graph_rand.node_count(10).edge_count(20).directed();
Graph g = graph_rand.next();
You may additionally set a property of your graph. Different from the parameter, you can only set at maximum one property. You may combine property with some parameters, but be cautious as some properties will ignore certain parameter(s).
- dag() - this will generate a directed acyclic graph. By setting this, the graph will always be directed.
Graph is a special class that holds the result of GraphRandomizer.
You may call methods below:
- node_count() : int - this will return an integer N, the number of nodes in your graph.
- edge_count() : int - this will return an integer E, the number of edges in your graph.
- edges() : pair<vector,vector> - this will return your graph edges
GraphRandomizer gr;
Graph g = gr.node_count(10)
.edge_count(15)
.self_loop()
.next();
vector<int> p1, p2;
p1 = g.edges().first;
p2 = g.edges().second;
for (int i=0;i<g.edge_count();i++){
cout<<p1[i] <<" "<<p2[i]<<endl;
}