Skip to content

Commit 55b1cf8

Browse files
author
Maximilian Reißmann
committed
add reverse
1 parent 7cb2d8e commit 55b1cf8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/Gep.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ end
291291
alpha_operator, _ = create_operator_masks(gene_seq_alpha, gene_seq_alpha, pb)
292292
mutation_seq_1 = generate_chromosome(chromosome1.toolbox)
293293

294-
295294
@inbounds @simd for i in eachindex(gene_seq_alpha)
296295
gene_seq_alpha[i] = alpha_operator[i] == 1 ? mutation_seq_1.genes[i] : gene_seq_alpha[i]
297296
end
@@ -311,9 +310,8 @@ end
311310

312311
@inline function reverse_insertion!(chromosome::Chromosome)
313312
start_1 = rand(chromosome.toolbox.gen_start_indices)
314-
insert_pos = rand(start_1:(start_1+chromosome.toolbox.head_len-1))
315-
insert_sym = rand(chromosome.toolbox.tailsyms)
316-
chromosome.genes[insert_pos] = insert_sym
313+
rolled_array = circshift(chromosome.genes[start_1:chromosome.toolbox.head_len-1], rand(1:chromosome.toolbox.head_len-1))
314+
chromosome.genes[start_1:chromosome.toolbox.head_len-1] = rolled_array
317315
end
318316

319317
@inline function compute_fitness(elem::Chromosome, operators::OperatorEnum, x_data::AbstractArray{T}, y_data::AbstractArray{T}, loss_function::Function,
@@ -334,7 +332,7 @@ end
334332
@inline function genetic_operations!(space_next::Vector{Chromosome}, i::Int, toolbox::Toolbox)
335333
#allocate them within the space - create them once instead of n time
336334
space_next[i:i+1] = replicate(space_next[i], space_next[i+1], toolbox)
337-
rand_space = rand(11)
335+
rand_space = rand(13)
338336

339337

340338
if rand_space[1] < toolbox.gep_probs["one_point_cross_over_prob"]
@@ -380,6 +378,15 @@ end
380378
if rand_space[11] < toolbox.gep_probs["inversion_prob"]
381379
gene_insertion!(space_next[i+1])
382380
end
381+
382+
if rand_space[12] < toolbox.gep_probs["inversion_prob"]
383+
reverse_insertion!(space_next[i])
384+
end
385+
386+
if rand_space[13] < toolbox.gep_probs["inversion_prob"]
387+
reverse_insertion!(space_next[i+1])
388+
end
389+
383390
end
384391

385392
function runGep(epochs::Int,

0 commit comments

Comments
 (0)