lib/population.js
function Population(opts) {

    // allow use object for gene
    var genes = opts.genes.map(function(gene, index) {
        return index;
    });
    this.oriGenes = opts.genes;
    this.fitness = function(individual) {
        individual = individual.map(function(geneIndex) {
            return opts.genes[geneIndex];
        });
        return opts.fitness(individual);
    };

    this.genePool = GenePool(genes, opts.N, opts.weights);
    this.K = opts.K;
    this.N = opts.N;
    // the very first generation
    this.population = [];
    this.history = {}; // 记住产生过的个体

    // 默认尝试1000次仍无新结果则取消尝试
    this.maxLoop = opts.maxLoop || 1000;

    this.birthRate = opts.birthRate;
    this.mutationRate = opts.mutationRate;
}
function Population(opts) {

    // allow use object for gene
    var genes = opts.genes.map(function(gene, index) {
        return index;
    });
    this.oriGenes = opts.genes;
    this.fitness = function(individual) {
        individual = individual.map(function(geneIndex) {
            return opts.genes[geneIndex];
        });
        return opts.fitness(individual);
    };

    this.genePool = GenePool(genes, opts.N, opts.weights);
    this.K = opts.K;
    this.N = opts.N;
    // the very first generation
    this.population = [];
    this.history = {}; // 记住产生过的个体

    // 默认尝试1000次仍无新结果则取消尝试
    this.maxLoop = opts.maxLoop || 1000;

    this.birthRate = opts.birthRate;
    this.mutationRate = opts.mutationRate;
}
N: 个体基因数 K: 种群规模（种群稳定时的数量） genes: 基因 weights: 基因权重，影响出现的可能性大小 mutationRate: 基因突变率，大约有多少比例的基因需要突变 birthRate: 出生率 timeout: 最大时限