JGAP

examples.knapsack
Class KnapsackMain

java.lang.Object
  extended by examples.knapsack.KnapsackMain

public class KnapsackMain
extends java.lang.Object

This class provides an implementation of the classic knapsack problem using a genetic algorithm. The goal of the problem is to reach a given volume (of a knapsack) by putting a number of items into the knapsack. The closer the sum of the item volumes to the given volume the better.

For further descriptions, compare the "coins" example also provided.

Since:
2.3

Field Summary
static java.lang.String[] itemNames
          Names of arbitrary items, only for outputting something imaginable
static double[] itemVolumes
          Volumes of arbitrary items in ccm
 
Constructor Summary
KnapsackMain()
           
 
Method Summary
static void findItemsForVolume(double a_knapsackVolume)
          Executes the genetic algorithm to determine the minimum number of items necessary to make up the given target volume.
static void main(java.lang.String[] args)
          Main method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

itemVolumes

public static final double[] itemVolumes
Volumes of arbitrary items in ccm


itemNames

public static final java.lang.String[] itemNames
Names of arbitrary items, only for outputting something imaginable

Constructor Detail

KnapsackMain

public KnapsackMain()
Method Detail

findItemsForVolume

public static void findItemsForVolume(double a_knapsackVolume)
                               throws java.lang.Exception
Executes the genetic algorithm to determine the minimum number of items necessary to make up the given target volume. The solution will then be written to the console.

Parameters:
a_knapsackVolume - the target volume for which this method is attempting to produce the optimal list of items
Throws:
java.lang.Exception
Since:
2.3

main

public static void main(java.lang.String[] args)
Main method. A single command-line argument is expected, which is the volume to create (in other words, 75 would be equal to 75 ccm).

Parameters:
args - first and single element in the array = volume of the knapsack to fill as a double value
Since:
2.3

JGAP