% make a graph representing a rectangular grid

function g=make_grid(A,B)
g=zeros(A*B);
  V=A*B;
  for k=1:A
      for j=1:B
          v=j+(k-1)*A;
          if k<A
              g(v,v+A)=1;
          end 
          if k>1
              g(v,v-A)=1;
          end
          if j<B
              g(v,v+1)=1;
          end
          if j>1
              g(v,v-1)=1;
          end
      end % for j
  end % for k
  g=min(1,g+g');
  return
