'Return a text-based representation of the tree.
Parameters
node : LP_SIMPLE_TREE_NODE, optional (default=None)
Tree node. Used to construct representation of the
tree under this node.
If not provided, node is considered root node.
level : int, optional (defaul=0)
Level of the node. Used for line indentation.
Returns
tree : str
Text-based representation of the tree.'

def to_string(self, node=None, level=0):

    if (node is None):
        if (self.node is None):
            return '(null    node)'
        else:
            node = self.node
    n = node.contents
    if (self.type == Classification):
        decimals = 1
    else:
        decimals = self.domain.class_var.number_of_decimals
    if (n.children_size == 0):
        if (self.type == Classification):
            node_cont = [round(n.dist[i], decimals) for i in range(self.cls_vals)]
            index = node_cont.index(max(node_cont))
            major_class = self.cls_vars[0].values[index]
            return ('    -->    %s    (%s)' % (major_class, node_cont))
        else:
            node_cont = ((str(round((n.sum / n.n), decimals)) + ':    ') + str(n.n))
            return ('    -->    (%s)' % node_cont)
    else:
        node_desc = self.dom_attr[n.split_attr].name
        if (self.type == Classification):
            node_cont = [round(n.dist[i], decimals) for i in range(self.cls_vals)]
        else:
            node_cont = ((str(round((n.sum / n.n), decimals)) + ':    ') + str(n.n))
        ret_str = (('\n' + ('            ' * level)) + ('%s    (%s)' % (node_desc, node_cont)))
        for i in range(n.children_size):
            attr = self.dom_attr[n.split_attr]
            if attr.is_continuous:
                split = ('<=' if ((i % 2) == 0) else '>')
                split += str(round(n.split, 5))
                ret_str += (('\n' + ('            ' * level)) + (':    %s' % split))
            else:
                ret_str += (('\n' + ('            ' * level)) + (':    %s' % attr.values[i]))
            ret_str += self.to_string(n.children[i], (level + 1))
        return ret_str
