<jupyter_start><jupyter_text>Курсач по ЭМППИС<jupyter_code>import random
import numpy as np
import copy
from matplotlib import pyplot as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Таблица<jupyter_code>Table = [
# (902000, 30000, 1158000, 1340202),
# (462000, 200000, 960000, 841616),
# (465000, 190000, 790000, 850112),
# (545000, 200000, 9098000, 949828),
# (311000, 350000, 396000, 566580),
# (675000, 29000, 984000, 1072609),
# (128000, 26000, 189000, 326461),
# (105000, 340000, 103000, 250755),
# (215000, 310000, 285000, 443086),
# (31000, 62000, 70000, 144563),
# (42000, 190000, 90000, 199759),
# (78000, 310000, 73000, 215763),
# (21000, 280000, 50000, 112703),

# (50000, 290000, 84000, 170887),
# (786000, 350000, 987000, 1180378),
# (97000, 270000, 156000, 268312),
# (125000, 270000, 239000, 316864),
# (1008000, 340000, 1383000, 1444587),
#     (1, 1.5),
#     (2, 12),
#     (3, 40.5),
#     (4, 96),
#     (5, 187.5),
#     (6, 324),
#     (7, 514.5),
#     (8, 768),
#     (9, 1093.5),
#     (10, 1500),
#     (11, 1996.5),
#     (12, 2592),
#     (13, 3295.5),
#     (14, 4116),
#     (15, 5062.5),
#     (16, 6144),
#     (17, 7369.5),
#     (18, 8748),
#     (19, 10288.5),
#     (20, 12000),
#     (21, 13891.5),
#     (22, 15972),
#     (23, 18250.5),
#     (24, 20736),
#     (25, 23437.5),
#     (26, 26364),
#     (27, 29524.5),
#     (28, 32928),
#     (29, 36583.5),
#     (30, 40500),
    
#     (25.9, 117.6),
#     (24.6, 117.6),
#     (7.7, 31.2),
#     (8.2, 36),
#     (9.7, 25.2),
#     (2.2, 8.4),
#     (3.5, 10.8),
#     (66.6, 352.8),
#     (7.5, 72),
#     (20, 72),
#     (6, 24),
#     (100, 360),
#     (11.3, 36),
#     (100, 215),
#     (20, 48),
#     (100, 360),
#     (150, 324),
#     (31.5, 60),
#     (15, 48),
#     (32.5, 60),
#     (19.7, 60),
#     (66.6, 300),
#     (29.5, 120),
#     (15, 90),
#     (38, 210),
#     (10, 48),
#     (15.4, 70),
#     (48.5, 239),
#     (16.3, 82),
#     (12.8, 62),
#     (32.6, 170),
#     (35.5, 192),
#     (5.5, 18),
#     (10.4, 50),
#     (14, 60),
#     (6.5, 42),
#     (13, 60),
#     (90, 444),
#     (8, 42),
#     (16, 114),
#     (177.9, 1248),
#     (302, 2400),
#     (282.1, 1368),
#     (284.7, 973),
#     (79, 400),
#     (423, 2400),
#     (190, 420),
#     (47.5, 252),
#     (21, 107),
#     (78, 571.4),
#     (11.4, 98.8),
#     (19.3, 155),
#     (101, 750),
#     (219, 2120),
#     (50, 370),
#     (227, 1181),
#     (70, 278),
#     (0.9, 8.4),
#     (980, 4560),
#     (350, 720),
#     (70, 458),
#     (271, 2460),
#     (90, 162),
#     (40, 150),
#     (137, 636),
#     (150, 882),
#     (339, 444),
#     (240, 192),
#     (144, 576),
#     (151, 432),
#     (34, 72),
#     (98, 300),
#     (85, 300),
#     (20, 240),
#     (111, 600),
#     (162, 756),
#     (352, 1200),
#     (165, 97),
#     (60, 409),
#     (100, 703),
#     (32, 1350),
#     (53, 480),
#     (41, 599),
#     (24, 430),
#     (165, 4178.2),
#     (65, 1772.5),
#     (70, 1645.9),
#     (50, 1924.5),
#     (7.25, 648),
#     (233, 8211),
#     (16.3, 480),
#     (6.2, 12),
#     (3, 38),
    (21000, 50000),
    (50000, 84000),
    (786000, 987000),
    (97000, 156000),
    (125000, 239000),
    (1008000, 1383000),
    (902000, 115800),
    (462000, 96000),
    (465000, 790000),
    (545000, 908000),
    (311000, 396000),
    (675000, 984000),
    (128000, 189000),
    (105000, 103000),
    (215000, 285000),
    (31000, 70000),
    (42000, 90000),
    (78000, 73000),
    
]
print(Table)
# Удалить повторяющиеся элементы
Table = list(set(Table))
# Граница 70/30
border = int(len(Table)*0.7)
test = Table[border:]
train = Table[:border]
print(test)
print(train)<jupyter_output>[(21000, 50000), (50000, 84000), (786000, 987000), (97000, 156000), (125000, 239000), (1008000, 1383000), (902000, 115800), (462000, 96000), (465000, 790000), (545000, 908000), (311000, 396000), (675000, 984000), (128000, 189000), (105000, 103000), (215000, 285000), (31000, 70000), (42000, 90000), (78000, 73000)]
[(902000, 115800), (50000, 84000), (462000, 96000), (465000, 790000), (786000, 987000), (21000, 50000)]
[(125000, 239000), (128000, 189000), (105000, 103000), (215000, 285000), (311000, 396000), (42000, 90000), (97000, 156000), (1008000, 1383000), (545000, 908000), (31000, 70000), (78000, 73000), (675000, 984000)]<jupyter_text>Фитнес функция<jupyter_code># Манхэттен – метрика городских кварталов
def MD(x, T=train):
    s = 0.0
    for el in T:
        s += abs(x[0] * el[0] ** x[1] - el[1])
        # print(x[0], x[1],el[0] ** x[1] - el[1], s)
    return s
