class Configuration {
protected int index; // index of the last element considered
protected boolean in; // true iff the last element is in the tentative sol'n
protected long worth; // total worth of all elements in this solution
protected long size; // total size of all elements in this solution
protected Configuration parent; // configuration deriving this one
protected static int[] s;
protected static int[] w;
protected static long bagSize;
/** The initial configuration - is only called for the root config. */
Configuration(int[] sizes, int[] worths, long sizeConstraint) {
/* Set static references to the constraints for all configurations */
s = sizes;
w = worths;
bagSize = sizeConstraint;
/* Set root configuration values */
index = -1;
in = false;
worth = 0L;
size = 0L;
parent = null;
}
/** Default constructor */
Configuration() { /* Assume default initial values */ }
/** Expand this configuration to one that includes next item */
public Configuration expandWithNext() {
Configuration c = new Configuration();
c.index = index + 1;
c.in = true;
c.worth = worth + w[c.index];
c.size = size + s[c.index];
c.parent = this;
return c;
}
/** Expand this configuration to one that doesn't include next item */
public Configuration expandWithoutNext() {
Configuration c = new Configuration();
c.index = index + 1;
c.in = false;
c.worth = worth;
c.size = size;
c.parent = this;
return c;
}