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
06b24fec
Commit
06b24fec
authored
5 years ago
by
O'Sullivan Solal
Browse files
Options
Downloads
Patches
Plain Diff
ajout de la fonction population
parent
a5d79180
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test.py
+113
-0
113 additions, 0 deletions
test.py
with
113 additions
and
0 deletions
test.py
0 → 100644
+
113
−
0
View file @
06b24fec
import
random
class
Population
:
def
__init__
(
self
,
n
):
self
.
indiv
=
[
Individu
(
rot_table
.
alea
)
for
k
in
range
(
n
)]
self
.
n
=
n
def
selection_duel_pondere
(
self
,
p
=
(
self
.
n
)
//
2
):
n
=
self
.
n
newself
=
[]
#méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer
while
len
(
self
)
>
p
:
m
=
random
.
randrange
(
0
,
len
(
self
))
t
=
random
.
randrange
(
0
,
len
(
self
))
x
=
self
[
m
]
y
=
self
[
t
]
p
=
uniform
(
0
,
1
)
if
p
>
x
.
score
/
(
x
.
score
+
y
.
score
):
newself
.
append
(
y
)
else
:
newself
.
append
(
x
)
return
(
newself
)
def
selection_duel
(
self
,
p
=
(
self
.
n
)
//
2
):
n
=
self
.
n
newself
=
[]
#méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer
while
len
(
self
)
>
p
:
m
=
random
.
randrange
(
0
,
len
(
self
))
t
=
random
.
randrange
(
0
,
len
(
self
))
x
=
self
[
m
]
y
=
self
[
t
]
if
x
.
score
<=
y
.
score
:
newself
.
append
(
x
)
else
:
newself
.
append
(
y
)
return
(
newself
)
def
selection_par_rang
(
self
,
p
):
liste_individus
=
self
.
indiv
n
=
self
.
n
def
echanger
(
tableau
,
i
,
j
):
tableau
[
i
],
tableau
[
j
]
=
tableau
[
j
],
tableau
[
i
]
def
partitionner
(
tableau
,
debut
,
fin
):
echanger
(
tableau
,
debut
,
randint
(
debut
,
fin
-
1
))
partition
=
debut
for
i
in
range
(
debut
+
1
,
fin
):
if
tableau
[
i
]
<
tableau
[
debut
]:
if
tableau
[
i
].
score
<
tableau
[
debut
].
score
:
partition
+=
1
echanger
(
tableau
,
i
,
partition
)
echanger
(
tableau
,
debut
,
partition
)
return
partition
def
tri_rapide_aux
(
tableau
,
debut
,
fin
):
if
debut
<
fin
-
1
:
positionPivot
=
partitionner
(
tableau
,
debut
,
fin
)
tri_rapide_aux
(
tableau
,
debut
,
positionPivot
)
tri_rapide_aux
(
tableau
,
positionPivot
+
1
,
fin
)
def
tri_rapide
(
tableau
):
tri_rapide_aux
(
tableau
,
0
,
len
(
tableau
))
tri_rapide
(
liste_individus
)
individus_selectionnes
=
[]
for
_
in
range
(
p
):
curseur
=
random
()
*
n
*
(
n
+
1
)
/
2
# print("curseur", curseur)
j
=
1
while
j
*
(
j
+
1
)
/
2
<
curseur
:
j
+=
1
#on doit prendre l'individu avec le jème score
# print("individus selectionés", individus_selectionnes)
individus_selectionnes
.
append
(
liste
[
j
-
1
])
def
modifier_population
(
self
,
liste_individus
):
self
.
n
=
len
(
liste_individus
)
self
.
indiv
=
liste_individus
return
self
self
=
modifier_population
(
self
,
individus_selectionnes
)
def
reproduction
(
self
,
selection
=
selection_duel
,
enfant
=
mixage
,
p
=
n
//
2
):
newself
=
selection
(
self
,
p
)
while
len
(
newself
)
<
self
.
n
:
m
=
random
.
randrange
(
0
,
len
(
newself
))
t
=
random
.
randrange
(
0
,
len
(
newself
))
x
=
newself
[
m
]
y
=
newself
[
t
]
newself
.
append
(
enfant
(
x
,
y
))
return
(
newself
)
print
([
random
.
randrange
(
1
,
10
)
for
i
in
range
(
5
)])
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