You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-16Lines changed: 24 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -266,11 +266,14 @@ Let's have a look at the GA struct.
266
266
267
267
```go
268
268
typeGAstruct {
269
-
//Fields that are provided by the user
269
+
//Required fields
270
270
NewGenomeNewGenome
271
271
NPopsint
272
272
PopSizeint
273
273
ModelModel
274
+
275
+
// Optional fields
276
+
NBestint
274
277
MigratorMigrator
275
278
MigFrequencyint
276
279
SpeciatorSpeciator
@@ -279,32 +282,37 @@ type GA struct {
279
282
RNG *rand.Rand
280
283
ParallelEvalbool
281
284
282
-
// Fields that are generated at runtime
285
+
// Fields generated at runtime
283
286
PopulationsPopulations
284
-
BestIndividual
285
-
CurrentBestIndividual
287
+
HallOfFameIndividuals
286
288
Age time.Duration
287
289
Generationsint
288
290
}
289
291
```
290
292
291
293
You have to fill in the first set of fields, the rest are generated when calling the `GA`'s `Initialize()` method. Check out the examples in `presets.go` to get an idea of how to fill them out.
292
294
293
-
-`NewGenome` is a method that returns a random genome that you defined in the previous step. gago will use this method to produce an initial population. Again, gago provides some methods for common random genome generation.
294
-
-`NPops` determines the number of populations that will be used.
295
-
-`PopSize` determines the number of individuals inside each population.
296
-
-`Model` determines how to use the genetic operators you chose in order to produce better solutions, in other words it's a recipe. A dedicated section is available in the [model section](#models).
297
-
-`Migrator` and `MigFrequency` should be provided if you want to exchange individuals between populations in case of a multi-population GA. If not the populations will be run independently. Again this is an advanced concept in the genetic algorithms field that you shouldn't deal with at first.
298
-
-`Speciator` will split each population in distinct species at each generation. Each specie will be evolved separately from the others, after all the species has been evolved they are regrouped.
299
-
-`Logger` is optional and provides basic population statistics, you can read more about it in the [logging section](#logging-population-statistics).
300
-
-`Callback` is optional will execute any piece of code you wish every time `ga.Enhance()` is called. `Callback` will also be called when `ga.Initialize()` is. Using a callback can be useful for many things:
295
+
- Required fields
296
+
-`NewGenome` is a method that returns a random genome that you defined in the previous step. gago will use this method to produce an initial population. Again, gago provides some methods for common random genome generation.
297
+
-`NPops` determines the number of populations that will be used.
298
+
-`PopSize` determines the number of individuals inside each population.
299
+
-`Model` determines how to use the genetic operators you chose in order to produce better solutions, in other words it's a recipe. A dedicated section is available in the [model section](#models).
300
+
- Optional fields
301
+
-`NBest` determines how many of the best individuals encountered should be regarded in the `HallOfFame` field. This defaults to 1.
302
+
-`Migrator` and `MigFrequency` should be provided if you want to exchange individuals between populations in case of a multi-population GA. If not the populations will be run independently. Again this is an advanced concept in the genetic algorithms field that you shouldn't deal with at first.
303
+
-`Speciator` will split each population in distinct species at each generation. Each specie will be evolved separately from the others, after all the species has been evolved they are regrouped.
304
+
-`Logger` is optional and provides basic population statistics, you can read more about it in the [logging section](#logging-population-statistics).
305
+
-`Callback` is optional will execute any piece of code you wish every time `ga.Enhance()` is called. `Callback` will also be called when `ga.Initialize()` is. Using a callback can be useful for many things:
301
306
- Calculating specific population statistics that are not provided by the logger
302
307
- Changing parameters of the GA after a certain number of generations
303
308
- Monitoring for converging populations
304
-
-`RNG` can be set to make results reproducible. If it is not provided then a default `rand.New(rand.NewSource(time.Now().UnixNano()))` will be used. If you want to make your results reproducible use a constant source, e.g. `rand.New(rand.NewSource(42))`.
305
-
-`ParallelEval` determines if a population is evaluated in parallel. The rule of thumb is to set this to `true` if your `Evaluate` method is expensive, if not it won't be worth the overhead. Refer to the [section on parallelism](#a-note-on-parallelism) for a more comprehensive explanation.
306
-
307
-
Essentially, only `NewGenome`, `NPops`, `PopSize` and `Model` are required to initialize and run a GA. The other fields are optional.
309
+
-`RNG` can be set to make results reproducible. If it is not provided then a default `rand.New(rand.NewSource(time.Now().UnixNano()))` will be used. If you want to make your results reproducible use a constant source, e.g. `rand.New(rand.NewSource(42))`.
310
+
-`ParallelEval` determines if a population is evaluated in parallel. The rule of thumb is to set this to `true` if your `Evaluate` method is expensive, if not it won't be worth the overhead. Refer to the [section on parallelism](#a-note-on-parallelism) for a more comprehensive explanation.
311
+
- Fields populated at runtime
312
+
-`Populations` is where all the current populations and individuals are kept.
313
+
-`HallOfFame` contains the `NBest` individuals ever encountered. This slice is always sorted, meaning that the first element of the slice will be the best individual ever encountered.
314
+
-`Age` indicates the duration the GA has spent calling the `Enhance` method.
315
+
-`Generations` indicates how many times the `Enhance` method has been called.
0 commit comments