Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Genetic Bike A
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ii
collabschools
NORBIS-DLN Collaboration School 2022
Genetic Bike A
Commits
fb1a46e0
Commit
fb1a46e0
authored
2 years ago
by
hui
Browse files
Options
Downloads
Patches
Plain Diff
active the write data function to log the data
parent
169e3ff9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+3
-3
3 additions, 3 deletions
.gitignore
main.py
+1
-7
1 addition, 7 deletions
main.py
src/genetic_algo.py
+4
-6
4 additions, 6 deletions
src/genetic_algo.py
with
8 additions
and
16 deletions
.gitignore
+
3
−
3
View file @
fb1a46e0
.*__*
.*__*
.*/__*
.*/__*
.*/__pycache__
.*/__pycache__
bike/__pycache__/gen.cpython-310.pyc
bike/__pycache__/*
bike/__pycache__/simu_bike.cpython-310.pyc
debug.log
debug.log
data/*
\ No newline at end of file
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main.py
+
1
−
7
View file @
fb1a46e0
...
@@ -3,13 +3,7 @@
...
@@ -3,13 +3,7 @@
import
src.genetic_algo
as
ga
import
src.genetic_algo
as
ga
import
bike.simu_bike
as
sb
import
bike.simu_bike
as
sb
# points_position = np.random.rand(4, 2)*8+3
gen
=
ga
.
Genetic_algorithm
(
population_size
=
5
,
# a_bike=sb.creat_bike(points_position=points_position)
# print(a_bike)
gen
=
ga
.
Genetic_algorithm
(
population_size
=
20
,
start_point
=
(
0
,
5
),
start_point
=
(
0
,
5
),
side_length
=
5
,
side_length
=
5
,
fit_func
=
sb
.
creat_bike
)
fit_func
=
sb
.
creat_bike
)
...
...
This diff is collapsed.
Click to expand it.
src/genetic_algo.py
+
4
−
6
View file @
fb1a46e0
...
@@ -122,10 +122,7 @@ class Population():
...
@@ -122,10 +122,7 @@ class Population():
def
save_population_to_file
(
self
,
filename
):
def
save_population_to_file
(
self
,
filename
):
with
open
(
filename
,
"
w
"
)
as
f
:
with
open
(
filename
,
"
w
"
)
as
f
:
json
.
dump
([
ind
.
coordinates
for
ind
in
self
.
population
],
f
)
json
.
dump
([
ind
.
coordinates
for
ind
in
self
.
population
],
f
)
def
load_fitness_score_from_file
(
self
,
filename
):
f
.
close
()
with
open
(
filename
,
"
r
"
)
as
f
:
fitness_scores
=
json
.
load
(
f
)
return
fitness_scores
class
Genetic_algorithm
():
class
Genetic_algorithm
():
'''
'''
...
@@ -271,13 +268,14 @@ random.randint(start_point[1], start_point[1]+side_length)),
...
@@ -271,13 +268,14 @@ random.randint(start_point[1], start_point[1]+side_length)),
# START
# START
# Generate the initial population and Compute fitness
# Generate the initial population and Compute fitness
self
.
p
=
Population
(
self
.
__population_size
,
self
.
__start_point
,
self
.
__side_length
,
self
.
fit_func
)
self
.
p
=
Population
(
self
.
__population_size
,
self
.
__start_point
,
self
.
__side_length
,
self
.
fit_func
)
#self.p.save_population_to_file()
#self.p.load_fitness_score_from_file("data/population.json")
average_fitness_score
=
self
.
p
.
average_fitness_score
()
average_fitness_score
=
self
.
p
.
average_fitness_score
()
best_fitness_score
=
self
.
p
.
best_fitness_score
()
best_fitness_score
=
self
.
p
.
best_fitness_score
()
# REPEAT
# REPEAT
file_counter
=
0
while
abs
(
best_fitness_score
-
average_fitness_score
)
>
0.5
:
while
abs
(
best_fitness_score
-
average_fitness_score
)
>
0.5
:
self
.
p
.
save_population_to_file
(
"
data/population_
"
+
str
(
file_counter
)
+
"
.json
"
)
file_counter
+=
1
# Selection
# Selection
top_individuals
=
self
.
selection
(
self
.
p
,
percentage
=
0.2
)
top_individuals
=
self
.
selection
(
self
.
p
,
percentage
=
0.2
)
# Crossover
# Crossover
...
...
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