コード例 #1
0
def lvxm(P, i, b, lb, ub, par):
    alpha, beta, pm, etam = par[0], par[1], par[2], par[3]
    np.random.shuffle(b)
    p1 = P[i]
    p2 = P[b[0]]
    y = p1 + alpha * levy(beta, len(p1)) * (p1 - p2)
    y = repair(y, lb, ub)
    y = poly_mutation(y, lb, ub, etam, pm)
    y = repair(y, lb, ub)
    return y
コード例 #2
0
def dem(P, i, b, lb, ub, par):
    f, pm, etam = par[0], par[1], par[2]
    np.random.shuffle(b)
    p1 = P[i]
    p2, p3 = P[b[0]], P[b[1]]
    y = p1 + f * (p2 - p3)
    y = repair(y, lb, ub)
    y = poly_mutation(y, lb, ub, etam, pm)
    y = repair(y, lb, ub)
    return y
コード例 #3
0
def ga(P, i, b, lb, ub, par):
    pc, pm, etac, etam = par[0], par[1], par[2], par[3]
    np.random.shuffle(b)
    p1, p2 = P[b[0]], P[b[1]]
    if np.random.uniform(0, 1) < pc:
        c1, c2 = sbx_crossover(p1, p2, lb, ub, etac)
    else:
        c1, c2 = p1, p2
    if np.random.uniform(0, 1) < 0.5:
        y = c1
    else:
        y = c2
    y = repair(y, lb, ub)
    y = poly_mutation(y, lb, ub, etam, pm)
    y = repair(y, lb, ub)
    return y
コード例 #4
0
def lvx(P, i, b, lb, ub, par):
    alpha, beta = par[0], par[1]
    np.random.shuffle(b)
    p1 = P[i]
    p2 = P[b[0]]
    y = p1 + alpha * levy(beta, len(p1)) * (p1 - p2)
    y = repair(y, lb, ub)
    return y
コード例 #5
0
def de(P, i, b, lb, ub, par):
    f = par[0]
    np.random.shuffle(b)
    p1 = P[i]
    p2, p3 = P[b[0]], P[b[1]]
    y = p1 + f * (p2 - p3)
    y = repair(y, lb, ub)
    return y
コード例 #6
0
def de_normal(P, i, b, lb, ub, par):
    f = par[0]
    np.random.shuffle(b)
    p1 = P[i]
    p2, p3 = P[b[0]], P[b[1]]
    y = np.zeros((len(p1), 1))
    for j in range(len(p1)):
        y[j] = p1[j] + f * np.random.normal(1) * (p2[j] - p3[j])
    y = repair(y, lb, ub)
    return y
コード例 #7
0
def ga(P, rank, distances, lb, ub, par):
    pc, pm, etac, etam, = par[0], par[1], par[2], par[3]
    Q = []
    while len(Q) < len(P):
        p = []
        for _ in range(2):
            idx = np.arange(len(P))
            np.random.shuffle(idx)
            t = idx[:2]
            res = bin_tournament(t, rank, distances)
            p.append(res)
        p1, p2 = P[p[0]], P[p[1]]
        if np.random.uniform(0, 1) <= pc:
            c1, c2 = sbx_crossover(p1, p2, lb, ub, etac)
        else:
            c1, c2 = p1, p2
        c1, c2 = repair(c1, lb, ub), repair(c2, lb, ub)
        c1 = poly_mutation(c1, lb, ub, etam, pm)
        c2 = poly_mutation(c2, lb, ub, etam, pm)
        c1, c2 = repair(c1, lb, ub), repair(c2, lb, ub)
        Q.append(c1)
        Q.append(c2)
    return Q