A meta-algorithm is a reusable algorithmic template: generic structural code defines the technique, while problem-specific components complete it for each instance. section 18.1.2
Design a meta-algorithm by separating the stable framework from components supplied for the target problem:
- Keep the optimization structure generic, including the main genetic-algorithm flow. section 18.1.2
- Supply problem-specific chromosome representations and methods, such as those for a 0–1 knapsack instance. section 18.1.2
- Pass varying behavior through composition, runtime arguments using the strategy pattern, or compile-time inheritance using the template pattern. section 18.1.2
Genetic optimization for knapsack
A genetic-algorithm template can model each organism with an Individual class containing a chromosome and fitness operation. For a knapsack instance, chromosome encodings distinguish selections such as wheat flour and tomatoes from wheat flour, rice, and beans. section 18.1.2
Figure 18.4 Examples of encoding chromosomes for the knapsack problem (the specific instance described in section 1.4). Two figures are shown: the differences in the genotypes (the two strings) are reflected in the phenotypes (the goods taken to Mars: wheat flour and tomatoes versus wheat flour, rice, and beans). The latter chromosome encodes the best solution for the instance of the problem summed up in table 18.1.
Compare chromosome genotypes with their decoded knapsack selections, including the encoding for the best stated solution. section 18.1.2
