Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/breed/ReproductionPipeline.java @ 6152

Last change on this file since 6152 was 6152, checked in by bfarka, 13 years ago

added ecj and custom statistics to communicate with the okb services #1441

File size: 2.9 KB
Line 
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
8package ec.breed;
9import ec.*;
10import ec.util.*;
11
12/*
13 * ReproductionPipeline.java
14 *
15 * Created: Thu Nov  8 13:39:32 EST 2001
16 * By: Sean Luke
17 */
18
19/**
20 * ReproductionPipeline is a BreedingPipeline which simply makes a copy
21 * of the individuals it recieves from its source.  If the source is another
22 * BreedingPipeline, the individuals have already been cloned, so ReproductionPipeline
23 * won't clone them again...unless you force it to do so by turning on the <tt>must-clone</tt>
24 * parameter.
25 *
26 <p><b>Typical Number of Individuals Produced Per <tt>produce(...)</tt> call</b><br>
27 ...as many as the child produces
28
29 <p><b>Number of Sources</b><br>
30 1
31
32 <p><b>Parameters</b><br>
33 <table>
34 <tr><td valign=top><i>base.</i><tt>must-clone</tt><br>
35 <font size=-1>bool =  <tt>true</tt> or <tt>false</tt> (default)</font></td>
36 <td valign=top>(do we <i>always</i> clone our individuals, or only clone if the individual hasn't already been cloned by our source?  Typically you want <tt>false</tt>)</td></tr>
37
38 </table>
39 <p><b>Default Base</b><br>
40 breed.reproduce
41
42 * @author Sean Luke
43 * @version 1.0
44 */
45
46public class ReproductionPipeline extends BreedingPipeline
47    {
48    public static final String P_REPRODUCE = "reproduce";
49    public static final String P_MUSTCLONE = "must-clone";
50    public static final int NUM_SOURCES = 1;
51   
52    public boolean mustClone;
53   
54    public Parameter defaultBase() { return BreedDefaults.base().push(P_REPRODUCE); }
55
56    public int numSources() { return NUM_SOURCES; }
57
58    public void setup(final EvolutionState state, final Parameter base)
59        {
60        super.setup(state,base);
61        Parameter def = defaultBase();
62        mustClone = state.parameters.getBoolean(base.push(P_MUSTCLONE), def.push(P_MUSTCLONE),false);
63               
64        if (likelihood != 1.0)
65            state.output.warning("ReproductionPipeline given a likelihood other than 1.0.  This is nonsensical and will be ignored.",
66                base.push(P_LIKELIHOOD),
67                def.push(P_LIKELIHOOD));
68        }
69       
70    public int produce(final int min,
71        final int max,
72        final int start,
73        final int subpopulation,
74        final Individual[] inds,
75        final EvolutionState state,
76        final int thread)
77        {
78        // grab individuals from our source and stick 'em right into inds.
79        // we'll modify them from there
80        int n = sources[0].produce(min,max,start,subpopulation,inds,state,thread);
81               
82        // this code is basically the same as BreedingPipeline.reproduce() but we copy it here
83        // because of the 'mustClone' option.
84               
85        if (mustClone || sources[0] instanceof SelectionMethod)
86            for(int q=start; q < n+start; q++)
87                inds[q] = (Individual)(inds[q].clone());
88        return n;
89        }
90    }
Note: See TracBrowser for help on using the repository browser.