* @param dependOn the index number of pathway this one depends on, -1 if no dependency
     * @return
     */
    private ArrayList<Queue> pathwayQueues(LayoutInfo[] layouts,int[] dependOn){
        ArrayList<Queue> queues = new ArrayList<Queue>();//each queue is for a disconnected group of pathways
        int n=layouts.length;
        boolean[] added = new boolean[n];//whether the pathway is added into a queue
        //boolean[] processed = new boolean[n];//whether all neighbours of this pathway are added into some queue
        Queue<Integer> toProcess = new LinkedList<Integer>();

        //current queue to add pathways into
        //if not null, then exists a queue to add pathways into
        //otherwise need to create a new queue(for disconnected group of pathways)
        Queue currentQueue=null;        

        Arrays.sort(layouts,new LayoutBoxSizeComparator());

        /*
        for(LayoutInfo i:layouts){
            System.out.println(i.getExactLayoutBox().size());
        }
        //*/

        for(int i=n-1;i>=0;i--){
            if(added[i]){
                continue;
            }

            currentQueue=new LinkedList<Integer>();//current queue to add pathways into
            queues.add(currentQueue);
            toProcess.add(i);
            currentQueue.add(i);
            added[i]=true;
            dependOn[i]=-1;

            while(toProcess.size() != 0){
                int p = toProcess.remove();                
                for(int j=n-2;j>=0;j--){//the first one is already added, so j starting from 1
                    //find all non-visited neighbour pathways of layout[p]
                    if(added[j]){
                        continue;
                    }
                    if(layouts[p].sharedNodes(layouts[j]).size() > 0 && !added[j]){
                        currentQueue.add(j);
                        toProcess.add(j);
                        added[j]=true;
                        dependOn[j]=p;
                    }
                }
                //processed[p]=true;
            }
            currentQueue=null;//finished a connected group of pathways
        }

        return queues;
    }