Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/breed/ForceBreedingPipeline.java @ 7611

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

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

File size: 3.3 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 * ForceBreedingPipeline.java
14 *
15 * Created: December 28, 1999
16 * By: Sean Luke
17 */
18
19/**
20 *
21 * ForceBreedingPipeline has one source.  To fill its quo for produce(...),
22 * ForceBreedingPipeline repeatedly forces its source to produce exactly numInds
23 * individuals at a time, except possibly the last time, where the number of
24 * individuals its source produces may be as low as 1.  This is useful for forcing
25 * Crossover to produce only one individual, or mutation to produce 2 individuals
26 * always, etc.
27
28 <p><b>Typical Number of Individuals Produced Per <tt>produce(...)</tt> call</b><br>
29 Determined by <i>base</i>.<tt>num-inds</tt>
30
31 <p><b>Number of Sources</b><br>
32 1
33
34 <p><b>Parameters</b><br>
35 <table>
36 <tr><td valign=top><i>base</i>.<tt>num-inds</tt><br>
37 <font size=-1>int &gt;= 1</font></td>
38 <td valign=top>(The number of individuals this breeding pipeline will force its
39 source to produce each time in order to fill the quo for produce(...).)</td></tr>
40 </table>
41
42 <p><b>Default Base</b><br>
43 breed.force
44
45 *
46 * @author Sean Luke
47 * @version 1.0
48 */
49
50public class ForceBreedingPipeline extends BreedingPipeline
51    {
52    public static final String P_NUMINDS = "num-inds";
53    public static final String P_FORCE = "force";
54
55    public int numInds;
56
57    public Parameter defaultBase()
58        {
59        return BreedDefaults.base().push(P_FORCE);
60        }
61
62    public int numSources() { return 1; }   
63
64    public void setup(final EvolutionState state, final Parameter base)
65        {
66        super.setup(state,base);
67        Parameter def = defaultBase();
68        numInds = state.parameters.getInt(base.push(P_NUMINDS),def.push(P_NUMINDS),1);
69        if (numInds==0)
70            state.output.fatal("ForceBreedingPipeline must produce at least 1 child at a time", base.push(P_NUMINDS),def.push(P_NUMINDS));
71
72        // declare that likelihood isn't used
73        if (likelihood < 1.0f)
74            state.output.warning("ForceBreedingPipeline does not respond to the 'likelihood' parameter.",
75                base.push(P_LIKELIHOOD), def.push(P_LIKELIHOOD));
76        }
77
78    /** Returns the max of typicalIndsProduced() of all its children */
79    public int typicalIndsProduced()
80        {
81        return numInds;
82        }
83
84    public int produce(final int min,
85        final int max,
86        final int start,
87        final int subpopulation,
88        final Individual[] inds,
89        final EvolutionState state,
90        final int thread)
91
92        {
93        int n = numInds;
94        if (n < min) n = min;
95        if (n > max) n = max;
96
97        int total;
98        int numToProduce;
99        for(total=0; total<n; )
100            {
101            numToProduce = n - total;
102            if (numToProduce > numInds) numToProduce = numInds;
103
104            total += sources[0].produce(numToProduce,numToProduce,start+total,
105                subpopulation,inds,state,thread);
106            }
107       
108        // clone if necessary
109        if (sources[0] instanceof SelectionMethod)
110            for(int q=start; q < total+start; q++)
111                inds[q] = (Individual)(inds[q].clone());
112               
113        return total;
114        }
115    }
Note: See TracBrowser for help on using the repository browser.