Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
genetic-algorithms
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
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
Lennart Eichhorn
genetic-algorithms
Commits
0b61c5e8
Commit
0b61c5e8
authored
5 years ago
by
Lennart Eichhorn
Browse files
Options
Downloads
Patches
Plain Diff
Refactored the OnlyBest selector
parent
5184f236
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/MainClasses/GeneticAlgorithm.java
+1
-1
1 addition, 1 deletion
src/main/java/MainClasses/GeneticAlgorithm.java
src/main/java/Selectors/OnlyBest.java
+9
-19
9 additions, 19 deletions
src/main/java/Selectors/OnlyBest.java
with
10 additions
and
20 deletions
src/main/java/MainClasses/GeneticAlgorithm.java
+
1
−
1
View file @
0b61c5e8
...
@@ -126,7 +126,7 @@ public class GeneticAlgorithm {
...
@@ -126,7 +126,7 @@ public class GeneticAlgorithm {
}
else
if
(
config
.
getSelectionMethod
().
equals
(
SelectionMethods
.
Tournament
))
{
}
else
if
(
config
.
getSelectionMethod
().
equals
(
SelectionMethods
.
Tournament
))
{
this
.
selector
=
new
Tournament
(
this
.
config
,
this
.
rand
);
this
.
selector
=
new
Tournament
(
this
.
config
,
this
.
rand
);
}
else
if
(
config
.
getSelectionMethod
().
equals
(
SelectionMethods
.
OnlyBest
))
{
}
else
if
(
config
.
getSelectionMethod
().
equals
(
SelectionMethods
.
OnlyBest
))
{
this
.
selector
=
new
OnlyBest
(
this
.
isHydrophobic
);
this
.
selector
=
new
OnlyBest
();
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/Selectors/OnlyBest.java
+
9
−
19
View file @
0b61c5e8
...
@@ -7,31 +7,21 @@ import java.util.Random;
...
@@ -7,31 +7,21 @@ import java.util.Random;
public
class
OnlyBest
implements
Selector
{
public
class
OnlyBest
implements
Selector
{
int
[]
isHydrophobic
;
public
OnlyBest
()
{
public
OnlyBest
(
int
[]
isHydrophobic
)
{
this
.
isHydrophobic
=
isHydrophobic
;
}
}
@Override
@Override
public
Candidate
[]
selectNewPopulation
(
Candidate
[]
population
,
double
[]
fitness
,
double
totalFitness
)
{
public
Candidate
[]
selectNewPopulation
(
Candidate
[]
generation
)
{
int
populationSize
=
population
.
length
;
Candidate
bestCandidate
=
generation
[
0
];
for
(
Candidate
candidate:
generation
)
{
int
bestIndex
=
0
;
if
(
candidate
.
getFitness
()
>=
bestCandidate
.
getFitness
())
{
double
bestFitness
=
0
;
bestCandidate
=
candidate
;
for
(
int
i
=
0
;
i
<
populationSize
;
i
++)
{
if
(
fitness
[
i
]
>=
bestFitness
)
{
bestFitness
=
fitness
[
i
];
bestIndex
=
i
;
}
}
}
}
Candidate
[]
newPopulation
=
new
Candidate
[
populationSize
];
Candidate
[]
newPopulation
=
new
Candidate
[
generation
.
length
];
int
[]
bestFolding
=
population
[
bestIndex
].
getFolding
();
for
(
int
i
=
0
;
i
<
generation
.
length
;
i
++)
{
newPopulation
[
i
]
=
new
Candidate
(
bestCandidate
.
getFolding
());
for
(
int
i
=
0
;
i
<
populationSize
;
i
++)
{
newPopulation
[
i
]
=
new
Candidate
(
bestFolding
);
}
}
return
newPopulation
;
return
newPopulation
;
...
...
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