我正在研究旅行商问题的分支定界算法,但遇到了一点麻烦。我正在使用一个非常标准的队列,其中的节点代表顶点(路径)的子集。我很确定我已经解决了整个问题,但目前我有公共类 Queue,在它下面有私有类 Node,它的所有属性:当前路径、下限等。
但是,在我的主程序中,我初始化了节点队列并创建了两个起始节点,但出现错误“节点无法解析为类型”。我认为这是因为它在 Queue 类中并且主程序无法访问,但是当我将它移出时,我在连接到节点的项目上的其他任何地方都会出错。
我真的希望这是有道理的,我不确定如何解释它,但其他一切似乎都很好。这是我的代码片段以进行澄清:
`public class Queue<Item> implements Iterable<Item> {
private int N; // number of elements on queue
private Node first; // beginning of queue
private Node last; // end of queue
// helper linked list class
public class Node {
public int level; //level on the tree
public int[] path; //current path
public int bound; //lower bound
public Item item;
public Node next; //the next in the path
public boolean inPath; //checks to see if the vertex is in the current path
public int missingV; //the vertex that is missing from the path
}`
那是我声明 Node 类的地方,也是我在主程序中实际使用它的地方:
`public static void main(String args[]) {
int n = 4;
int[][] W = new int[][] {{0,2,4,7},{2,0,7,3},{4,7,0,5},{6,3,5,0}};
int[] opttour;
Queue<Node> PQ = new Queue<Node>();
Node u = new Node();
Node v = new Node();`