This file is indexed.

/usr/include/ga/GASelector.h is in libga-dev 2.4.7-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
// $Header$
/* ----------------------------------------------------------------------------
  selector.h
  mbwall 10aug94
  Copyright (c) 1995 Massachusetts Institute of Technology
                     all rights reserved

 DESCRIPTION:
  The selectors are functions that use information in fitness objects to pick
genomes from a population.  There are a number of selection criteria, and
not every selection method will work with every fitness object.

  These are the pre-defined selection methods.  A brief outline of what each 
one does is given here, but for more details (especially the theoretical 
foundations for each method), see Goldberg.  See the source file for some
implementation details that Goldberg does not delve into.
  The selection methods can, to some extent, be mixed and matched with the
various scaling methods.
  If you want to do speciating selection (e.g. DeJong-style crowding with
Hamming distance) then you will have to write your own selection method.

         Rank - pick the genome with the best fitness (not objective score)
RouletteWheel - weighted selection where individuals with better fitness have
                a greater chance of being selected than those with lower 
                scores.
   Tournament - similar to roulette, but instead of choosing one, choose two
                then pick the better of the two as the selected individuals
      Uniform - stochastic uniform selection picks randomly from the 
                population.  Each individual has as much chance as any other.
          SRS - stochastic remainder selection does a preselection based on 
                the expected number of each genome, then a random sampling on 
                the preselected list.
           DS - deterministic sampling is implemented as described in 
                Goldberg's book (as much as I could understand it, anyway).
---------------------------------------------------------------------------- */
#ifndef _ga_selector_h_
#define _ga_selector_h_

#include <string.h>
#include <ga/gaid.h>

class GAGenome;
class GAPopulation;

/* ----------------------------------------------------------------------------
   The base class definition for the selector object defines the interface.
Any derived selector must define a clone member and a select member.  If you
add any special data members then you should also define a copy member.
   Any selector can do its business based on fitness or objective scores.  The
base selector provides the mechanism for this.  Derived classes can use it if
they want to, or ignore it.
---------------------------------------------------------------------------- */
class GASelectionScheme  : public GAID {
public:
  GADefineIdentity("GASelectionScheme", GAID::Selection);
  enum { RAW, SCALED };

  GASelectionScheme(int w=SCALED) { which = w;}
  GASelectionScheme(const GASelectionScheme& orig) { copy(orig); }
  GASelectionScheme& operator=(const GASelectionScheme& orig)
    { if(&orig != this) copy(orig); return *this; }
  virtual ~GASelectionScheme() {}
  virtual GASelectionScheme* clone() const=0;
  virtual void copy(const GASelectionScheme& orig)
    { pop=orig.pop; which=orig.which; }
  virtual void assign(GAPopulation& p) { pop = &p; }
  virtual void update() {}
  virtual GAGenome& select() const=0;

protected:
  GAPopulation* pop;
  int which;			// should we use fitness or objective scores?
};


/* ----------------------------------------------------------------------------
   The rank selector simply picks the best individual in the population.  You 
can specify whether the selector should use the raw (objective) scores or the
scaled (fitness) scores to determine the best individual.  Default is fitness.
---------------------------------------------------------------------------- */
#if USE_RANK_SELECTOR == 1
class GARankSelector : public GASelectionScheme {
public:
  GADefineIdentity("GARankSelector", GAID::RankSelection);

  GARankSelector(int w=GASelectionScheme::SCALED) : GASelectionScheme(w) {}
  GARankSelector(const GARankSelector& orig) { copy(orig); }
  GARankSelector& operator=(const GASelectionScheme& orig) 
    { if(&orig != this) copy(orig); return *this; }
  virtual ~GARankSelector() {}
  virtual GASelectionScheme* clone() const { return new GARankSelector; }
  virtual GAGenome& select() const;
};
#endif

  
/* ----------------------------------------------------------------------------
   Roulette wheel uses a fitness-proportional algorithm for selecting 
individuals.
---------------------------------------------------------------------------- */
#if USE_ROULETTE_SELECTOR == 1 || USE_TOURNAMENT_SELECTOR == 1
class GARouletteWheelSelector : public GASelectionScheme {
public:
  GADefineIdentity("GARouletteWheelSelector", GAID::RouletteWheelSelection);

  GARouletteWheelSelector(int w=GASelectionScheme::SCALED) : 
  GASelectionScheme(w) 
    { psum = (float*)0; n = 0; }
  GARouletteWheelSelector(const GARouletteWheelSelector& orig) 
    { psum = (float*)0; n = 0; copy(orig); }
  GARouletteWheelSelector& operator=(const GASelectionScheme& orig) 
    { if(&orig != this) copy(orig); return *this; }
  virtual ~GARouletteWheelSelector() { delete [] psum; }
  virtual GASelectionScheme* clone() const
    { return new GARouletteWheelSelector; }
  virtual void copy(const GASelectionScheme& orig) {
    GASelectionScheme::copy(orig);
    const GARouletteWheelSelector& sel = 
      DYN_CAST(const GARouletteWheelSelector&,orig);
    delete [] psum;
    n = sel.n; 
    psum = new float[n];
    memcpy(psum, sel.psum, n * sizeof(float));
  }
  virtual GAGenome& select() const;
  virtual void update();

protected:
  int n;
  float* psum;
};
#endif

  
/* ----------------------------------------------------------------------------
   This version of the tournament selector does two roulette wheel selections
then picks the better of the two.  We derive from the roulette wheel class so
that we can use its update method.
---------------------------------------------------------------------------- */
#if USE_TOURNAMENT_SELECTOR == 1
class GATournamentSelector : public GARouletteWheelSelector {
public:
  GADefineIdentity("GATournamentSelector", GAID::TournamentSelection);

