Implementing branch and bound for knapsack

前端 未结 1 1604
醉话见心
醉话见心 2021-01-03 06:25

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

相关标签:
1条回答
  • 2021-01-03 07:13

    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(..)

    0 讨论(0)
提交回复
热议问题