Feat(random): Start random tree generation

This commit is contained in:
Bertrand Benjamin 2019-05-09 16:46:24 +02:00
parent 5df0b0c21e
commit eb072bd511
2 changed files with 67 additions and 39 deletions

View File

@ -0,0 +1,67 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2017 lafrite <lafrite@Poivre>
#
# Distributed under terms of the MIT license.
"""
Tools to extract random nodes, random variables, generate random values and
fill new trees
Flow
----
Tree with RdLeaf
|
| Extract nodes
|
List of nodes to generate
|
| extract_rv
|
List random variables to generate
|
| Generate
|
Dictionnary of generated random variables
|
| Compute nodes
|
Dictionnary of computed nodes
|
| Replace
|
Tree with RdLeaf replaced by generated values
"""
def extract_rv(node_list):
""" Extract the set of random values from the node list
:param node_list: list of nodes
:return: set of random values
:example:
>>> node_list = ["{a}", "{a*k}"]
>>> extract_rv(node_list)
{"a", "k"}
"""
pass
def compute_nodes(node_list, generated_values):
""" Compute nodes from generated random values
:param generated_values: Dictionnary of name:generated value
:param node_list: list of nodes
:return: Dictionnary of evaluated nodes from generated values
:example:
>>> node_list = ["{a}", "{a*k}"]
>>> generated_values = {"a":2, "k":3}
>>> compute_nodes(node_list, generated_values)
{"{a}": 2, "{a*k}": 6}
"""
pass

View File

@ -1,39 +0,0 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2017 lafrite <lafrite@Poivre>
#
# Distributed under terms of the MIT license.
"""
Function to create random strings
:example:
>>> form = "{a} / {b} + {c} / {k*b}"
>>> conditions = [
... "abs({b}) != 1",
... "{d} > 1",
... "{b} != {d}",
... "gcd({a},{b}) == 1",
... "gcd({c},{k*b}) == 1",
... ]
>>> #random_str(form, conditions)
>>> form = "{a:int}x + {b:fraction}"
>>> conditions = [
... "{b.denom} > 2",
... ]
>>> #random_str(form, conditions)
"""
import random
__all__ = []
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del