Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/parsimony/ProportionalTournamentSelection.java @ 13229

Last change on this file since 13229 was 6152, checked in by bfarka, 14 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 and George Mason University
3  Licensed under the Academic Free License version 3.0
4  See the file "LICENSE" for more information
5*/
6
7
8package ec.parsimony;
9
10import ec.select.*;
11import ec.*;
12import ec.util.*;
13import ec.steadystate.*;
14
15/*
16 * ProportionalTournamentSelection.java
17 *
18 * Created: Fri Feb 01 2002
19 * By: Liviu Panait
20 */
21
22/**
23 * This selection method adds parsimony pressure to the regular tournament selection.  The comparison of
24 * individuals is based on fitness with probability <i>prob</i>, and it is based on size with probability
25 * <i>1-prob</i>.  For each pairwise comparsion of individuals, the ProportionalTournamentSelection randomly decides
26 * whether to compare based on fitness or size.
27
28 <p><b>Typical Number of Individuals Produced Per <tt>produce(...)</tt> call</b><br>
29 Always 1.
30
31 <p><b>Parameters</b><br>
32 <table>
33 <tr><td valign=top><i>base.</i><tt>size</tt><br>
34 <font size=-1>int &gt;= 1</font></td>
35 <td valign=top>(the tournament size)</td></tr>
36
37 <tr><td valign=top><i>base.</i><tt>pick-worst</tt><br>
38 <font size=-1> bool = <tt>true</tt> or <tt>false</tt> (default)</font></td>
39 <td valign=top>(should we pick the <i>worst</i> individual in the tournament instead of the <i>best</i>?)</td></tr>
40
41 <tr><td valign=top><i>base.</i><tt>fitness-prob</tt><br>
42 <font size=-1> double &gt;= 0 and &lt;= 1</font></td>
43 <td valign=top>(the probability of comparing individuals based on fitness, rather than size)</td></tr>
44
45 </table>
46
47 <p><b>Default Base</b><br>
48 select.proportional-tournament
49
50 *
51 * @author Liviu Panait
52 * @version 1.0
53 */
54
55public class ProportionalTournamentSelection extends TournamentSelection
56    {
57    /** default base */
58    public static final String P_PROPORTIONAL_TOURNAMENT = "proportional-tournament";
59
60    /** The parameter for the probability of having the tournament based on fitness */
61    public static final String P_PROBABILITY = "fitness-prob";
62
63    /** The probability of having the tournament based on fitness */
64    public double fitnessPressureProb;
65
66    public Parameter defaultBase()
67        {
68        return SelectDefaults.base().push(P_PROPORTIONAL_TOURNAMENT);
69        }
70   
71    public void setup(final EvolutionState state, final Parameter base)
72        {
73        super.setup(state,base);
74       
75        Parameter def = defaultBase();
76
77        fitnessPressureProb = state.parameters.getDouble(base.push(P_PROBABILITY),def.push(P_PROBABILITY),0.0);
78        if( fitnessPressureProb<0.0 || fitnessPressureProb>1.0 )
79            state.output.fatal( "Probability must be between 0.0 and 1.0",
80                base.push(P_PROBABILITY),def.push(P_PROBABILITY));
81        }
82
83    public boolean betterThan(Individual first, Individual second, int subpopulation, EvolutionState state, int thread)
84        {
85        if (state.random[thread].nextBoolean(fitnessPressureProb))
86            return first.fitness.betterThan(second.fitness);
87        else
88            return first.size() < second.size();
89        }
90    }
Note: See TracBrowser for help on using the repository browser.