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
a13196da
Commit
a13196da
authored
5 years ago
by
Kappes Marques Rodrigo
Browse files
Options
Downloads
Patches
Plain Diff
cleaned the population
parent
fe7ae3c5
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
__pycache__/individu.cpython-37.pyc
+0
-0
0 additions, 0 deletions
__pycache__/individu.cpython-37.pyc
__pycache__/population.cpython-37.pyc
+0
-0
0 additions, 0 deletions
__pycache__/population.cpython-37.pyc
population.py
+21
-31
21 additions, 31 deletions
population.py
with
21 additions
and
31 deletions
__pycache__/individu.cpython-37.pyc
+
0
−
0
View file @
a13196da
No preview for this file type
This diff is collapsed.
Click to expand it.
__pycache__/population.cpython-37.pyc
+
0
−
0
View file @
a13196da
No preview for this file type
This diff is collapsed.
Click to expand it.
population.py
+
21
−
31
View file @
a13196da
...
...
@@ -5,16 +5,20 @@ from croisement import croisement_un_point, croisement_deux_points
import
copy
class
Population
:
#Class initialization
def
__init__
(
self
,
n
):
self
.
indiv
=
[
Individu
(
RotTable
())
for
k
in
range
(
n
)]
self
.
n
=
n
#Updates the current individuals in the population
def
modifier_population
(
self
,
liste_individus
):
"""
Fonction qui renvoie une nouvelle instance de population a partir d
'
une liste d
'
individus
"""
self
.
n
=
len
(
liste_individus
)
self
.
indiv
=
liste_individus
return
self
#Select a fixed number of individuals in a population
def
selection_p_best
(
self
,
p
=
None
):
if
p
==
None
:
p
=
(
self
.
n
)
//
2
...
...
@@ -23,7 +27,7 @@ class Population:
individus_selectionnes
=
[
element
for
element
in
liste_individus
[:
p
]]
self
=
self
.
modifier_population
(
individus_selectionnes
)
#Select via comparing two random individuals with some randomness involved and compared
def
selection_duel_pondere
(
self
,
p
=
None
):
if
p
==
None
:
p
=
(
self
.
n
)
//
2
...
...
@@ -33,7 +37,8 @@ class Population:
meilleur
=
individu
newself
=
[
meilleur
]
m
=
randrange
(
0
,
self
.
n
)
t
=
randrange
(
0
,
self
.
n
)
#méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer
t
=
randrange
(
0
,
self
.
n
)
#méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer
non_vu
=
[
i
for
i
in
range
(
0
,
self
.
n
)]
while
len
(
newself
)
<
p
:
m
=
choice
(
non_vu
)
...
...
@@ -50,6 +55,7 @@ class Population:
self
=
self
.
modifier_population
(
newself
)
#Selection via comparing the player`s score randomly
def
selection_duel
(
self
,
p
=
None
):
if
p
==
None
:
p
=
(
self
.
n
)
//
2
...
...
@@ -75,8 +81,7 @@ class Population:
newself
.
append
(
y
)
self
=
self
.
modifier_population
(
newself
)
#Selection using a random method to select players based on their rank in score
def
selection_par_rang
(
self
,
p
=
None
):
if
p
==
None
:
p
=
(
self
.
n
)
//
2
...
...
@@ -97,6 +102,7 @@ class Population:
self
=
self
.
modifier_population
(
individus_selectionnes
)
#Selecting using a random method that takes the score into ponderation
def
selection_proportionnelle
(
self
,
p
=
None
):
if
p
==
None
:
p
=
(
self
.
n
)
//
2
...
...
@@ -116,8 +122,12 @@ class Population:
newself
.
append
(
x
)
self
=
self
.
modifier_population
(
newself
)
#The Function that makes the selection and reduces the quantity of players
#and after reproduces and mutates the remaining ones into a new population
def
reproduction
(
self
,
proba_mutation
=
None
,
selection
=
None
,
enfant
=
croisement_un_point
,
p
=
None
):
liste_selections
=
[
self
.
selection_p_best
,
self
.
selection_duel_pondere
,
self
.
selection_duel
,
self
.
selection_par_rang
,
self
.
selection_proportionnelle
]
#Values of variables if there are no initial conditions
if
proba_mutation
==
None
:
proba_mutation
=
0.001
if
selection
==
None
:
...
...
@@ -126,14 +136,19 @@ class Population:
selection
=
liste_selections
[
selection
]
if
p
==
None
:
p
=
(
self
.
n
)
//
2
vieille_taille
=
self
.
n
selection
(
p
)
newself
=
[
element
for
element
in
self
.
indiv
]
while
len
(
newself
)
<
vieille_taille
:
m
=
randrange
(
0
,
self
.
n
)
t
=
randrange
(
0
,
self
.
n
)
#We have to make a deep copy so we dont lose the values of the parents
x
=
copy
.
deepcopy
(
newself
[
m
])
y
=
copy
.
deepcopy
(
newself
[
t
])
#Creation of the childs
couple_enfant
=
enfant
(
x
,
y
)
for
child
in
couple_enfant
:
child
.
mutation_close_values
(
proba_mutation
,
number_of_mutations
=
2
)
...
...
@@ -142,40 +157,15 @@ class Population:
newself
.
append
(
couple_enfant
[
1
])
self
=
self
.
modifier_population
(
newself
)
#Prints the current population(used for debugging)
def
afficher
(
popu
):
for
individu
in
popu
.
indiv
:
print
(
"
\n
individu
\n
"
)
# print(individu.table.rot_table)
print
(
"
score
"
,
individu
.
score
)
def
test
():
popu
=
Population
(
4
)
print
(
"
\n
POPULATION INITIALE
\n
"
)
for
individu
in
popu
.
indiv
:
individu
.
evaluate
()
afficher
(
popu
)
popu
.
reproduction
(
selection
=
popu
.
selection_duel
)
print
(
"
\n
REPRODUCTION
\n
"
)
afficher
(
popu
)
#test()
def
test2
():
popu
=
Population
(
10
)
for
individu
in
popu
.
indiv
:
lineList
=
[
line
.
rstrip
(
'
\n
'
)
for
line
in
open
(
"
plasmid_8k.fasta
"
)]
brin
=
''
.
join
(
lineList
[
1
:])
individu
.
evaluate
()
print
(
"
\n
\n
POPULATION INITIALE
\n
\n
"
)
afficher
(
popu
)
popu
.
selection_proportionnelle
()
print
(
"
\n\n
APRES SELECTION
\n\n
"
)
afficher
(
popu
)
# test2()
...
...
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