/********************************************************************** # Copyright (c) EWA Systems Inc. 1998 - 2005 All Rights Reserved # No part of this program may be photocopied, reproduced, # or translated to another programming language without # the prior written consent of EWA Systems. **********************************************************************/ package com.ewasystems.opt.ga.test; import com.ewasystems.opt.ga.GeneticAlleleSet; import com.ewasystems.opt.ga.GeneticEngine; import com.ewasystems.opt.ga.GeneticGene; import com.ewasystems.opt.ga.GeneticProblem; import com.ewasystems.opt.ga.GeneticRunTask; /** *
Genetic Algorithm Test Case: Multi Knapsack
*Description: Maximize Value in Limited Weight Backpack where * Value differs between Backpacks
*Copyright: EWASystems Copyright (c) 1998 - 2005
*Company: EWASystems
* @author Lincoln Evans-Beauchamp * @version 1.0 */ public class MultiKnapsack extends GeneticProblem { /** Backpack Weight Limit */ protected int weightLimit = 625; /** Object Weights */ protected int[] objectWeights = new int[150]; /** Object Values */ protected double[][] objectValues = new double[150][3]; /** * Problem Constructor */ public MultiKnapsack() { super("3 Knapsacks 150 Objects", "Minimize f(x) = 1/4000*sum(x(i)-100)^2 - prod((x(i)-100)/sqrt(i)) + 1 where X = [-600, 600] by .02"); for (int i=0; i<150; i++) { objectWeights[i] = (int)(10d + 10d*Math.random()); objectValues[i][0] = (int)(100d*Math.random()); objectValues[i][1] = (int)(100d*Math.random()); objectValues[i][2] = (int)(100d*Math.random()); } } /** * The Objective Function * @param gene The Genetic Gene to Test * @return double: The Genetic Gene's Fitness */ public double f(GeneticGene gene) { double[] wt = new double[3]; double value = 0d; for (int i=0; i