def troll(E, n, i, a):
    above = barrier()
    prev_lead = barrier()
    if i + 1 not in (E + [n + 1]):
        above = troll(E, n, i + 1, a)
    if i in E and i != 0:
        prev_lead = troll(E, n, E[E.index(i) - 1], a)

    while True:
        # Awake and light off - a[i] = 0
        while next(above):
            yield True
        a[i] = 1
        yield True

        # Asleep and light on - a[i] = 1
        yield next(prev_lead)

        # Awake and light on - a[i] = 1
        a[i] = 0
        yield True

        # Asleep and light off - a[i] = 0
        while next(above):
            yield True
        yield next(prev_lead)
Esempio n. 2
0
def test():
    print("""Выберете функцию которую нужно минимизировать:
    1 - 1.1
    2 - 1.2
    3 - 1.3
    4 - 2.1
    5 - 2.2
    """)
    chosenFoon = int(input("Ваш выбор: "))

    print("\nМинимизируемая функция:", end=" ")

    if chosenFoon == 1:
        print(functionFormul[0])
        print("Метод штрафных функций: ")
        res = penalty.penalty([0., 0.], f, 0.1, 10, 0.01,
                              restrictionsOfEquality[1],
                              restrictionsOfNotEquality[1])

        out(res, f(res))

    elif chosenFoon == 2:
        print(functionFormul[0])
        print("Метод штрафных функций: ")
        res = penalty.penalty([0., 1.], f, 0.1, 10, 0.01,
                              restrictionsOfEquality[2],
                              restrictionsOfNotEquality[2])

        out(res, f(res))

    elif chosenFoon == 3:
        print(functionFormul[0])
        print("Метод штрафных функций: ")
        res = penalty.penalty([2., 2.], f, 0.1, 10, 0.01,
                              restrictionsOfEquality[3],
                              restrictionsOfNotEquality[3])

        out(res, f(res))

    elif chosenFoon == 4:
        print(functionFormul[1])
        print("Метод барьерных функций: ")
        res = barrier.barrier([11., 11.], f1, 100., 0.5, 0.005,
                              restrictionsOfNotEquality[4])

        out(res, f1(res))

    elif chosenFoon == 5:
        print(functionFormul[2])

        print("Метод штрафных функций: ")
        res = penalty.penalty([20., 10.], f2, 10., 0.5, 0.01, [],
                              restrictionsOfNotEquality[5])
        out(res, f2(res))

    else:
        print("такой нет")

    print()
def troll(n, k, a, coroutines):
    next_up = coroutines[k + 1] if k + 1 < n else barrier()
    next_down = coroutines[k + 2] if k + 2 < n else barrier()

    if a[k] == 1 or k % 2 == 1:
        next_up, next_down = next_down, next_up

    while True:
        while next(next_up):
            yield True
        a[k] = 1 - a[k]
        yield True

        while next(next_down):
            yield True
        yield False

        next_up, next_down = next_down, next_up
Esempio n. 4
0
def troll(n, k, a):
    neighbour = troll(n, k + 1, a) if k < n else barrier()

    while True:
        # awake0:
        while next(neighbour):
            yield True
        a[k] = 1
        yield True

        # asleep1:
        yield False

        # awake1:
        a[k] = 0
        yield True

        # asleep0
        while next(neighbour):
            yield True
        yield False
Esempio n. 5
0
def troll(n, k, a):
    neighbour = troll(n, k + 1, a) if k < n else barrier()

    while True:
        # awake0:
        while next(neighbour):
            yield True
        a[k] = 1
        yield True

        # asleep1:
        yield False

        # awake1:
        a[k] = 0
        yield True

        # asleep0
        while next(neighbour):
            yield True
        yield False
Esempio n. 6
0
def troll(a, i):
    previous = troll(a, i - 1) if i > 0 else barrier()
    while True:
        a[i] = 1 - a[i]
        yield True
        yield next(previous)
Esempio n. 7
0
        minimumPoint = penalty.penalty([0., 0.], test_f, 0.1, 10, 0.01,
                                       restrictionsOfEquality[0],
                                       restrictionsOfNotEquality[0])
        printValues(minimumPoint, 1)

    elif chosenFoon == 2:
        print("Метод штрафных функций: ")
        minimumPoint = penalty.penalty([0., 1.], test_f, 0.1, 10, 0.01,
                                       restrictionsOfEquality[1],
                                       restrictionsOfNotEquality[1])
        printValues(minimumPoint, 2)

    elif chosenFoon == 3:
        print("Метод барьерных функций: ")
        minimumPoint = penalty.penalty([0., 1.], test_f, 0.1, 10, 0.01, [],
                                       restrictionsOfNotEquality[2])
        printValues(minimumPoint, 3)

    elif chosenFoon == 4:
        print("Метод  штрафных функций: ")
        minimumPoint = penalty.penalty([0, 0], f1, 0.1, 10, 0.01,
                                       restrictionsOfEquality[3],
                                       restrictionsOfNotEquality[3])
        printValues(minimumPoint, 4)

    elif chosenFoon == 5:
        print("Метод барьерных функций: ")
        minimumPoint = barrier.barrier([3, 1], f2, 100, 0.5, 0.01,
                                       restrictionsOfNotEquality[4])
        printValues(minimumPoint, 5)