/** Get this configuration's index */
public long getIndex() {
return index;
}
/** Get this configuration's size */
public long getSize() {
return size;
}
/** Get this configuration's worth */
public long getWorth() {
return worth;
}
/** Get this configuration's upper bound on future potential worth */
public double getUpperBound() {
int g; // index for greedy solution
double bound = worth; // start from current worth
long curSize=0L;
long sizeConstraint = bagSize - size;
/* Greedily add items until remaining size is overflowed */
for (g=index+1; (curSize <= sizeConstraint) && (g < s.length); g++) {
curSize += s[g];
bound += (double) w[g];
}
if (g < s.length) {
bound -= w[g]; // roll back to worth that fit
/* Add fractional component of the extra greedy item */
bound += (double) (bagSize - size)*w[g]/s[g];
}
return bound;
}
/** Print a solution from this configuration */
public void printSolution() {
Configuration c = this; // start with external-node Configuration
System.out.println("(Size,Worth) = " + c.size + "," + c.worth);
System.out.print("index-size-worth list = [");
for (; c.parent != null; c = c.parent) // march up to root
if (c.in) { // print index, size, and worth of next included item
System.out.print("(" + c.index);
System.out.print("," + s[c.index]);
System.out.print("," + w[c.index] + ")");
}
System.out.println("]");
}