Skip to content

TreeRandomizer

afaji edited this page Mar 7, 2017 · 7 revisions

TreeRandomizer

TreeRandomizer randomly generates a Tree.

To begin, you have to include

#include "tcrand/tree.hpp"

This will enable TreeRandomizer and Tree class. Next, you can create your randomizer object as follow:

tcrand::TreeRandomizer tree_rand;

Setting Parameters

You may set some parameters for your TreeRandomizer, by calling methods below:

  • node(N) - generated tree will have N nodes
  • depth(D) - generated tree will have depth D
  • leaf(Lmin , Lmax ) - generated tree will have Lmin to Lmax leaves
  • child(Cmin , Cmax) - Every internal node will have has Cmin to Cmax childs
  • root(R) - set your tree root to R. Your tree root is 0 by default
  • path_weight(Wmin = 0, Wmax = 100) - gives random weights for each path. If not set, the weight will be from 0 to 100
  • node_weight(Wmin = 0, Wmax = 100) - gives random weights for each node. If not set, the weight will be from 0 to 100
  • weight(Wmin = 0, Wmax = 100) - gives random weights for each path and node. If not set, the weight will be from 0 to 100

You can chain and combine all parameters above as you like, for example:

tree_rand.leaf(100, 150).node(500);
Tree t = tree_rand.next();

Setting Property

You may additionally set a property of your tree. 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).

  • chain() - this will generate a chain tree. i.e, the tree's depth is equal to the tree's node. This property ignores leaf, depth and child configurations
  • star() - this will generate a star tree. This property ignores leaf, depth and child configurations
  • caterpillar() - this will generate a [caterpillar tree] (https://en.wikipedia.org/wiki/Caterpillar_tree).

Tree

Tree is a special class that holds the result of TreeRandomizer. You may simply print your result to file by calling print(file = stdout) method. This will print a tree based on this format: First line is an integer N, the number of nodes in the tree The next N-1 lines consists of 2 variable a and b, where node a and b is directly connected.

Clone this wiki locally