From 3e43684937a75e0f8817f6de255facd690cdea68 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Thu, 9 May 2019 16:46:24 +0200 Subject: [PATCH] Feat(random): Start random tree generation --- mapytex/calculus/core/random/__init__.py | 67 ++++++++++++++++++++++++ mapytex/calculus/core/random/str_gene.py | 39 -------------- 2 files changed, 67 insertions(+), 39 deletions(-) delete mode 100644 mapytex/calculus/core/random/str_gene.py diff --git a/mapytex/calculus/core/random/__init__.py b/mapytex/calculus/core/random/__init__.py index e69de29..c9f3080 100644 --- a/mapytex/calculus/core/random/__init__.py +++ b/mapytex/calculus/core/random/__init__.py @@ -0,0 +1,67 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# vim:fenc=utf-8 +# +# Copyright © 2017 lafrite +# +# 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 diff --git a/mapytex/calculus/core/random/str_gene.py b/mapytex/calculus/core/random/str_gene.py deleted file mode 100644 index 7f857a7..0000000 --- a/mapytex/calculus/core/random/str_gene.py +++ /dev/null @@ -1,39 +0,0 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- -# vim:fenc=utf-8 -# -# Copyright © 2017 lafrite -# -# 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