9

If a game map is partitioned into subgraphs, how to minimize edges between subgraphs?

I have a problem, Im trying to make A* searches through a grid based game like pacman or sokoban, but i need to find "enclosures". What do i mean by enclosures? subgraphs with as few cut edges as possible given a maximum size and minimum size for number of vertices for each subgraph that act as a soft constraints.
Alternatively you could say i am looking to find bridges between subgraphs, but its generally the same problem.


Example

Gridbased gamemap example http://dl.dropbox.com/u/1029671/map1.jpg

Given a game that looks like this, what i want to do is find enclosures so that i can properly find entrances to them and thus get a good heuristic for reaching vertices inside these enclosures.

alt text http://dl.dropbox.com/u/1029671/map.jpg

So what i want is to find these colored regions on any given map.


My Motivation

The reason for me bothering to do this and not just staying content with the performance of a simple manhattan distance heuristic is that an enclosure heuristic can give more optimal results and i would not have to actually do the A* to get some proper distance calculations and also for later adding competitive blocking of opponents within these enclosures when playing sokoban type games. Also the enclosure heuristic can be used for a minimax approach to finding goal vertices more properly.

Possible solution

A possible solution to the problem is the Kernighan Lin algorithm :

function Kernighan-Lin(G(V,E)):
  determine a balanced initial partition of the nodes into sets A and B
  do
     A1 := A; B1 := B
     compute D values for all a in A1 and b in B1
     for (i := 1 to |V|/2)
      find a[i] from A1 and b[i] from B1, such that g[i] = D[a[i]] + D[b[i]] - 2*c[a][b] is maximal
      move a[i] to B1 and b[i] to A1
      remove a[i] and b[i] from further consideration in this pass
      update D values for the elements of A1 = A1 / a[i] and B1 = B1 / b[i]
    end for
    find k which maximizes g_max, the sum of g[1],...,g[k]
    if (g_max > 0) then
       Exchange a[1],a[2],...,a[k] with b[1],b[2],...,b[k]
 until (g_max <= 0)
 return G(V,E)

My problem with this algorithm is its runtime at O(n^2 * lg(n)), i am thinking of limiting the nodes in A1 and B1 to the border of each subgraph to reduce the amount of work done.

I also dont understand the c[a][b] cost in the algorithm, if a and b do not have an edge between them is the cost assumed to be 0 or infinity, or should i create an edge based on some heuristic.

Do you know what c[a][b] is supposed to be when there is no edge between a and b? Do you think my problem is suitable to use a multi level method? Why or why not? Do you have a good idea for how to reduce the work done with the kernighan-lin algorithm for my problem?

Tore
  • 579
  • 1
  • 6
  • 19
  • 1
    I don't understand how you come to color exactly this way in the second image. What are your criteria? Why isn't the yellow blob sub-divided? How do you define the graph? A vert is a spot and its neighbours are the (at most) four spots to the north, south, east and west? – ziggystar Apr 06 '10 at 13:46
  • yes, that is the way i define the graph, each square(vertex) has its neighbours to north, east, south and west. The picture is just to illustrate, you can divide yellow, red, black etc into several closures, its just the constraints of max/min vertices per closure regulating the nature of the subdividing. So if my min constraint is 8 vertices then that yellow closure would fullfill the constraint, but it the min constraint was 4 it could end just below the box. Finding an algorithm that works generally for several maps and closures is what im after. – Tore Apr 06 '10 at 14:10
  • You want to partition the map into subgraphs. The size of the subgraphs has to adhere to some bounds (max, min size) and the number of edges between partitions shall be minimized? – ziggystar Apr 06 '10 at 14:18
  • correct. That is exactly what i want to do. – Tore Apr 06 '10 at 14:43
  • Kernighan Lin gave me wierd solutions when using it on K different subgraphs. I think its because of the way i divide up the graph into K subgraphs. – Tore Apr 27 '10 at 00:06

2 Answers2

1

Not sure of the question, but perhaps you can use the max-flow/min-cut duality.

There are specialized and efficient algorithms for the max-flow that you can use to solve the primal.

You then need to obtain the dual solution using the technique described here.

PS: let me know if you need help with Operations Research jargon.

baol
  • 4,362
  • 34
  • 44
0

Maybe have a look at this link on Wikipedia for further reading.

The graph partitioning problem in mathematics consists of dividing a graph into pieces, such that the pieces are of about the same size and there are few connections between the pieces.

Graph Partition

ziggystar
  • 28,410
  • 9
  • 72
  • 124