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


from fractions import Fraction
from math import ceil
from numpy.random.mtrand import randint
from Turbine.calc.lcm import lcm
        dataflow.set_ini_cons_rate_list(arc, [int(x * coef) for x in dataflow.get_ini_cons_rate_list(arc)])
        dataflow.set_threshold_list(arc, [int(x * coef) for x in dataflow.get_threshold_list(arc)])
        dataflow.set_ini_threshold_list(arc, [int(x * coef) for x in dataflow.get_ini_threshold_list(arc)])


def get_normalized_vector(dataflow):
    """Compute the normalization vector of an un-normalize graph.

    Return
    ------
    Return the the vector of coefficient for normalize the graph.
    """
    coef_list = {}

    lcm_rf = 1
    lcm_post_mult = 1
    for task in dataflow.get_task_list():
        lcm_rf = lcm(lcm_rf, dataflow.get_repetition_factor(task))
    for arc in dataflow.get_arc_list():
        if dataflow.is_sdf:
            rate = dataflow.get_prod_rate(arc)
        if dataflow.is_csdf:
            rate = sum(dataflow.get_prod_rate_list(arc))
        zi = lcm_rf / dataflow.get_repetition_factor(dataflow.get_source(arc))
        # print lcm_rf, "t"+str(dataflow.get_source(arc)), dataflow.get_repetition_factor(dataflow.get_source(arc))
        # print str(arc[0])+"->"+str(arc[1]), "zi", zi, "rate", rate, "ka", Fraction(numerator=zi, denominator=rate)
        coef_list[arc] = Fraction(numerator=zi, denominator=rate)
        if dataflow.is_csdf:
            for phase in dataflow.get_prod_rate_list(arc) + dataflow.get_cons_rate_list(arc):
                if float(coef_list[arc]) * float(phase) != int(coef_list[arc] * phase):

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


# Path: Turbine/algorithms/normalized.py
from fractions import Fraction
from math import ceil
from numpy.random.mtrand import randint
from Turbine.calc.lcm import lcm

        dataflow.set_ini_cons_rate_list(arc, [int(x * coef) for x in dataflow.get_ini_cons_rate_list(arc)])
        dataflow.set_threshold_list(arc, [int(x * coef) for x in dataflow.get_threshold_list(arc)])
        dataflow.set_ini_threshold_list(arc, [int(x * coef) for x in dataflow.get_ini_threshold_list(arc)])


def get_normalized_vector(dataflow):
    """Compute the normalization vector of an un-normalize graph.

    Return
    ------
    Return the the vector of coefficient for normalize the graph.
    """
    coef_list = {}

    lcm_rf = 1
    lcm_post_mult = 1
    for task in dataflow.get_task_list():
        lcm_rf = lcm(lcm_rf, dataflow.get_repetition_factor(task))
    for arc in dataflow.get_arc_list():
        if dataflow.is_sdf:
            rate = dataflow.get_prod_rate(arc)
        if dataflow.is_csdf:
            rate = sum(dataflow.get_prod_rate_list(arc))
        zi = lcm_rf / dataflow.get_repetition_factor(dataflow.get_source(arc))
        # print lcm_rf, "t"+str(dataflow.get_source(arc)), dataflow.get_repetition_factor(dataflow.get_source(arc))
        # print str(arc[0])+"->"+str(arc[1]), "zi", zi, "rate", rate, "ka", Fraction(numerator=zi, denominator=rate)
        coef_list[arc] = Fraction(numerator=zi, denominator=rate)
        if dataflow.is_csdf:
            for phase in dataflow.get_prod_rate_list(arc) + dataflow.get_cons_rate_list(arc):
                if float(coef_list[arc]) * float(phase) != int(coef_list[arc] * phase):

                    lcm_post_mult = lcm(lcm_post_mult, coef_list[arc].denominator)