package com.company.genetic_algorithm_knapsack; import java.util.Random; // this is a chromosome public class Individual { // the genes are not binary values // [0, 1, 1, 0, 0] private int[] genes; private int[] weights; private int[] values; private int fitness; private Random random; public Individual(int[] weights, int[] values) { this.weights = weights; this.values = values; this.genes = new int[values.length]; this.random = new Random(); } public int getFitness() { // MAX value but <= weight, if not, penaty ! int weight = 0; int value = 0; for(int i=0;i