import os
import matplotlib.pyplot as plt
results = {}

def errorfill(x, y, yerr, color=None, alpha_fill=0.3, ax=None):
    ax = ax if ax is not None else plt.gca()
    if color is None:
        color = ax._get_lines.color_cycle.next()
    ymin, ymax = yerr
    ax.plot(x, y, color=color)
    ax.fill_between(x, ymax, ymin, color=color, alpha=alpha_fill)


def generate(dim, l, mu = 5, la = 5, c = 0.5):
    axis = []
    resu = []
    resu_bars_mini = []
    resu_bars_maxi = []
    NB_IT = 5
    for i in range(50, 151, 50):
        results[i] = []
        axis.append(i)
        mini  =10
        maxi = 0
        for j in range(NB_IT):
            os.system('./main '+str(l)+" "+str(i)+ " " + str(dim) + " 1000 "+ str(mu)+ " "+ str(la)+ " " + str(c) + " > res_genetic_"+str(dim))
            r = open("res_genetic_"+str(dim), "r")
            res = float(r.readline())
            mini = min(res, mini)
            maxi = max(res, maxi)
            results[i].append(res)
        resu.append(sum(results[i])/NB_IT)
        resu_bars_mini.append(mini)
        resu_bars_maxi.append(maxi)

    resu_bars = [resu_bars_mini, resu_bars_maxi]
    print results
    print axis
    print resu
    print resu_bars

    #plt.errorbar(axis, resu, resu_bars, fmt='o')

    #errorfill(axis, resu, resu_bars)


dim = 3

generate(dim, 3, 5, 5, 0.1)
generate(dim, 3, 5, 5, 0.3)
generate(dim, 3, 5, 5, 0.5)
generate(dim, 3, 5, 5, 0.7)
generate(dim, 3, 5, 5, 0.9)

errorfill(axis, resu, resu_bars)

plt.show()
