public RegionGraph constructRegionGraph (FactorGraph mdl)
{
if (mdl instanceof UndirectedGrid) {
RegionGraph rg = new RegionGraph ();
UndirectedGrid grid = (UndirectedGrid) mdl;
// First set up regions for all
for (int x = 0; x < grid.getWidth () - 1; x++) {
for (int y = 0; y < grid.getHeight () - 1; y++) {
Variable[] vars = new Variable[] {
grid.get (x, y),
grid.get (x+1, y),
grid.get (x+1, y+1),
grid.get (x, y+1), };
Factor[] edges = new Factor[] {
mdl.factorOf (vars[0], vars[1]),
mdl.factorOf (vars[1], vars[2]),
mdl.factorOf (vars[2], vars[3]),