Skip to content

Commit fb6853e

Browse files
author
Aart Stuurman
committed
WIP direct tree in manager_pop. Also check previous commit
1 parent 80f2044 commit fb6853e

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

experiments/examples/manager_pop.py

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
)
1212
from pyrevolve.evolution.selection import multiple_selection, tournament_selection
1313
from pyrevolve.experiment_management import ExperimentManagement
14-
from pyrevolve.genotype.plasticoding import PlasticodingConfig
15-
from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig
16-
from pyrevolve.genotype.plasticoding.crossover.standard_crossover import (
17-
standard_crossover,
14+
from pyrevolve.genotype.direct_tree.direct_tree_config import DirectTreeGenotypeConfig
15+
from pyrevolve.genotype.direct_tree.direct_tree_crossover import (
16+
crossover_list as direct_tree_crossover_list,
17+
)
18+
from pyrevolve.genotype.direct_tree.direct_tree_genotype import (
19+
Genotype as DirectTreeGenotype,
20+
)
21+
from pyrevolve.genotype.direct_tree.direct_tree_mutation import (
22+
mutate as direct_tree_mutate,
1823
)
19-
from pyrevolve.genotype.plasticoding.initialization import random_initialization
20-
from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig
21-
from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation
2224
from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue
2325
from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue
2426

@@ -33,23 +35,27 @@ async def run():
3335
population_size = 100
3436
offspring_size = 50
3537

36-
genotype_conf = PlasticodingConfig(
37-
max_structural_modules=20,
38-
allow_vertical_brick=True,
39-
use_movement_commands=True,
40-
use_rotation_commands=False,
41-
use_movement_stack=True,
42-
)
43-
44-
mutation_conf = MutationConfig(
45-
mutation_prob=0.8,
46-
genotype_conf=genotype_conf,
38+
genotype_conf: DirectTreeGenotypeConfig = DirectTreeGenotypeConfig(
39+
max_parts=50,
40+
min_parts=10,
41+
max_oscillation=5,
42+
init_n_parts_mu=10,
43+
init_n_parts_sigma=4,
44+
init_prob_no_child=0.1,
45+
init_prob_child_block=0.4,
46+
init_prob_child_active_joint=0.5,
47+
mutation_p_duplicate_subtree=0.2,
48+
mutation_p_delete_subtree=0.2,
49+
mutation_p_generate_subtree=0.2,
50+
mutation_p_swap_subtree=0.2,
51+
mutation_p_mutate_oscillators=0.5,
52+
mutation_p_mutate_oscillator=0.5,
53+
mutate_oscillator_amplitude_sigma=0.3,
54+
mutate_oscillator_period_sigma=0.3,
55+
mutate_oscillator_phase_sigma=0.3,
4756
)
48-
49-
crossover_conf = CrossoverConfig(
50-
crossover_prob=0.8,
51-
)
52-
# experiment params #
57+
mutation_conf = genotype_conf
58+
crossover_conf = genotype_conf
5359

5460
# Parse command line / file input arguments
5561
settings = parser.parse_args()
@@ -79,20 +85,27 @@ async def run():
7985

8086
population_conf = PopulationConfig(
8187
population_size=population_size,
82-
genotype_constructor=random_initialization,
88+
genotype_constructor=lambda conf, _id: DirectTreeGenotype(
89+
conf, _id, random_init=True
90+
),
8391
genotype_conf=genotype_conf,
8492
fitness_function=fitness.displacement_velocity,
85-
mutation_operator=standard_mutation,
93+
mutation_operator=lambda genotype, gen_conf: direct_tree_mutate(
94+
genotype, gen_conf, in_place=False
95+
),
8696
mutation_conf=mutation_conf,
87-
crossover_operator=standard_crossover,
97+
crossover_operator=lambda parents, gen_conf, _cross_conf: direct_tree_crossover_list(
98+
[p.genotype for p in parents], gen_conf
99+
),
88100
crossover_conf=crossover_conf,
89101
selection=lambda individuals: tournament_selection(individuals, 2),
90102
parent_selection=lambda individuals: multiple_selection(
91103
individuals, 2, tournament_selection
92104
),
93105
population_management=steady_state_population_management,
94-
population_management_selector=tournament_selection,
106+
population_management_selector=None,
95107
evaluation_time=settings.evaluation_time,
108+
grace_time=settings.grace_time,
96109
offspring_size=offspring_size,
97110
experiment_name=settings.experiment_name,
98111
experiment_management=experiment_management,

0 commit comments

Comments
 (0)