  GATournamentSelector(int w=GASelectionScheme::SCALED) : 
  GARouletteWheelSelector(w) {}
  GATournamentSelector(const GATournamentSelector& orig) { copy(orig); }
  GATournamentSelector& operator=(const GASelectionScheme& orig) 
    { if(&orig != this) copy(orig); return *this; }
  virtual ~GATournamentSelector() {}
  virtual GASelectionScheme* clone() const
    { return new GATournamentSelector; }
  virtual GAGenome& select() const;
};
#endif



/* ----------------------------------------------------------------------------
   Stochastic uniform sampling selection.  This is just a fancy name for 
random sampling.  Any individual in the population has as much chance of being
selected as any other.
---------------------------------------------------------------------------- */
#if USE_UNIFORM_SELECTOR == 1
class GAUniformSelector : public GASelectionScheme {
public:
  GADefineIdentity("GAUniformSelector", GAID::UniformSelection);

  GAUniformSelector(int w=GASelectionScheme::SCALED) : GASelectionScheme(w) { }
  GAUniformSelector(const GAUniformSelector& orig) { copy(orig); }
  GAUniformSelector& operator=(const GASelectionScheme& orig) 
    { if(&orig != this) copy(orig); return *this; }
  virtual ~GAUniformSelector() { }
  virtual GASelectionScheme* clone() const { return new GAUniformSelector; }
  virtual GAGenome& select() const;
};
#endif


/* ----------------------------------------------------------------------------
   Stochastic remainder sampling selection.  
---------------------------------------------------------------------------- */
#if USE_SRS_SELECTOR == 1
class GASRSSelector : public GASelectionScheme {
public:
  GADefineIdentity("GASRSSelector", GAID::SRSSelection);

  GASRSSelector(int w=GASelectionScheme::SCALED) : GASelectionScheme(w)
    { fraction = (float*)0; choices = (unsigned int *)0; n = 0; }
  GASRSSelector(const GASRSSelector& orig)
    { fraction = (float*)0; choices = (unsigned int *)0; n = 0; copy(orig); }
  GASRSSelector& operator=(const GASelectionScheme& orig) 
    { if(&orig != this) copy(orig); return *this; }
  virtual ~GASRSSelector() { delete [] fraction; delete [] choices; }
  virtual GASelectionScheme* clone() const { return new GASRSSelector; }
  virtual void copy(const GASelectionScheme& orig) {
    GASelectionScheme::copy(orig);
    const GASRSSelector& sel = DYN_CAST(const GASRSSelector&, orig);
    delete [] fraction;  delete [] choices;
    n = sel.n; 
    fraction = new float [n];
    choices = new unsigned int [n];
    memcpy(fraction, sel.fraction, n * sizeof(float));
    memcpy(choices, sel.choices, n * sizeof(unsigned int));
  }
  virtual GAGenome& select() const;
  virtual void update();

protected:
  float *fraction;
  unsigned int *choices;
  unsigned int n;
};
#endif


/* ----------------------------------------------------------------------------
   Deterministic sampling selection.  
---------------------------------------------------------------------------- */
#if USE_DS_SELECTOR == 1
class GADSSelector : public GASelectionScheme {
public:
  GADefineIdentity("GADSSelector", GAID::DSSelection);

  GADSSelector(int w=GASelectionScheme::SCALED) : GASelectionScheme(w) {
    fraction = (float*)0;
    choices = (unsigned int *)0; 
    idx = (unsigned int *)0; 
    n = 0; 
  }
  GADSSelector(const GADSSelector& orig) { 
    fraction = (float*)0; 
    choices = (unsigned int *)0; 
    idx = (unsigned int *)0; 
    n = 0; 
    copy(orig); 
  }
  GADSSelector& operator=(const GASelectionScheme& orig) 
    { if(&orig != this) copy(orig); return *this; }
  virtual ~GADSSelector() {
    delete [] fraction;
    delete [] choices;
    delete [] idx;
  }
  virtual GASelectionScheme* clone() const { return new GADSSelector; }
  virtual void copy(const GASelectionScheme& orig) {
    GASelectionScheme::copy(orig);
    const GADSSelector& sel = DYN_CAST(const GADSSelector&, orig);
    delete [] fraction;  delete [] choices; delete [] idx;
    n = sel.n; 
    fraction = new float [n];
    choices = new unsigned int [n];
    idx = new unsigned int [n];
    memcpy(fraction, sel.fraction, n * sizeof(float));
    memcpy(choices, sel.choices, n * sizeof(unsigned int));
    memcpy(idx, sel.idx, n * sizeof(unsigned int));
  }
  virtual GAGenome& select() const;
  virtual void update();

protected:
  float *fraction;
  unsigned int *choices;
  unsigned int *idx;
  unsigned int n;
};
#endif


#endif