<gh_stars>0
from itertools import product
from os.path import join as path_join
import sys

import matplotlib.pyplot as plt
import numpy as np

from evolution import Evolution, get_random_points
from cec2017.functions import f4

if len(sys.argv) != 2:
    sys.exit("Usage: python visualize.py DIRECTORY")

# Create a view of the function

_x_arr = _y_arr = np.arange(-100, 101, 5)
X, Y = np.meshgrid(_x_arr, _y_arr)
Z = np.empty(X.shape)
for i, j in product(range(X.shape[0]), range(X.shape[1])):
    Z[i, j] = f4(np.array([X[i, j], Y[i, j]]))

# Get the algorithm
e = Evolution(f4, population_size=30, mutation_factor=1.0, elite_count=10)

initial_pop = e.rate_points(get_random_points(50, 100, 2))

for idx, pop in enumerate(e.evolve(initial_pop)):
    plt.clf()
    plt.xlim(-100, 100)
    plt.ylim(-100, 100)
    plt.contourf(X, Y, Z, levels=50)
    plt.plot([p.coords[0] for p in pop], [p.coords[1] for p in pop], ".k")
    plt.savefig(path_join(sys.argv[1], f"{idx:0>3}.png"), dpi=175)

from itertools import product
from os.path import join as path_join
import sys

import matplotlib.pyplot as plt
import numpy as np

from evolution import Evolution, get_random_points
from cec2017.functions import f4

if len(sys.argv) != 2:
    sys.exit("Usage: python visualize.py DIRECTORY")

# Create a view of the function

_x_arr = _y_arr = np.arange(-100, 101, 5)
X, Y = np.meshgrid(_x_arr, _y_arr)
Z = np.empty(X.shape)
for i, j in product(range(X.shape[0]), range(X.shape[1])):
    Z[i, j] = f4(np.array([X[i, j], Y[i, j]]))

# Get the algorithm
e = Evolution(f4, population_size=30, mutation_factor=1.0, elite_count=10)

initial_pop = e.rate_points(get_random_points(50, 100, 2))

for idx, pop in enumerate(e.evolve(initial_pop)):
    plt.clf()
    plt.xlim(-100, 100)
    plt.ylim(-100, 100)
    plt.contourf(X, Y, Z, levels=50)
    plt.plot([p.coords[0] for p in pop], [p.coords[1] for p in pop], ".k")
    plt.savefig(path_join(sys.argv[1], f"{idx:0>3}.png"), dpi=175)
# Create a view of the function # Get the algorithm