Repository navigation
GraphRandomizer
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(N) - generated graph will have N nodes
- edge(E) - generated graph will have E edges. If you did not set this, E will be equal to N * 1.1
-
directed(b) - set b to
falseto make the randomizer generate an undirected graph. this is true by default. -
loop(b) - set b to
trueto enable loop. This is false by default - component(C) - generated graph will have C components. The number of component is 1 by default.
- scc(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.
You can chain and combine all parameters above as you like, for example:
graph_rand.node(10).edge(20).directed(false);
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] (https://en.wikipedia.org/wiki/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 simply print your result to file by calling print(file = stdout) method. This will print a graph based on this format:
- First line is 2 integers N and E, the number of nodes and edges respectively.
- The next E lines consist of 2 variable path_from[i] and path_to[i], meaning there is an edge from path_from[i] to path_to[i].
Additionally, you may call methods below:
- node() - this will return an integer N, the number of nodes in your graph.
- edge() - this will return an integer E, the number of edges in your graph.
-
path() - this will return a
tuple<vector<int> , vector<int> >that desribe the graph edge in path_from and path_to. -
pathTo() - this will return a
vector<int>that describe vector path_from -
pathFrom() - this will return a
vector<int>that describe vector path_to - shufflePath() - this will shuffle the path order
TBD