# def MD(x, T=train,verbose=False):
#     s = 0.0
#     if verbose:
#         print("REAL", "COCOMO", "RA", "MD")
#         for el in T:
#             F=x[0] * (el[0] ** x[1])*el[1]
#             md=abs(F - el[2])
#             s += md 
#             print(el[2], el[3], F, md)

#     else:
#         for el in T:
#             s += abs(x[0] * (el[0] ** x[1])*el[1] - el[2])
#     # print(x[0], x[1],el[0] ** x[1] - el[1], s)
#     return s<jupyter_output><empty_output><jupyter_text>Генератор рандомных значений<jupyter_code>def generate(N, lb=0.0, rb=10.0):
    r = []
    for i in range(N):
        r.append((random.uniform(lb, rb), random.uniform(lb, rb)))

    return r<jupyter_output><empty_output><jupyter_text>Роевой алгоритм<jupyter_code># N - кол-во особей
# T - кол-во поколений
# c1,c2 - ветер
def ra(N=70, T=200, c1=1, c2=1):
    Y = np.array(generate(N))
    X = Y.copy()
    # X = Y
    ymax = copy.copy(Y[0])
    v = [0] * N

    x0 = []
    x1 = []

    for i in range(T):
        x0.append(i)
        x1.append(MD(ymax))
        for j in range(N):
            if MD(X[j]) < MD(Y[j]):
                Y[j] = X[j]

            if MD(Y[j]) < MD(ymax):
                ymax = Y[j]
                # ymax = copy.copy(Y[j])
                # print(MD(ymax))

        for j in range(N):
            v[j] = v[j] + c1 * random.uniform(0.0, 1.0) * (Y[j] - X[j]) + c2 * random.uniform(0.0, 1.0) * (ymax - X[j])
            X[j] = X[j] + v[j]

    x0.append(T+1)
    x1.append(MD(ymax))
    return [ymax,x0,x1]
maximum, x0, x1 = ra(70, 200)
print(maximum, MD(maximum, test))
plt.plot(x0,x1)<jupyter_output>/home/diamon/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:5: RuntimeWarning: overflow encountered in double_scalars
  """
{'fraction_non_alphanumeric': 0.23208083359646353, 'fraction_numerical': 0.288127565519419, 'mean_word_length': 2.3554025423728815, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '635200', 'license': 'MIT', 'n_tokens_mistral': 4208, 'n_tokens_neox': 2964, 'n_words': 632, 'path': 'main.ipynb', 'repo_name': 'zhilyaev/evolutionary-swarm-algorithm', 'size': '6334'}