Saataa andagii !
This commit is contained in:
parent
d99a556d3d
commit
757ea77cc5
8 changed files with 549 additions and 500 deletions
|
@ -5,6 +5,7 @@
|
||||||
### Linux
|
### Linux
|
||||||
|
|
||||||
- `git clone https://git.leizour.fr/lucien/ultra-mastermind-implementation`
|
- `git clone https://git.leizour.fr/lucien/ultra-mastermind-implementation`
|
||||||
|
- `cd ultra-mastermind-implementation`
|
||||||
- `python -m venv .venv`
|
- `python -m venv .venv`
|
||||||
- `source .venv/bin/activate`
|
- `source .venv/bin/activate`
|
||||||
- `pip install -r requirements.txt`
|
- `pip install -r requirements.txt`
|
||||||
|
@ -20,8 +21,9 @@
|
||||||
#### Second method
|
#### Second method
|
||||||
|
|
||||||
- `git clone https://git.leizour.fr/lucien/ultra-mastermind-implementation`
|
- `git clone https://git.leizour.fr/lucien/ultra-mastermind-implementation`
|
||||||
|
- `cd ultra-mastermind-implementation`
|
||||||
- `python -m venv .venv`
|
- `python -m venv .venv`
|
||||||
- `./.venv/bin/activate`
|
- `.venv/bin/activate`
|
||||||
- `pip install -r requirements.txt`
|
- `pip install -r requirements.txt`
|
||||||
- `python main.py`
|
- `python main.py`
|
||||||
|
|
||||||
|
|
103
analyse.py
Normal file
103
analyse.py
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
# fichier de tests du projet
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import random
|
||||||
|
|
||||||
|
# project libs importations
|
||||||
|
import lib.ultra_mastermind_obj as libobj
|
||||||
|
import lib.ultra_mastermind_imp as libimp
|
||||||
|
import lib.ultra_mastermind_pp_imp as libppimp
|
||||||
|
|
||||||
|
PM = "Hello, world!"
|
||||||
|
NG = 4000
|
||||||
|
N = 400
|
||||||
|
TS = 0.7
|
||||||
|
TM = 0.25
|
||||||
|
ALPHA = 0.5
|
||||||
|
FITNESS_METHOD = 3
|
||||||
|
|
||||||
|
# Variation de la taille de la phrase
|
||||||
|
length_ng = []
|
||||||
|
length = []
|
||||||
|
|
||||||
|
for i in range(5, 26, 3):
|
||||||
|
print(f"Step {i}:")
|
||||||
|
length.append(i)
|
||||||
|
vals = []
|
||||||
|
for j in range(5):
|
||||||
|
print(f" Part {j}")
|
||||||
|
PM = "".join([chr(random.randint(0, 255)) for _ in range(i)])
|
||||||
|
pop = libppimp.new_population(PM, NG, N, TS, TM, ALPHA, FITNESS_METHOD)
|
||||||
|
ng = libppimp.run(pop)
|
||||||
|
vals.append(ng)
|
||||||
|
length_ng.append(sum(vals) / len(vals))
|
||||||
|
|
||||||
|
plt.plot(length, length_ng)
|
||||||
|
plt.title("Nombre de générations nécéssaires en fonction de la taille de la phrase.")
|
||||||
|
plt.xlabel("Taille de la phrase")
|
||||||
|
plt.ylabel("Nombre de générations")
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
# Variation de la taille de la population
|
||||||
|
n_ng = []
|
||||||
|
n = []
|
||||||
|
|
||||||
|
for i in range(50, 1000, 100):
|
||||||
|
print(f"Step {i}:")
|
||||||
|
n.append(i)
|
||||||
|
vals = []
|
||||||
|
for j in range(5):
|
||||||
|
print(f" Part {j}")
|
||||||
|
pop = libppimp.new_population(PM, NG, i, TS, TM, ALPHA, FITNESS_METHOD)
|
||||||
|
ng = libppimp.run(pop)
|
||||||
|
vals.append(ng)
|
||||||
|
n_ng.append(sum(vals) / len(vals))
|
||||||
|
|
||||||
|
plt.plot(n, n_ng)
|
||||||
|
plt.title("Nombre de générations nécéssaires en fonction de la taille de la population.")
|
||||||
|
plt.xlabel("Taille de la population")
|
||||||
|
plt.ylabel("Nombre de générations")
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
# Variation du taut de sélection
|
||||||
|
ts_ng = []
|
||||||
|
ts = []
|
||||||
|
|
||||||
|
for i in range(1, 9, 1):
|
||||||
|
print(f"Step {i / 10}:")
|
||||||
|
ts.append(i / 10)
|
||||||
|
vals = []
|
||||||
|
for j in range(5):
|
||||||
|
print(f" Part {j}")
|
||||||
|
pop = libppimp.new_population(PM, NG, N, i / 10, TM, ALPHA, FITNESS_METHOD)
|
||||||
|
ng = libppimp.run(pop)
|
||||||
|
vals.append(ng)
|
||||||
|
ts_ng.append(sum(vals) / len(vals))
|
||||||
|
|
||||||
|
plt.plot(ts, ts_ng)
|
||||||
|
plt.title("Nombre de générations nécéssaires en fonction du taut de sélection.")
|
||||||
|
plt.xlabel("Taut de sélection")
|
||||||
|
plt.ylabel("Nombre de générations")
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
# Variation du taut de mutation
|
||||||
|
tm_ng = []
|
||||||
|
tm = []
|
||||||
|
|
||||||
|
for i in range(10, 40, 5):
|
||||||
|
print(f"Step {i / 100}:")
|
||||||
|
tm.append(i / 100)
|
||||||
|
vals = []
|
||||||
|
for j in range(5):
|
||||||
|
print(f" Part {j}")
|
||||||
|
pop = libppimp.new_population(PM, NG, N, TS, i / 100, ALPHA, FITNESS_METHOD)
|
||||||
|
ng = libppimp.run(pop)
|
||||||
|
vals.append(ng)
|
||||||
|
tm_ng.append(sum(vals) / len(vals))
|
||||||
|
|
||||||
|
plt.plot(tm, tm_ng)
|
||||||
|
plt.title("Nombre de générations nécéssaires en fonction du taut de mutation.")
|
||||||
|
plt.xlabel("Taut de mutation")
|
||||||
|
plt.ylabel("Nombre de générations")
|
||||||
|
plt.show()
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 44 KiB |
|
@ -165,7 +165,7 @@ def mutate(individual) -> None:
|
||||||
Methode qui change un des caractères du chromozome
|
Methode qui change un des caractères du chromozome
|
||||||
"""
|
"""
|
||||||
new = list(individual["chromozome"])
|
new = list(individual["chromozome"])
|
||||||
dice = random.randint(1,3)
|
dice = random.randint(1, 6)
|
||||||
if dice == 1 and len(new) < 30:
|
if dice == 1 and len(new) < 30:
|
||||||
new.insert(random.randint(0, len(new) - 1), chr(random.randint(0, 255)))
|
new.insert(random.randint(0, len(new) - 1), chr(random.randint(0, 255)))
|
||||||
elif dice == 2 and len(new) > 4:
|
elif dice == 2 and len(new) > 4:
|
||||||
|
@ -186,12 +186,14 @@ def mutate_pop(population) -> None:
|
||||||
mutate(population["individuals"][to_mutate])
|
mutate(population["individuals"][to_mutate])
|
||||||
mutated.append(to_mutate)
|
mutated.append(to_mutate)
|
||||||
|
|
||||||
def run(population) -> None:
|
def run(population) -> int:
|
||||||
"""
|
"""
|
||||||
Boucle principale
|
Boucle principale
|
||||||
"""
|
"""
|
||||||
for i in range(population["ng"]):
|
for i in range(population["ng"]):
|
||||||
|
if get_best(population)["chromozome"] == population["pm"]:
|
||||||
|
return i
|
||||||
select(population)
|
select(population)
|
||||||
reproduct(population)
|
reproduct(population)
|
||||||
mutate_pop(population)
|
mutate_pop(population)
|
||||||
print_best(population)
|
return population["ng"]
|
||||||
|
|
1
main.py
1
main.py
|
@ -31,6 +31,7 @@ def main() -> None:
|
||||||
# imperative version ++
|
# imperative version ++
|
||||||
pop = libppimp.new_population(PM, NG, N, TS, TM, ALPHA, FITNESS_METHOD)
|
pop = libppimp.new_population(PM, NG, N, TS, TM, ALPHA, FITNESS_METHOD)
|
||||||
libppimp.run(pop)
|
libppimp.run(pop)
|
||||||
|
print(libppimp.get_best(pop)["chromozome"])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
59
tests.py
59
tests.py
|
@ -1,59 +0,0 @@
|
||||||
# fichier de tests du projet
|
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
|
|
||||||
# project libs importations
|
|
||||||
import lib.ultra_mastermind_obj as libobj
|
|
||||||
import lib.ultra_mastermind_imp as libimp
|
|
||||||
import lib.ultra_mastermind_pp_imp as libppimp
|
|
||||||
|
|
||||||
# Variation du nombre de générations
|
|
||||||
PM = "Hello, world!"
|
|
||||||
# NG = 2000
|
|
||||||
N = 400
|
|
||||||
TS = 0.5
|
|
||||||
TM = 0.25
|
|
||||||
ALPHA = 0.5
|
|
||||||
FITNESS_METHOD = 3
|
|
||||||
|
|
||||||
fitness_ng = []
|
|
||||||
all_ng = []
|
|
||||||
|
|
||||||
for i in range(1, 11):
|
|
||||||
NG = i * 200
|
|
||||||
all_ng.append(NG)
|
|
||||||
pop = libppimp.new_population(PM, NG, N, TS, TM, ALPHA, FITNESS_METHOD)
|
|
||||||
libppimp.run(pop)
|
|
||||||
fitness_ng.append(libppimp.get_fitness(pop, libppimp.get_best(pop)))
|
|
||||||
|
|
||||||
plt.plot(all_ng, fitness_ng)
|
|
||||||
plt.title("Fitness du meilleur individu en fonction du nombre de générations")
|
|
||||||
plt.xlabel("Nombre de générations")
|
|
||||||
plt.ylabel("Fitness du meilleur individu")
|
|
||||||
plt.show()
|
|
||||||
|
|
||||||
# Variation du nombre de générations
|
|
||||||
PM = "Hello, world!"
|
|
||||||
NG = 500
|
|
||||||
# N = 400
|
|
||||||
TS = 0.5
|
|
||||||
TM = 0.25
|
|
||||||
ALPHA = 0.5
|
|
||||||
FITNESS_METHOD = 3
|
|
||||||
|
|
||||||
fitness_n = []
|
|
||||||
all_n = []
|
|
||||||
|
|
||||||
for i in range(1, 11):
|
|
||||||
N = i * 100
|
|
||||||
all_n.append(N)
|
|
||||||
pop = libppimp.new_population(PM, NG, N, TS, TM, ALPHA, FITNESS_METHOD)
|
|
||||||
libppimp.run(pop)
|
|
||||||
fitness_n.append(libppimp.get_fitness(pop, libppimp.get_best(pop)))
|
|
||||||
|
|
||||||
plt.plot(all_n, fitness_n)
|
|
||||||
plt.title("Fitness du meilleur individu en fonction de la taille de population")
|
|
||||||
plt.xlabel("Taille de population")
|
|
||||||
plt.ylabel("Fitness du meilleur individu")
|
|
||||||
plt.show()
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue