I suggest that you break your code up into much
smaller pieces and evaluate the individual pieces
make sure that each does what you want. This
includes: dropping the Module, evaluating your
loops step by step, and so on. As you verify that
each step works, you can then begin to put the
steps together. Even then you should verify that
the combined steps give you the results you expect,
i.e. those that you would get by evaluating the
steps individually. You may need to repeatedly
use Clear to remove previous assignments to your
symbols so that you will know that your results
come only from the code your are evaluating.
Eventually, you will come across "what you did
wrong" or a place in your code where combining
things does not work as you expect.
As you may have guessed, I can not tell "what
you did wrong" from what you have presented. Here
are some ideas for future posts that may help
your readers to help you. These are, in no way,
presented as a reproach.
First, there is nothing wrong with your code as
presented, that is, anyone can copy the code
paste it into a notebook and evaluate it without
seeing any errors. My guess is that you see the
error that you cite only when you evaluate your
function with actual arguments. Your comments
help some but nowhere near as much as a set of
lines defining some sample values for regionData,
adjacencies, partition, etc.
You seem to be using at least one of the Standard
Add On packages (what are InduceSubgraph,
FromAdjacencyLists, ... )? The presented code
does not show any package loading.
It would be difficult for someone who is not
familiar with the problem you are working on to
find what is wrong with your code. As presented,
yours is a problem for a paid consultant. If you
follow the process of breaking up your code to
determine the exact point where the problem occurs
and then present a complete set of code to
reproduce the problem, the readers of this forum
will more likely be able to help.