Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EI Jeux Evolutionnaires
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Santos Garcia Carlos
EI Jeux Evolutionnaires
Commits
df9a5c2c
Commit
df9a5c2c
authored
5 years ago
by
Muller Sacha
Browse files
Options
Downloads
Patches
Plain Diff
Correction des bugs de population.py
parent
3ff492be
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
RotTable.py
+3
-3
3 additions, 3 deletions
RotTable.py
population.py
+57
-26
57 additions, 26 deletions
population.py
with
60 additions
and
29 deletions
RotTable.py
+
3
−
3
View file @
df9a5c2c
...
@@ -63,7 +63,7 @@ class RotTable:
...
@@ -63,7 +63,7 @@ class RotTable:
###################
###################
table1
=
RotTable
()
#
table1 = RotTable()
print
(
table1
.
orta
())
#
print(table1.orta())
print
(
table1
.
rot_table
[
"
AA
"
])
#
print(table1.rot_table["AA"])
This diff is collapsed.
Click to expand it.
population.py
+
57
−
26
View file @
df9a5c2c
import
random
import
random
from
random
import
random
,
randint
,
randrange
from
individu
import
Individu
from
RotTable
import
RotTable
from
croisement
import
*
class
Population
:
class
Population
:
def
__init__
(
self
,
n
):
def
__init__
(
self
,
n
):
self
.
indiv
=
[
Individu
(
r
ot
_t
able
.
alea
)
for
k
in
range
(
n
)]
self
.
indiv
=
[
Individu
(
R
ot
T
able
()
)
for
k
in
range
(
n
)]
self
.
n
=
n
self
.
n
=
n
def
selection_duel_pondere
(
self
,
p
=
(
self
.
n
)
//
2
):
def
selection_duel_pondere
(
self
,
p
=
None
):
if
p
==
None
:
p
=
(
self
.
n
)
//
2
newself
=
[]
newself
=
[]
vu
=
{}
vu
=
set
()
m
=
None
m
=
None
t
=
None
#méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer
t
=
None
#méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer
while
len
(
newself
)
<
p
:
while
len
(
newself
)
<
p
:
while
m
in
vu
:
while
m
in
vu
:
m
=
random
.
randrange
(
0
,
len
(
self
))
m
=
randrange
(
0
,
len
(
self
))
while
t
in
vu
:
while
t
in
vu
:
t
=
random
.
randrange
(
0
,
len
(
self
))
t
=
randrange
(
0
,
len
(
self
))
x
=
self
[
m
]
x
=
self
.
indiv
[
m
]
y
=
self
[
t
]
y
=
self
.
indiv
[
t
]
vu
.
add
(
t
)
vu
.
add
(
t
)
vu
.
add
(
m
)
vu
.
add
(
m
)
p
=
unifor
m
(
0
,
1
)
p
=
rando
m
(
0
,
1
)
if
p
>
x
.
score
/
(
x
.
score
+
y
.
score
):
if
p
>
x
.
score
/
(
x
.
score
+
y
.
score
):
newself
.
append
(
y
)
newself
.
append
(
y
)
else
:
else
:
...
@@ -27,18 +34,20 @@ class Population:
...
@@ -27,18 +34,20 @@ class Population:
return
(
newself
)
return
(
newself
)
def
selection_duel
(
self
,
p
=
(
self
.
n
)
//
2
):
def
selection_duel
(
self
,
p
=
None
):
if
p
==
None
:
p
=
(
self
.
n
)
//
2
newself
=
[]
newself
=
[]
vu
=
{}
vu
=
set
()
t
=
None
t
=
None
m
=
None
m
=
None
while
len
(
newself
)
<
p
:
while
len
(
newself
)
<
p
:
while
m
in
vu
:
while
m
in
vu
:
m
=
random
.
randrange
(
0
,
len
(
self
))
m
=
randrange
(
0
,
len
(
self
))
while
t
in
vu
:
while
t
in
vu
:
t
=
random
.
randrange
(
0
,
len
(
self
))
t
=
randrange
(
0
,
len
(
self
))
x
=
self
[
m
]
x
=
self
.
indiv
[
m
]
y
=
self
[
t
]
y
=
self
.
indiv
[
t
]
vu
.
add
(
t
)
vu
.
add
(
t
)
vu
.
add
(
m
)
vu
.
add
(
m
)
if
x
.
score
<=
y
.
score
:
if
x
.
score
<=
y
.
score
:
...
@@ -47,7 +56,9 @@ class Population:
...
@@ -47,7 +56,9 @@ class Population:
newself
.
append
(
y
)
newself
.
append
(
y
)
return
(
newself
)
return
(
newself
)
def
selection_par_rang
(
self
,
p
=
(
self
.
n
)
//
2
):
def
selection_par_rang
(
self
,
p
=
None
):
if
p
==
None
:
p
=
(
self
.
n
)
//
2
liste_individus
=
self
.
indiv
liste_individus
=
self
.
indiv
n
=
self
.
n
n
=
self
.
n
...
@@ -58,7 +69,7 @@ class Population:
...
@@ -58,7 +69,7 @@ class Population:
echanger
(
tableau
,
debut
,
randint
(
debut
,
fin
-
1
))
echanger
(
tableau
,
debut
,
randint
(
debut
,
fin
-
1
))
partition
=
debut
partition
=
debut
for
i
in
range
(
debut
+
1
,
fin
):
for
i
in
range
(
debut
+
1
,
fin
):
if
tableau
[
i
]
<
tableau
[
debut
]:
#
if tableau[i] < tableau[debut]:
if
tableau
[
i
].
score
<
tableau
[
debut
].
score
:
if
tableau
[
i
].
score
<
tableau
[
debut
].
score
:
partition
+=
1
partition
+=
1
echanger
(
tableau
,
i
,
partition
)
echanger
(
tableau
,
i
,
partition
)
...
@@ -85,7 +96,7 @@ class Population:
...
@@ -85,7 +96,7 @@ class Population:
j
+=
1
j
+=
1
#on doit prendre l'individu avec le jème score
#on doit prendre l'individu avec le jème score
# print("individus selectionés", individus_selectionnes)
# print("individus selectionés", individus_selectionnes)
individus_selectionnes
.
append
(
liste
[
j
-
1
])
individus_selectionnes
.
append
(
liste
_individus
[
j
-
1
])
def
modifier_population
(
self
,
liste_individus
):
def
modifier_population
(
self
,
liste_individus
):
self
.
n
=
len
(
liste_individus
)
self
.
n
=
len
(
liste_individus
)
...
@@ -94,30 +105,50 @@ class Population:
...
@@ -94,30 +105,50 @@ class Population:
self
=
modifier_population
(
self
,
individus_selectionnes
)
self
=
modifier_population
(
self
,
individus_selectionnes
)
def
selection_proportionelle
(
self
,
p
=
(
self
.
n
)
//
2
):
def
selection_proportionelle
(
self
,
p
=
None
):
if
p
==
None
:
p
=
(
self
.
n
)
//
2
newself
=
[]
newself
=
[]
somme
=
0
somme
=
0
for
indiv
in
self
:
for
indiv
in
self
.
indiv
:
somme
=
somme
+
indiv
.
score
somme
=
somme
+
indiv
.
score
while
len
(
newself
)
<
p
:
while
len
(
newself
)
<
p
:
m
=
m
=
random
.
randrange
(
0
,
len
(
self
))
m
=
m
=
randrange
(
0
,
len
(
self
))
x
=
self
[
m
]
x
=
self
.
indiv
[
m
]
p
=
unifor
m
(
0
,
1
)
p
=
rando
m
(
0
,
1
)
if
p
<=
x
.
score
/
somme
:
if
p
<=
x
.
score
/
somme
:
newself
.
append
(
x
)
newself
.
append
(
x
)
return
(
newself
)
return
(
newself
)
def
reproduction
(
self
,
selection
=
selection_duel
,
enfant
=
mixage
,
p
=
n
//
2
):
def
reproduction
(
self
,
selection
=
selection_duel
,
enfant
=
croisement_un_point
,
p
=
None
):
if
p
==
None
:
p
=
(
self
.
n
)
//
2
newself
=
selection
(
self
,
p
)
newself
=
selection
(
self
,
p
)
while
len
(
newself
)
<
self
.
n
:
while
len
(
newself
)
<
self
.
n
:
m
=
random
.
randrange
(
0
,
len
(
newself
))
m
=
randrange
(
0
,
len
(
newself
))
t
=
random
.
randrange
(
0
,
len
(
newself
))
t
=
randrange
(
0
,
len
(
newself
))
x
=
newself
[
m
]
x
=
newself
[
m
]
y
=
newself
[
t
]
y
=
newself
[
t
]
newself
.
append
(
enfant
(
x
,
y
))
newself
.
append
(
enfant
(
x
,
y
))
return
(
newself
)
return
(
newself
)
# def afficher(popu):
# for individu in popu.indiv :
# print("\n individu \n")
# print(individu.table.rot_table)
# def test():
# popu = Population(4)
# print("\n POPULATION INITIALE \n")
# afficher(popu)
# popu.selection_duel()
# print("\n SELECTION DUEL \n")
# afficher(popu)
# popu.reproduction
# print("\n REPRODUCTION \n")
# afficher(popu)
# test()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment