Skip to content
Snippets Groups Projects
Commit 3bac5ccc authored by Gontier Antonin's avatar Gontier Antonin :fox:
Browse files

Ajout du dossier agents

parent f781d91e
No related branches found
No related tags found
No related merge requests found
Showing with 521 additions and 0 deletions
22 serialization::archive 12 0 0 0 0 1344 18 8 32 10 320 0 1013583046238459020 3388985591207744950 2982613052529104261 1864945918558131434 369744756122932655 1601167026102129766 1357917267247977783 3370806482810786961 4024703252783977860 5866142337366053967 1635191909183706673 4510173093021865093 2830831956759303670 2082903970093323687 1106101554977297650 2961194032337605943 4753126379796944350 1131345111509947656 34242241459475605 3884497811312891410 4391488520413434900 5253673033509688500 1369839634286433285 2491746809223205936 3577347170709623988 195508185551033788 4851825073903261234 219179547391022551 699520991998760468 3028911271070094660 5491333425154676083 2911983441693234683 1523825074760209460 5571375573589153122 1975476549663347860 1707751877805593649 6172111851610526774 4708712881789359606 655557046124729421 423375794029810742 1837789983069558229 6211781738614773236 2101013813157746131 3508584155977110581 2306126724512765474 3090180531948934269 5643892489321403505 3101318856787154072 5352285494705968240 5126955434849588533 2987761379873576129 126386993273361684 3162600815337198932 2600176112718894225 2208820394684110238 4086897804700865813 5818881914795283555 5239035673976722736 2029561780522702293 3019397630889874614 1324476815567115344 2307815962974704833 5264896551309989279 4319246056757875758 3802984655511049638 2063137585613395423 5468480601078650004 1254752556205888996 320756828209402998 4170424528939996593 4436923917348984000 3321418929537734185 5217399620061746238 1101501778801579563 3713960004808005085 5634791296610456758 5258063223137326651 1887134060727883295 5661704707715421561 1311143909958571357 1537668527475217952 3050439779684996374 5411046710090290705 1607990127540753465 4666932642613810390 1189620607334667434 1225137039767721455 5350567663035143480 4814757223959909754 1540271423523378361 252402383931266313 6147437039529285172 2586915903545529756 5306954317375985041 3825814511681918076 2091562146584941973 5756904515390657617 5580429227473917481 4089587504659190867 2852927185952462193 2212848992052991252 2405391496742720662 1731253689900094959 5135266203824968782 3997330933795279968 2726663443135157687 4994900482007356565 5607274481568765113 3684853328455783702 2857681373051638937 3301581508886484432 4157412225905939736 831597348907963914 4225311201143510356 4688538110726297107 1018176933792241201 3794667377838412955 6179618687116563614 3649580992895112338 3783823673546429555 5092056881538061522 1631564656017593751 3153893114312414349 4713728132019475649 667494271821960438 2735034158604965082 3388767899809109539 4987937251808826794 5157513865718289974 4127863122306880924 3342713438480291326 6212623909193634962 2420331046159275334 726632351898391700 4976791829474629007 3708867903528293909 3761291200146429115 4456564382559261777 5388176811180545190 3400818648233301459 1254497164035675638 4899969344114382311 6112836938355791124 538350345968113136 4581650979349943649 3740606909591541093 2028930185714128165 604110476428891367 2216619373307057456 1577812188839204052 1884849913986372734 3702061869641586109 1550459581306295642 1568730332297548956 1740151442365371964 2943728980841321636 821215097931748656 4641137347442758835 5120835132434634069 5361561698872940053 2400922656424678671 1353849062429382128 4857622861566793116 1862867315459708138 4488171593951139098 5136942133054952620 4862037179864503862 5312165229770528257 343838726706779258 2865753164046489011 63583969056838941 3576498757834953964 5983064182602618293 596557681177384499 6163385822786639079 1236424418396296499 2139290120713688371 3279661156366177817 4683810441970669075 2100351587772159061 16182899782341713 4113227385976640769 5677084947201938955 1824959096035398827 4239840123314230381 6028114846219228486 465452337925051730 4848656898766460208 5036879838289384771 3257237935269631227 2578401153332270292 4636071079853315408 3275434466558268818 5193637755727435080 2812948409034495513 2510922080523179537 1524381409741591680 424761198022546638 1604772890277729654 4820657767609390295 2573182184962119058 2460707299898643950 3535962490096899340 6159379065067328715 5856748423160714583 5415053489447556412 4549830040024864079 5793237100721722773 1317213193912898817 5793686187845276826 2506651239939429500 987693572612248853 4289143619596211412 3738068661802521719 3207981761585632712 2573831704102524410 2389831293012202962 1464509092897248690 4856646931388323352 668479105265849709 3929242957545657620 1553991215408862701 1271346384257930401 2429539231986439397 243201325382784342 4956068616640091526 3421071614958327106 2576123453250950672 1698194834502571331 159526373384869384 4213255871244129488 4637052190334702925 4767000297862255807 3865308028345373916 4436091136601052465 5019244759896511694 771354343651857877 2236206870165706035 2524234757142041767 153306183504188624 1708134269565392242 2621458249822590231 3396381936683963585 5620806871611758059 4197774616010839285 4620763517853488569 1267484570830329202 5955571001217799646 2083285523419616504 5266833599186294157 4409539773669627219 4338833747552228595 117356105375470746 1523969710362285521 1077735967060481431 4395564942585550097 25393821000848905 106293794154960229 2650878870212367686 5499086960835581430 1996988164688565521 136525724999275699 3519124992751588724 916543750312351233 1599580264057590966 2740419370365605140 3024341758563538321 4785789064412878309 4059138893453088050 1009331768897164441 1513849597881374263 4369088832971625604 2171380093346436658 2073018203306710359 4865081696935892496 686129634564494583 5706651860283872482 2743864328248677779 5815838593385518468 998313424566146192 686796147441030675 4805950680324068768 1236455260615923135 649859968296047957 5842951734626997431 5077454974368502912 5568648585338771005 838822024125437461 718120392641533143 1522643064995599596 5143412393813628399 3919651784363201681 3299557997769872558 3817081938557785335 5634679558322804083 421751162659820703 4954793435866977451 1779056186982553072 4662137589778830547 4314529978303534518 1311591952144258488 3298998059134112982 5321469502617933367 2983540962674103639 3631465966121276907 552043650100745686 117127336780322002 2768021981303919799 3253426505248134340 1069211984137573686 5883606331250103513 6136755518040691956 2227727308879811864 4289797818417599695 2569751547899401517 4166852565206848930 4955950397409023285 2292774654783804756 2166564100880258298 353132559578486162 36 0 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00
src/agents/captures/asterix.png

789 B

src/agents/captures/donkey_kong.png

18.5 KiB

src/agents/captures/enduro.png

8.96 KiB

src/agents/captures/frostbite.png

9.88 KiB

src/agents/captures/galaxian.png

3.9 KiB

src/agents/captures/space_invaders.png

22.9 KiB

#!/usr/bin/python3.5
# This Python file uses the following encoding: utf-8
#Télécharger matplotlib et numpy
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import sys
import string
import re
if (len(sys.argv)!=2) :
print("Mettez en paramètre le fichier de statistique")
quit()
integrity = re.compile("stat_agent_(\w*)_\d+_\d+\.txt")
check = integrity.search(sys.argv[1])
if check == None :
print("Mauvais paramètre "+sys.argv[1])
quit()
rom = check.group(1)
#./neo_src/stat_agent_5_10.txt par exemple
fichier_stats = open(sys.argv[1])
lines = fichier_stats.readlines()
#Booléen de contrôle
good_file = False
good_options = False
#Les différentes regexp utilisées
emplacement = re.compile("Emplacement executable : (\w*), Rom : (\w*)")
options = re.compile("Mutation : ([0-9.]+), Croisement : ([0-9.]+), Taille du pool : ([0-9.]+), Population : ([0-9.]+)")
performance = re.compile("([0-9.]+);([0-9.]+)")
exception = re.compile(".*;([0-9.]+)")
#paramètres de l'agent
path = ''
mut = ''
cross = ''
pool = ''
pop = ''
rom = ''
#Tableau pour le plot
generations = []
scores = []
#Pour gérer les exceptions
follower = -1
for line in lines :
#print(line)
line.lstrip()
line.rstrip('\n')
#Vérifie la première ligne
if (good_file == False) :
first_line = emplacement.search(line)
if first_line != None :
path = first_line.group(1)
print(path)
rom = first_line.group(2)
print(rom)
good_file = True
continue
if first_line == None :
break
#Vérifie la deuxième ligne ssi la première ligne est vérifiée
if(good_file and not(good_options)) :
second_line = options.search(line)
if second_line != None :
mut = second_line.group(1)
cross = second_line.group(2)
pool = second_line.group(3)
pop = second_line.group(4)
good_options = True
continue
if second_line == None :
break
#Stocke les performances d'un agent dans les tableaux generations et scores
if(good_file and good_options):
#print(line)
generation = performance.search(line)
if generation != None :
print("good format")
scores.append(generation.group(1))
generations.append(generation.group(2))
if generation == None :
#Si jamais la ligne n'a pas une bonne tête
print("exception")
#Capte une ligne du type "-nan;15"
bad_generation = exception.search(line)
if bad_generation != None :
generations.append(bad_generation.group(1))
#Si jamais on a une erreur à la première génération
if follower > 0 :
i = scores[follower]
scores.append(i)
else :
scores.append(0)
if bad_generation == None :
print("not handled")
#on saute la ligne et on continue la lecture du fichier
continue
follower+=1
if(good_file and good_options) :
#Création des figures
fig, ax = plt.subplots()
#Création des points
ax.plot(generations,scores,".")
#Création de la légende
ax.set(xlabel="generation",ylabel="score",title=path+" on "+rom+" with M="+mut+", C="+cross+", P="+pool+", and Pop="+pop)
#Création de la grille et scaling des axes
ax.grid(True)
ax.axis('equal')
#Montre la fenêtre
plt.show()
#Sauvegarde la figure dans le dossier courant
fig.savefig(fichier_stats.name+"_fig.png",format="png")
else :
print("Problème lors de la lecture du fichier de statistiques")
fichier_stats.close()
#!/usr/bin/python3.5
# This Python file uses the following encoding: utf-8
#Télécharger matplotlib, PIL, et numpy
import re
import string
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import math
import PIL
from PIL import Image
import sys
if (len(sys.argv)!=2) :
print("Mettez en paramètre le fichier de statistique")
quit()
integrity = re.compile("instr_agent_(\w*)_\d+_\d+\.txt")
check = integrity.search(sys.argv[1])
print(sys.argv[1])
if check == None :
print("Mauvais paramètre "+sys.argv[1])
quit()
fichier_instruction = open(sys.argv[1])
lines = fichier_instruction.readlines()
rom = check.group(1)
print(rom)
#Les regexps pour capturer les registres et les index des registres
R = re.compile("R\[(\d+)\]")
M = re.compile("M\[(\d+)\]")
I = re.compile("I\[(\d+)\]")
O = re.compile("O\[(\d+)\]")
#Pour des pourcentages pour les figures
output_total = 0
memory_total = 0
register_total = 0
operation_total = 0
#Les dictionnaires pour stocker les index des registres et leur nombre d'occurences dans le programme
registerR = {}
registerM = {}
inputI = {}
registerO = {}
#Le dictionnaire des opérations
operations = {"nop":0," + ":0," - ":0,"max":0,"min":0,"-(":0,"*":0,"/":0,"log":0,"exp":0,"cos":0,"sin":0,"popcount":0,"if":0,"goto":0}
#print(operations)
#Boucle de capture
for line in lines :
line.lstrip()
line.rstrip('\n')
operation_total+=1
#Détecte les cases registres utilisées
catchR = R.findall(line)
if catchR != [] :
#print(catchR)
for num in catchR :
if num in registerR :
registerR[num] = registerR[num]+1
else :
registerR[num] = 1
register_total+=1
#Détecte les cases mémoire utilisées
catchM = M.findall(line)
if catchM != [] :
#print(catchM)
for num in catchM :
if num in registerM :
registerM[num] = registerM[num]+1
else :
registerM[num] = 1
memory_total+=1
#Détecte les cases input utilisées
catchI = I.findall(line)
if catchI != [] :
#print(catchI)
for num in catchI :
if num in inputI :
inputI[num] = inputI[num]+1
else :
inputI[num] = 1
#Détecte les cases output utilisées
catchO = O.findall(line)
if catchO != [] :
#print(catchO)
for num in catchO :
if num in registerO :
registerO[num] = registerO[num]+1
else :
registerO[num] = 1
output_total+=1
#Détecte les opérations appliquées
for op in operations:
if op in line:
operations[op]= operations[op]+1
#Nécessaire pour différencier les if, if_goto et +
operations['if']-=operations['goto']
operations[' + ']-=operations['goto']
#print(registerO)
#print(registerO.keys())
#print(registerO.values())
#Traitement pour rendre les outputs plus clair
trueO = list(registerO.keys())
i=0
while i < len(trueO) :
if trueO[i] == '0' :
trueO[i] = 'nope'
elif trueO[i] == '1' :
trueO[i] = 'fire'
elif trueO[i] == '2' :
trueO[i] = 'up'
elif trueO[i] == '3' :
trueO[i] = 'right'
elif trueO[i] == '4' :
trueO[i] = 'left'
elif trueO[i] == '5' :
trueO[i] = 'down'
elif trueO[i] == '6' :
trueO[i] = 'upright'
elif trueO[i] == '7' :
trueO[i] = 'upleft'
elif trueO[i] == '8' :
trueO[i] = 'downright'
elif trueO[i] == '9' :
trueO[i] = 'downleft'
elif trueO[i] == '10' :
trueO[i] = 'upfire'
elif trueO[i] == '11' :
trueO[i] = 'rightfire'
elif trueO[i] == '12' :
trueO[i] = 'leftfire'
elif trueO[i] == '13' :
trueO[i] = 'downfire'
elif trueO[i] == '14' :
trueO[i] = 'uprightfire'
elif trueO[i] == '15' :
trueO[i] = 'upleftfire'
elif trueO[i] == '16' :
trueO[i] = 'downrightfire'
elif trueO[i] == '17' :
trueO[i] = 'downleftfire'
i+=1
print(trueO)
#Traitement pour avoir des pourcentages
trueO_values = list(registerO.values())
for i in range(len(trueO_values)) :
trueO_values[i]=(trueO_values[i]/output_total)*100
R_values = list(registerR.values())
for i in range(len(R_values)):
R_values[i] = (R_values[i]/register_total)*100
M_values = list(registerM.values())
for i in range(len(M_values)) :
M_values[i] = (M_values[i]/memory_total)*100
op_values = list(operations.values())
for i in range(len(op_values)) :
op_values[i] = (op_values[i]/operation_total)*100
figO,axO = plt.subplots(2,1,figsize=(21, 27)) #figsize à ajuster pour modifier la taille des graphiques
plt.subplots_adjust(wspace=0.5,hspace=0.8)
axO[0].bar(trueO,trueO_values)
axO[0].set(xlabel = "Used Output Registers", ylabel = "Number of use (%)", title = "General Use of the Output Registers")
axO[1].barh(list(operations.keys()),op_values)
axO[1].set(xlabel = "Number of use (%)", ylabel = "Used Operations", title = "General Use of the Operations")
plt.show()
figR,axR = plt.subplots(2,1,figsize=(21,27))
plt.subplots_adjust(wspace=0.5,hspace=0.8)
axR[0].bar(list(registerR.keys()),R_values)
axR[0].set(xlabel = "Used Registers", ylabel = "Number of use (%)", title = "General Use of the short-term Registers")
axR[1].bar(list(registerM.keys()),M_values)
axR[1].set(xlabel = "Used Registers", ylabel = "Number of use (%)", title = "General Use of the long-term Registers")
plt.show()
#Traitement des images
#Création de la matrice 210x160
matrice_image = [[0 for x in range(160)] for y in range(210)]
max_input = max(inputI.values())
#print(max_input)
#On remplit la matrice
for inp,use in inputI.items() :
#print(inp)
aux1 = int(int(inp)/32)
h = aux1*5
#print(aux1)
aux2 = int(inp) - aux1*32
w = aux2*5
#print(aux2)
for i in np.arange(h,h+5,1.0) :
for j in np.arange(w,w+5,1.0) :
matrice_image[int(i)][int(j)]= (use/max_input)
#print(matrice_image)
#import resizeimage
image = Image.open("captures/"+rom+".png")
result1 = Image.new(image.mode,image.size)
result2 = Image.new(image.mode,image.size)
#On noircit les pixels non considérés par l'algorithme
for i in range(160) :
for j in range(210) :
if matrice_image[j][i] == 0 :
p=(0,0,0,255)
result1.putpixel((j,i),p)
else :
pixel=image.getpixel((j,i))
p = (255-pixel[0],255-pixel[1],255-pixel[2],255)
result1.putpixel((j,i),p)
result1 = result1.resize((420,320),Image.ANTIALIAS)
result1.show()
result1.save(fichier_instruction.name+"_scope.png")
#On met en rouge les pixels non vus et on pondère les valeurs RGB selon le maximum de l'utilisation d'un input
for i in range(160) :
for j in range(210) :
if matrice_image[j][i] == 0 :
p=(255,0,0,255)
result2.putpixel((j,i),p)
else :
pixel=image.getpixel((j,i))
percent = matrice_image[j][i]
p = (int((255-pixel[0])*percent),int((255-pixel[1])*percent),int((255-pixel[2])*percent))
result2.putpixel((j,i),p)
result2 = result2.resize((420,320),Image.ANTIALIAS)
result2.show()
result2.save(fichier_instruction.name+"_scope_ponderation.png")
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Emplacement exécutable : neo_src
Mutation : 0.2, Croisement : 0.6, Taille du pool : 20, Population : 1000
220;1
220;2
240;3
250;4
260;5
260;6
260;7
260;8
270;9
270;10
870;11
870;12
1210;13
2400;14
2400;15
2400;16
2400;17
2400;18
2400;19
3200;20
3200;21
3200;22
3200;23
3200;24
3200;25
3220;26
3220;27
3220;28
3220;29
3220;30
-nan;31
3220;32
3220;33
3220;34
3220;35
3220;36
3220;37
3250;38
3250;39
3250;40
3250;41
3250;42
3250;43
3250;44
3250;45
3250;46
3250;47
3250;48
3250;49
3250;50
3250;51
3250;52
3310;53
3340;54
3400;55
3710;56
3710;57
3710;58
3710;59
3910;60
3910;61
3910;62
3910;63
3910;64
3910;65
3910;66
3910;67
3910;68
3910;69
3910;70
3910;71
3910;72
3910;73
3910;74
3910;75
4110;76
4110;77
4110;78
4110;79
4110;80
4110;81
4110;82
4110;83
4110;84
4110;85
4110;86
4110;87
4110;88
4110;89
4110;90
4110;91
4110;92
4110;93
4110;94
4110;95
4110;96
4110;97
4110;98
4110;99
4110;100
4110;101
4110;102
4110;103
4110;104
4110;105
4110;106
4110;107
4110;108
4110;109
4110;110
4110;111
4110;112
4110;113
4110;114
4110;115
4110;116
4110;117
4110;118
4110;119
4110;120
4110;121
4110;122
4110;123
4110;124
4110;125
4110;126
4110;127
4110;128
4110;129
4110;130
4110;131
4110;132
4110;133
4110;134
4110;135
4110;136
4110;137
4110;138
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment