Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nulling-python
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
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
smadani2
nulling-python
Commits
46e01594
Commit
46e01594
authored
4 years ago
by
Sepehr Madani
Browse files
Options
Downloads
Patches
Plain Diff
Refactor the max_time_limit on 'target'
parent
f3e02080
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
algorithms/genetic_algorithm.py
+9
-5
9 additions, 5 deletions
algorithms/genetic_algorithm.py
with
9 additions
and
5 deletions
algorithms/genetic_algorithm.py
+
9
−
5
View file @
46e01594
...
...
@@ -47,7 +47,7 @@ class Chromosome:
class
GeneticAlgorithm
(
BaseAlgorithm
):
"""
Finds nulls by running a genetic algorithm on all possible
"""
Finds nulls by running a genetic algorithm on all possible
discrete values.
"""
...
...
@@ -69,6 +69,7 @@ class GeneticAlgorithm(BaseAlgorithm):
self
.
gen_to_repeat
=
options
.
gen_to_repeat
self
.
time_limit
=
options
.
time_limit
self
.
stop_after_score
=
options
.
stop_after_score
self
.
max_time_limit
=
20
*
1000
self
.
generations
=
0
self
.
chromosomes
=
[]
...
...
@@ -95,7 +96,11 @@ class GeneticAlgorithm(BaseAlgorithm):
self
.
organize_sample
()
solve_function
=
getattr
(
self
,
"
solve_
"
+
self
.
stop_criterion
)
solve_function
()
return
(
self
.
make_weights
(
self
.
chromosomes
[
0
]),
self
.
chromosomes
[
0
].
get_score
(),
self
.
generations
)
return
(
self
.
make_weights
(
self
.
chromosomes
[
0
]),
self
.
chromosomes
[
0
].
get_score
(),
self
.
generations
)
def
solve_time
(
self
):
start_time
=
time_ns
()
...
...
@@ -104,7 +109,7 @@ class GeneticAlgorithm(BaseAlgorithm):
def
solve_target
(
self
):
start_time
=
time_ns
()
while
(
time_ns
()
-
start_time
)
//
10
**
6
<=
10
*
1000
:
while
(
time_ns
()
-
start_time
)
//
10
**
6
<=
self
.
max_time_limit
:
self
.
step
()
def
solve_iter
(
self
):
...
...
@@ -115,6 +120,7 @@ class GeneticAlgorithm(BaseAlgorithm):
self
.
create_children
()
self
.
mutate_sample
()
self
.
organize_sample
()
self
.
generations
+=
1
def
create_children
(
self
):
"""
Using the better half of the population, creates children overwriting the bottom half by doing crossovers.
...
...
@@ -137,8 +143,6 @@ class GeneticAlgorithm(BaseAlgorithm):
)
if
len
(
self
.
buckets
[
bucket_opp
])
>
0
else
choice
(
self
.
chromosomes
)
self
.
crossover_bucket
(
p1
,
p2
,
child
,
child
+
1
)
self
.
generations
+=
1
def
organize_sample
(
self
):
"""
Reorganizes the sample by updating pattern for all chromosomes and sorting them by their scores.
Optionally, if use_buckets is True, allocates each chromosome to its respective bucket.
"""
...
...
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