Ejemplo n.º 1
0
    w = 0
    for i, _ in enumerate(x):
        w = w + (x[i] * W[i])

    # penalizo sobrepasar el peso maximo
    return c if w <= M else 0


o = BCSO(test_function,
         dimension=N,
         maxiter=150,
         maximize=True,
         workers=1,
         threads=1,
         cats=500,
         mr=0.5,
         smp=20,
         cdc=0.7,
         pmo=0.7,
         spc=False,
         omega=0.5,
         weight=1)

best = o.run()

print(best[BCSO.BEST_FUNC_TEST_VALUE])

decode = []

for i, x in enumerate(best[BCSO.BEST_CAT_POSITION]):
    if x:
Ejemplo n.º 2
0
        for j, _ in enumerate(x):
            n = n + (matrix[i][j] * x[j])

        if n == 0:
            c = c + 100000

    return c


o = BCSO(test_function,
         dimension=n_group,
         maxiter=12,
         workers=1,
         threads=1,
         cats=100,
         mr=0.5,
         smp=10,
         cdc=0.5,
         pmo=0.1,
         spc=False,
         omega=0.5,
         weight=1,
         debug=False)

best = o.run()

print(best[BCSO.BEST_FUNC_TEST_VALUE])

decode_covering = []

for i, x in enumerate(best[BCSO.BEST_CAT_POSITION]):
    if x:
Ejemplo n.º 3
0
        for j, _ in enumerate(x):
            n = n + (matrix[i][j] * x[j])

        if n == 0:
            c = c + 1000

    return c


o = BCSO(test_function,
         dimension=n_group,
         maxiter=300,
         workers=1,
         threads=1,
         cats=150,
         mr=0.5,
         smp=20,
         cdc=0.7,
         pmo=0.1,
         spc=False,
         omega=0.5,
         weight=1)

best = o.run()

print(best[BCSO.BEST_FUNC_TEST_VALUE])

decode_covering = []

for i, x in enumerate(best[BCSO.BEST_CAT_POSITION]):
    if x:
Ejemplo n.º 4
0
from cso import BCSO

dataset = [10, -10, 20, 1, 3, 25, -100, 20]

def test_function(x, *args, **kwargs):

    c = 0
    for i, f in enumerate(x):
        if f == 1:
            c = c + dataset[i]

    return c

omin = BCSO(test_function,
        dimension=len(dataset), maximize=False, n_cats=100, smp=10, maxiter=100, cdc=1, mr=0.5)
omax = BCSO(test_function,
        dimension=len(dataset), maximize=True, n_cats=100, smp=10, maxiter=100, cdc=1, mr=0.5)

best_min = omin.run()
best_max = omax.run()

print(dataset)
print()
print('min', best_min)
print()
print('max', best_max)