示例#1
0
def crossover(population, fitness_value,
              probability_cross):  #BLX-alpha, alpha = 0.5
    for i in range(len(population)):
        child = 0
        parent1 = population[i]
        parent2 = population[st.selection(fitness_value)]
        if (probability_cross > random.random()):
            r = 2 * random.random() - 0.5
            if parent1 < parent2:
                child = (1 - r) * parent1 + r * parent2
            else:
                child = (1 - r) * parent2 + r * parent1
        if ft.fun(child) > ft.fun(parent1):
            population[i] = child
示例#2
0
def moduleTest(a, b, step):
    try:
        a = float(a)
        b = float(b)
        step = float(step)
    except ValueError:
        return ("Неверно введены значения")
    if (a > b or step <= 0):
        return ("Неверные условия теста!")

    resTable = PrettyTable()
    resTable.field_names = ["A", "B", "C", "x1", "x2"]

    i = j = k = a
    while (i <= b):
        while (j <= b):
            while (k <= b):
                fRes = fun(i, j, k)
                resTable.add_row(
                    [fRes["A"], fRes["B"], fRes["C"], fRes["x1"], fRes["x2"]])
                k += step
            j += step
            k = a
        i += step
        j = a

    res = "\nДиапазон: [%g; %g]\nШаг: %g\n" % (a, b,
                                               step) + resTable.get_string()
    return (res)
示例#3
0
def moduleTest(a, b, step):
    try:
        a = float(a)
        b = float(b)
        step = float(step)
    except ValueError:
        return ("Неверно введены значения")
    if (a > b or step <= 0):
        return ("Неверные условия теста!")

    resTable = PrettyTable()
    resTable.field_names = ["a", "b", "c", "Вид треугольника"]

    i = j = k = a
    while (i <= b):
        while (j <= b):
            while (k <= b):
                resTable.add_row([i, j, k, funRes(fun(i, j, k))])
                k += step
            j += step
            k = a
        i += step
        j = a

    res = "\nДиапазон: [%g; %g]\nШаг: %g\n" % (a, b,
                                               step) + resTable.get_string()
    return (res)
示例#4
0
def moduleTest():
    Hotp = randint(0, 23)
    Motp = randint(0, 59)
    Hp = randint(0, 100)
    Mp = randint(0, 100)
    res = "Hotp = %d\nMotp= %d\nHp = %d\nMp = %d\n" % (
        Hotp, Motp, Hp, Mp) + fun(Hotp, Motp, Hp, Mp)
    return (res)
示例#5
0
def chart():
    receive = request.json if request.method == "POST" else request.args
    reqdata = receive["graphic_selection"]
    type = reqdata["type"]
    date1 = reqdata["date_start"]
    date2 = reqdata["date_end"]
    datetime1 = str(date1["year"]) + '-' + str(date1["month"]) + '-' + str(
        date1["day"]) + ' 00:00:00'
    datetime2 = str(date2["year"]) + '-' + str(date2["month"]) + '-' + str(
        date2["day"]) + ' 00:00:00'
    print(type)
    print(date1)
    print(datetime1)
    print(date2)
    print(datetime2)
    result = fun(type, datetime1, datetime2)
    response = {"result": result}
    return jsonify(response)
示例#6
0
def simpleTest(A, B, C):
    fRes = fun(A, B, C)
    if (fRes["x1"] != "-" and fRes["x2"] != "-"):
        count = 2
    elif (fRes["x1"] != "-"):
        count = 1
        fRes["x2"] = ""
    else:
        count = 0
        fRes["x1"] = ""
        fRes["x2"] = ""

    res = "Уравнение\n(%s)x^2+(%s)x+(%s)=0" % (
        fRes["A"], fRes["B"], fRes["C"]) + "\nКоличество корней: " + str(count)
    if (count == 2):
        res += '\n' + str(fRes["x1"]) + '\n' + str(fRes["x2"])
    elif (count == 1):
        res += '\n' + str(fRes["x1"])

    return (res)
示例#7
0
def moduleTest(a, b, step):
    try:
        a = int(a)
        b = int(b)
        step = int(step)
    except ValueError:
        return ("Неверно введены значения")
    if (a > b or step <= 0):
        return ("Неверные условия теста!")

    resTable = PrettyTable()
    resTable.field_names = ["INPUT", "OUTPUT"]

    i = a
    while (i <= b):
        resTable.add_row([i, fun(i)])
        i += step

    res = resTable.get_string()
    return (res)
示例#8
0
def moduleTest(a, b, step):
    try:
        a = float(a)
        b = float(b)
        step = float(step)
    except ValueError:
        return ("Неверно введены значения")
    if (a > b or step <= 0):
        return ("Неверные условия теста!")

    resTable = PrettyTable()
    resTable.field_names = ["a", "r"]

    i = a
    while (i <= b):
        resTable.add_row(["%.5f" % i, "%.5f" % float(fun(i))])
        i += step

    res = "\nДиапазон: [%g; %g]\nШаг: %g\n" % (a, b,
                                               step) + resTable.get_string()
    return (res)
示例#9
0
import numpy as np
from matplotlib import pyplot
import function

x = np.linspace(0, 10)
pyplot.plot(10 * np.sin(5 * x) + 7 * np.cos(4 * x))
pyplot.show()

print function.fun(1.5105697566103822)
示例#10
0
if __name__ == '__main__':
    start = -2.*np.pi
    end = 1.*np.pi
    N = 6
    x = np.arange(start, end, 0.1)
    x = np.append(x, end)
    print('nodes,Lagrange_sq,Newton_sq,Lagrange_max,Newton_max')

    points = get_regular_interpolation_nodes(N, start, end)
    #points = get_czebyshev_interpolation_nodes(N, start, end)

    lagrange_polynomial = lagrange_interpolate(points)
    newton_polynomial = newton_interpolate(points)
    hermit_polynomial = hermit_interpolate(points)

    function_y = [fun(x) for x in x]
    lagrange_y = [lagrange_polynomial(x) for x in x]
    newton_y = [newton_polynomial(x) for x in x]
    hermit_y = [hermit_polynomial(x) for x in x]

    x_points, y_points = zip(*points)

    print('{0},{1},{2},{3},{4}'.format(N,
         calculate_mean_square_error(x, function_y, lagrange_y), calculate_mean_square_error(x, function_y, newton_y),
         calculate_max_error(x, function_y, lagrange_y), calculate_max_error(x, function_y, newton_y)))

    print('{0},{1},{2}'.format(N,
                               calculate_mean_square_error(x, function_y, hermit_y),
                               calculate_max_error(x, function_y, hermit_y))
          )
示例#11
0
def simpleTest(Hotp, Motp, Hp, Mp):
    res = fun(Hotp, Motp, Hp, Mp)
    return (res)
示例#12
0
def simpleTest(a):
    res = fun(a)
    return ("r = %s * 1/12 * sqrt(3) * (3 + sqrt(5)) = %s" % (a, res))
示例#13
0
def simpleTest(x):
    res = fun(x)
    return ("y = exp^(sqrt(%s+sqrt(%s))) = %s" % (x, x, res))
示例#14
0
def simpleTest(a, b, c):
    res = funRes(fun(a, b, c))
    return (res)
示例#15
0
def simpleTest(sum):
    res = fun(sum)
    return (res)