I\'m having a headache implementing this (awful) pseudo-java code (I wonder: why the hell people do that?) for the b&b knapsack problem. This is my implementation so far
I have only tested it with the given example, but it looks like that wherever the pseudocode says
enqueue(Q, u)
you should add a copy of u
to the linked list, rather than passing a reference to u
and continue manipulating it.
In other words, define a copy constructor for the class Node
and do
Q.offer(new Node(u));
instead of
Q.offer(u);
In fact, the code you give above only allocates two instances of the class Node
per call to branchAndBound(..)