public ArrayList<Node> generateGrid(int w, int h){
        ArrayList<Node> nodes = new ArrayList<Node>();
        for(int i=0;i<(w*h);i++)
        {
            Node n = new Node(i);
            nodes.add(n);
        }
        int nc = 0;
        int lc = 0;
        Link link;
        for(int j = 0 ; j<h;j++)
        {
            for(int i = 0; i<w;i++)
            {
                if(i < w-1) // link to the right
                {
                    link = new Link(nodes.get(nc+1));
                    nodes.get(nc).addLink(link);
                    lc++;
                }
                if(i > 0) // link to the left
                {
                    link = new Link(nodes.get(nc-1));
                    nodes.get(nc).addLink(link);
                    lc++;
                }
                if(j < h-1) // link down
                {
                    link = new Link(nodes.get(nc+w));
                    nodes.get(nc).addLink(link);
                    lc++;
                }
                if(j > 0) // link up
                {
                    link = new Link(nodes.get(nc-w));
                    nodes.get(nc).addLink(link);
                    lc++;
                }
                nc++;
            }
        }
        if(verb)
        {
            System.out.println("Generated grid with " + nc + " nodes and " + (double)lc/2d + " links.");
        }
        return nodes;
    }