/*
* Copyright 2002, 2003, 2004, 2005 - Koalog
*/
package com.koalog.jcs.examples;
import org.apache.log4j.PropertyConfigurator;
import com.koalog.jcs.variable.IntegerVariable;
import com.koalog.jcs.variable.BooleanVariable;
import com.koalog.jcs.constraint.BaseProblem;
import com.koalog.jcs.constraint.arithmetic.Mul;
import com.koalog.jcs.constraint.arithmetic.Sum;
import com.koalog.jcs.constraint.arithmetic.SmallerSum;
/**
* This is the famous Knapsack problem.
* Given:
*
* - n objects of given volumes and weights,
* - a bag of a given capacity (volume),
* it consists in putting in the bag as much weight as possible.
*
*
* @author Yan Georget
*/
public class KnapsackProblem extends BaseProblem {
//------------------------------------------------------------------------
// PROPERTIES
//------------------------------------------------------------------------
IntegerVariable weight;
//------------------------------------------------------------------------
// CONSTRUCTORS
//------------------------------------------------------------------------
/**
* Sole constructor.
* @param volumes the volumes
* @param weights the weights
* @param capacity the capacity
*/
public KnapsackProblem(int[] volumes, int[] weights, int capacity) {
int n = volumes.length;
BooleanVariable[] b = new BooleanVariable[n];
IntegerVariable[] v = new IntegerVariable[n];
IntegerVariable[] w = new IntegerVariable[n];
for (int i=0; i