simplest.py 1.77 KB
Newer Older
1
def dummy_edge(data):
2
    """Пустое ребро, не изменяет данные"""
3 4 5 6 7
    pass

def increment_a_edge(data):
    data['a'] += 1

8 9 10
def increment_a_double(data):
    data['a'] *= 2

11 12 13 14 15 16 17 18 19 20 21
def increment_a_array_edge(data):
    for i in range(len(data['a'])):
        data['a'][i] += 1

def increment_b_edge(data):
    data['b'] += 1

def decrement_a_edge(data):
    data['a'] -= 1

def nonzero_predicate(data):
22 23
    """Предикат: возвращает True если 'a' не равно 0"""
    return data['a'] != 0
24 25

def positiveness_predicate(data):
26
    return data['a'] > 0 
27 28

def nonpositiveness_predicate(data):
29 30 31
    return data['a'] <= 0 

def copy_to_c(data):
32 33 34
    data['c'] = data['a']

def selector_a_nonpositive(data):
Savva Golubitsky's avatar
Savva Golubitsky committed
35
    res = data['a'] <= 0
36 37
    return [res, not res]

38 39 40 41 42
def selector_a_positive(data):
    res = data['a'] > 0
    print(f"Selector check: a={data['a']}, continue={res}")
    return [res, not res]

43 44
def true_predicate(data):
    return True
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

def process_a(data):
    """Обработка ветки A: умножает a на 2"""
    if 'a' not in data:
        data['a'] = 0  # Инициализация по умолчанию
    data['a'] *= 2
    data['processed_by'] = 'A'

def process_b(data):
    """Обработка ветки B: устанавливает b в 10 (вместо добавления)"""
    data['b'] += 10
    data['processed_by'] = 'B'

def check_condition(data):
    """Предикат для выбора ветки (True - ветка A, False - ветка B)"""
    return data.get('value', 0) % 2 == 0  # Безопасное получение value

def branch_selector(data):
    """Селектор ветвления на основе check_condition"""
    condition = check_condition(data)
    return [condition, not condition]