1 | /* |
---|
2 | Copyright 2006 by Sean Luke |
---|
3 | Licensed under the Academic Free License version 3.0 |
---|
4 | See the file "LICENSE" for more information |
---|
5 | */ |
---|
6 | |
---|
7 | |
---|
8 | package ec.rule.breed; |
---|
9 | |
---|
10 | import ec.rule.*; |
---|
11 | import ec.*; |
---|
12 | import ec.util.*; |
---|
13 | |
---|
14 | /* |
---|
15 | * RuleMutationPipeline.java |
---|
16 | * |
---|
17 | * Created: Tue Mar 13 15:03:12 EST 2001 |
---|
18 | * By: Sean Luke |
---|
19 | */ |
---|
20 | |
---|
21 | |
---|
22 | /** |
---|
23 | * |
---|
24 | RuleMutationPipeline is a BreedingPipeline which implements a simple default Mutation |
---|
25 | for RuleIndividuals. Normally it takes an individual and returns a mutated |
---|
26 | child individual. RuleMutationPipeline works by calling mutateRules(...) on each RuleSet in the |
---|
27 | parent individual. |
---|
28 | |
---|
29 | <p><b>Typical Number of Individuals Produced Per <tt>produce(...)</tt> call</b><br> |
---|
30 | 1 |
---|
31 | |
---|
32 | <p><b>Number of Sources</b><br> |
---|
33 | 1 |
---|
34 | |
---|
35 | <p><b>Default Base</b><br> |
---|
36 | rule.mutate (not that it matters) |
---|
37 | |
---|
38 | * @author Sean Luke |
---|
39 | * @version 1.0 |
---|
40 | */ |
---|
41 | |
---|
42 | public class RuleMutationPipeline extends BreedingPipeline |
---|
43 | { |
---|
44 | public static final String P_MUTATION = "mutate"; |
---|
45 | public static final int INDS_PRODUCED = 1; |
---|
46 | public static final int NUM_SOURCES = 1; |
---|
47 | |
---|
48 | public Parameter defaultBase() { return RuleDefaults.base().push(P_MUTATION); } |
---|
49 | |
---|
50 | /** Returns 1 */ |
---|
51 | public int numSources() { return NUM_SOURCES; } |
---|
52 | |
---|
53 | /** Returns 1 */ |
---|
54 | // DO I need to change this? |
---|
55 | public int typicalIndsProduced() { return (INDS_PRODUCED); } |
---|
56 | |
---|
57 | public int produce(final int min, |
---|
58 | final int max, |
---|
59 | final int start, |
---|
60 | final int subpopulation, |
---|
61 | final Individual[] inds, |
---|
62 | final EvolutionState state, |
---|
63 | final int thread) |
---|
64 | { |
---|
65 | // grab n individuals from our source and stick 'em right into inds. |
---|
66 | // we'll modify them from there |
---|
67 | int n = sources[0].produce(min,max,start,subpopulation,inds,state,thread); |
---|
68 | |
---|
69 | // should we bother? |
---|
70 | if (!state.random[thread].nextBoolean(likelihood)) |
---|
71 | return reproduce(n, start, subpopulation, inds, state, thread, false); // DON'T produce children from source -- we already did |
---|
72 | |
---|
73 | // clone the individuals if necessary |
---|
74 | if (!(sources[0] instanceof BreedingPipeline)) |
---|
75 | for(int q=start;q<n+start;q++) |
---|
76 | inds[q] = (Individual)(inds[q].clone()); |
---|
77 | |
---|
78 | // mutate 'em |
---|
79 | for(int q=start;q<n+start;q++) |
---|
80 | { |
---|
81 | |
---|
82 | ((RuleIndividual)inds[q]).preprocessIndividual(state,thread); |
---|
83 | |
---|
84 | /* |
---|
85 | int len = ((RuleIndividual)inds[q]).rulesets.length; |
---|
86 | for( int x = 0 ; x < len ; x++ ) |
---|
87 | { |
---|
88 | ((RuleIndividual)inds[q]).rulesets[x].mutateRules( state, thread ); |
---|
89 | } |
---|
90 | */ |
---|
91 | ((RuleIndividual)inds[q]).mutate(state, thread); |
---|
92 | ((RuleIndividual)inds[q]).postprocessIndividual(state,thread); |
---|
93 | |
---|
94 | ((RuleIndividual)inds[q]).evaluated=false; |
---|
95 | } |
---|
96 | |
---|
97 | return n; |
---|
98 | } |
---|
99 | |
---|
100 | } |
---|
101 | |
---|
102 | |
---|