# Path: Turbine/calc/lcm.py
# def lcm(a, b):
#     return abs(a * b) / gcd(a, b)


from fractions import gcd
from Turbine.calc.lcm import lcm
from random import shuffle, randint, sample
import logging
import numpy

    gcd_value = 0

    n = dataflow.get_task_count()
    div = numpy.random.exponential(0.25)
    div = n + int(div * n)
    rv_list = numpy.random.multinomial(sum_rv, numpy.ones(n) / div)
    __get_non_zero_list(rv_list)

    # Modify the two last integers of the list to get a gcd equal to 1
    if gcd_value != 1:
        logging.info("recalculate GCD")
        while reduce(gcd, [gcd_value, rv_list[-1], rv_list[-2]]) != 1:
            rv_list[-1] -= 1
            rv_list[-2] += 1

    shuffle(rv_list)
    for task in dataflow.get_task_list():
        dataflow.set_repetition_factor(task, rv_list[task])
    return


def __generate_rates(dataflow, c_param):
    """Generate weights of the dataflow.
    """
    logging.info("Generate task wight")
    k = 0

    lcm_value = 1
    for task in dataflow.get_task_list():

# Path: Turbine/calc/lcm.py
# def lcm(a, b):
#     return abs(a * b) / gcd(a, b)


# Path: Turbine/generation/rates_computation.py
from fractions import gcd
from Turbine.calc.lcm import lcm
from random import shuffle, randint, sample
import logging
import numpy


    gcd_value = 0

    n = dataflow.get_task_count()
    div = numpy.random.exponential(0.25)
    div = n + int(div * n)
    rv_list = numpy.random.multinomial(sum_rv, numpy.ones(n) / div)
    __get_non_zero_list(rv_list)

    # Modify the two last integers of the list to get a gcd equal to 1
    if gcd_value != 1:
        logging.info("recalculate GCD")
        while reduce(gcd, [gcd_value, rv_list[-1], rv_list[-2]]) != 1:
            rv_list[-1] -= 1
            rv_list[-2] += 1

    shuffle(rv_list)
    for task in dataflow.get_task_list():
        dataflow.set_repetition_factor(task, rv_list[task])
    return


def __generate_rates(dataflow, c_param):
    """Generate weights of the dataflow.
    """
    logging.info("Generate task wight")
    k = 0

    lcm_value = 1
    for task in dataflow.get_task_list():

        lcm_value = lcm(lcm_value, dataflow.get_repetition_factor(task))