from random import randint
from math   import log
import matplotlib.pyplot as plt
import argument as arg

def   maximum( l  ) :
	score = l[0]
	res   = 1
	for v in l :
		if ( v < score ) :
			score = v
			res   = res + 1  
	return res

arg.cmdline()

x = []
y = []
z = []
pire = []
favo = []

for n in  range(2 , arg.iteration ) :
    cpt = 0
    min = n
    max = 0
    for  r in range( arg.repetition ) :
        liste = []
        for i in range( n ) :
            liste.append( randint(0, 2*n ) )
        maj = maximum( liste ) 
        cpt += maj
        if maj < min :
            min = maj
        if maj > max :
            max = maj	
    x.append( n )
    z.append( log(n)   )
    y.append( cpt / arg.repetition )
    favo.append( min )
    pire.append( max )


plt.title("Analyse de l'algorithme Maximum")
plt.ylabel("nombre de mise à jour")
plt.xlabel("taille des instances")
plt.grid()
plt.plot(x, y)
plt.plot(x, z)
plt.plot(x, pire)
plt.plot(x, favo)
plt.show()
plt.close()


