<p><em>(This is joint with <a href="https://cstheory.stackexchange.com/users/1173/jeff-phillips">Jeff Phillips</a>, who refuses to visit cstheory regularly ;))</em></p>
<p>I'm working with the problem formulation as stated and evolved in the comments. Namely, the goal is to find a minimum number of &quot;robots&quot; who can traverse a partition of an orthogonal polygon into rectangles, with the constraint that:</p>
<ul>
<li>A room can be entered and exited only in diametrically opposed directions (so north-south OR east-west)</li>
<li>A robot can only cross room boundaries along one (globally chosen) axis (so no 90 degree turns allowed)</li>
<li>Within a room though, a robot can do whatever it likes, as long it crosses room boundaries as specified.</li>
<li>Robots can backtrack arbitrarily as long as they follow the above rules.</li>
</ul>
<p>So a solution looks like an assignment of &quot;colors&quot; axes (NS or EW) to each room, and a traversal plan where each robot only traverses rooms having the same &quot;color&quot;.</p>
<p>Construct a graph where each rectangle is a vertex and two rectangles are marked as adjacent if they share a boundary. The edge is &quot;colored&quot; NS or EW, depending on the nature of the adjacency.</p>
<p><strong>Claim 1:</strong> If we are limited to one axis (NS or EW) then the minimum number of robots is merely the number of components in graph induced by edges of the corresponding color.</p>
<p><strong>Proof:</strong> Every edge represents a legal transition in that axis, so placing one robot in each connected component suffices, and you need at least one for each component for coverage.</p>
<p>Now consider the two partitions of the rectangle collection induced by the two colors. Notice that the minimum cardinality partition among these two might be far from optimal if for example your polygon is an L shape with each leg subdivided into n/2 rectangles. The individual graphs each have n/2 components, but the optimal solution is of size 2.</p>
<p>Construct a bipartite graph, in each node is one of the connected components of either of the partitions, and two nodes are connected if their corresponding components intersect. This graph is bipartite because the two sets of components were partitions.</p>
<p>Claim: the size of minimum vertex cover in this graph is the desired optimal soln.</p>
<p><strong>Proof.</strong>
Firstly note that in any optimal solution, the set of rectangles covered by any robot must be a subset of one of the components by reachability. Further, it costs nothing for this robot to cover any of the other rectangles in this partition. Hence wlog we can assume that OPT consists of a set of components that together cover all rectangles, i.e a set cover.</p>
<p>Secondly, since the graph is bipartite, we know that any rectangle is represented by exactly one edge between left and right sides. Thus, covering all rectangles actually requires covering all edges in this graph.</p>
<p>QED</p>
<p>VC in bipartite graphs can be solved in polynomial time, so the overall problem can be solved in polynomial time.</p>
<p>Comments ?</p>

CC BY-SA 2.5
2011-02-03T18:44:47.020Z
Thank you, Suresh.  I think my asking of this question must have been profoundly bad, because NS and EW are prohibited, but adjacent directions are ok. This may solve an orthogonal problem though, which could be very helpful, don't know yet.  In any case, I think I may have solved the case of a simple polygon anyway: it seems related to problems of rectilinear link center and link distance.  Choose a point in the link center, and draw the link graph to representative points in all rectangles. Then weight vertices wih (width, height) and use dynamic programming to minimize weight traversed.
Aaron Sterling
CC BY-SA 2.5
2011-02-03T18:48:17.110Z
That's sketchy, I know. I will post something more complete after the weekend, once I am more sure my idea works (or doesn't).  Snow and chemoinformatics have kept me from logging in here much this week.
Aaron Sterling
CC BY-SA 2.5
2011-02-03T19:38:04.367Z
ok that's confusing though, because in your post you were very clear that dimensions didn't matter: you merely wanted to count the number of robots needed. Your comment suggests that dimensions matter.
Suresh Venkat
CC BY-SA 2.5
2011-02-01T20:15:14.890Z
2011-02-01T20:15:14.890Z
2020-06-17T09:38:08.363Z
Suresh Venkat
<p>I assume that by "best starting room" you mean that it minimizes the sum of shortest walking distances from a fixed room to all the others.</p>

<p>Model your floor as undirected graph. Each room is a node. Nodes are connected if and only if there is a direct physical, walkable connection between them (such as a door). You can model hallways as a series of sufficiently small rooms, such as one piece per door. If you want, you can even model actual walking distances (center nodes in their rooms) by edge weights.</p>

<p>Once you have done this perform a SSSP (single source shortest path) algorithm for every non-hallway node. Choose the starting node that minimises the sum of distances found to all non-hallway nodes.</p>

<p>Note that this solution does not account for "saving" distance when visiting several rooms in a row. Such scenarios can be solved with the same model, but would become unpleasantly close to TSP (traveling salesman), but for your input sizes things should still work out.</p>

<p>(I am minimising the wrong thing, aren't I?)</p>

CC BY-SA 2.5
2011-01-30T18:36:15.487Z
2011-01-30T18:36:15.487Z
Raphael
<p>Suppose we have an orthogonal polygon with holes (all walls are axis-parallel).  All vertices can be on integer coordinates, if that helps.  Partition the polygon into rectangular rooms.  I would like to find the best room to start from, to visit all the rooms (rectangles). There's a limitation on my movement: in any room, I can only leave by two directions, say north and west. (Here best means there would only be one source in the plane dual graph with directed edges showing how to walk from room to room. If more than one source is required, I wish to minimize them.) </p>

<p>I have been looking at art gallery problems, and at VLSI papers on building rectilinear floorplans from network flows, and they are all tantalizingly close but far.  Can anyone provide suggestions so I can focus my search/proof construction?</p>

<p>EDIT to fix problem pointed out by Peter Taylor.  I can choose two directions per room. (probably they need to be adjacent, so NE is ok but NS is not.)  If I enter one room northward, I am automatically choosing South as one of thst new room's directions. (so only two in or out directions per room)  If I choose a  direction, and there are multiple rooms adjacent in that direction, I can enter all of them (and all of them then have the reverse direction assigned as one of their two directions), so the naive greedy approach would be to choose the direction that maximizes the number of rooms I can enter at that stage. I hope this is now complete, and understandable.</p>

CC BY-SA 2.5
2011-01-30T17:49:13.393Z
Can you restate the problem so that it's obvious why "Start in the southeast corner" isn't a trivial solution?
Peter Taylor
CC BY-SA 2.5
2011-01-30T18:38:19.070Z
Can you please elaborate on your cost model? Are you talking about a static property (minimal walking distances) or a dynamic one (visit all rooms in one sweep and backtrack as little as possible)? Do you have to return to you starting room?
Raphael
CC BY-SA 2.5
2011-01-30T18:55:10.680Z
@Raphael: the area of each room does not matter; nor does the distance traversed. (maybe later, yes, to tweak optimization) But for now: The only cost is the number of independent sources (starting rooms) required to visit all the rooms with the two-direction limitation. So the problem feels topological to me, not that that has helped me any.
Aaron Sterling
CC BY-SA 2.5
2011-01-30T19:35:38.900Z
This week I studied a lot about robotics, so I am going ahead and propose markov decision processes. I don't believe it can solve your problem right away , but trying it on relatively small polygons can perhaps give you a clue about what consists a good strategy/policy.
chazisop
CC BY-SA 2.5
2011-01-31T17:11:14.687Z
so if I understand correctly, the goal now is not to charge for distance travelled or cells visited, but to charge for number of sources needed ?
Suresh Venkat
CC BY-SA 2.5
2011-01-31T19:03:16.820Z
@Suresh: exactly so.  That has been my goal all along, but I appear to lack precision in my question-asking. Main objective: find the path (or set of paths) that minimizes the number of sources, i.e., the number of times one needs to start a new path.
Aaron Sterling
CC BY-SA 2.5
2011-01-31T20:29:25.200Z
also, you don't count movement within a rectangle, which is why you can enter and exit all rectangles on your top side with only one source. right ?
Suresh Venkat
CC BY-SA 2.5
2011-02-01T03:17:38.783Z
@Suresh: yes,that's correct. Thanks for your clarifying questions. :)
Aaron Sterling
<graph-algorithms><cg.comp-geom>
Find optimal room from which to visit all other rooms in a rectangular floorplan
Aaron Sterling
# Find optimal room from which to visit all other rooms in a rectangular floorplan

(Asked by: username_0 on 2011-01-30)

Suppose we have an orthogonal polygon with holes (all walls are axis-parallel). All vertices can be on integer coordinates, if that helps. Partition the polygon into rectangular rooms. I would like to find the best room to start from, to visit all the rooms (rectangles). There's a limitation on my movement: in any room, I can only leave by two directions, say north and west. (Here best means there would only be one source in the plane dual graph with directed edges showing how to walk from room to room. If more than one source is required, I wish to minimize them.)

I have been looking at art gallery problems, and at VLSI papers on building rectilinear floorplans from network flows, and they are all tantalizingly close but far. Can anyone provide suggestions so I can focus my search/proof construction?

EDIT to fix problem pointed out by Peter Taylor. I can choose two directions per room. (probably they need to be adjacent, so NE is ok but NS is not.) If I enter one room northward, I am automatically choosing South as one of thst new room's directions. (so only two in or out directions per room) If I choose a direction, and there are multiple rooms adjacent in that direction, I can enter all of them (and all of them then have the reverse direction assigned as one of their two directions), so the naive greedy approach would be to choose the direction that maximizes the number of rooms I can enter at that stage. I hope this is now complete, and understandable.

**Tags:** graph-algorithms, cg.comp-geom
> **Comments:**
> **username_1**: Can you restate the problem so that it's obvious why "Start in the southeast corner" isn't a trivial solution?  
> **username_2**: Can you please elaborate on your cost model? Are you talking about a static property (minimal walking distances) or a dynamic one (visit all rooms in one sweep and backtrack as little as possible)? Do you have to return to you starting room?  
> **username_0**: @Raphael: the area of each room does not matter; nor does the distance traversed. (maybe later, yes, to tweak optimization) But for now: The only cost is the number of independent sources (starting rooms) required to visit all the rooms with the two-direction limitation. So the problem feels topological to me, not that that has helped me any.  
> **username_3**: This week I studied a lot about robotics, so I am going ahead and propose markov decision processes. I don't believe it can solve your problem right away , but trying it on relatively small polygons can perhaps give you a clue about what consists a good strategy/policy.  
> **username_4**: so if I understand correctly, the goal now is not to charge for distance travelled or cells visited, but to charge for number of sources needed ?  
> **username_0**: @Suresh: exactly so.  That has been my goal all along, but I appear to lack precision in my question-asking. Main objective: find the path (or set of paths) that minimizes the number of sources, i.e., the number of times one needs to start a new path.  
> **username_4**: also, you don't count movement within a rectangle, which is why you can enter and exit all rectangles on your top side with only one source. right ?  
> **username_0**: @Suresh: yes,that's correct. Thanks for your clarifying questions. :)  

---

## 2 answers

### Answer by username_4 on 2011-02-01. Score: 1

*(This is joint with [Jeff Phillips](https://cstheory.stackexchange.com/users/1173/jeff-phillips), who refuses to visit cstheory regularly ;))*

I'm working with the problem formulation as stated and evolved in the comments. Namely, the goal is to find a minimum number of "robots" who can traverse a partition of an orthogonal polygon into rectangles, with the constraint that:

* A room can be entered and exited only in diametrically opposed directions (so north-south OR east-west)
* A robot can only cross room boundaries along one (globally chosen) axis (so no 90 degree turns allowed)
* Within a room though, a robot can do whatever it likes, as long it crosses room boundaries as specified.
* Robots can backtrack arbitrarily as long as they follow the above rules.

So a solution looks like an assignment of "colors" axes (NS or EW) to each room, and a traversal plan where each robot only traverses rooms having the same "color".

Construct a graph where each rectangle is a vertex and two rectangles are marked as adjacent if they share a boundary. The edge is "colored" NS or EW, depending on the nature of the adjacency.

**Claim 1:** If we are limited to one axis (NS or EW) then the minimum number of robots is merely the number of components in graph induced by edges of the corresponding color.

**Proof:** Every edge represents a legal transition in that axis, so placing one robot in each connected component suffices, and you need at least one for each component for coverage.

Now consider the two partitions of the rectangle collection induced by the two colors. Notice that the minimum cardinality partition among these two might be far from optimal if for example your polygon is an L shape with each leg subdivided into n/2 rectangles. The individual graphs each have n/2 components, but the optimal solution is of size 2.

Construct a bipartite graph, in each node is one of the connected components of either of the partitions, and two nodes are connected if their corresponding components intersect. This graph is bipartite because the two sets of components were partitions.

Claim: the size of minimum vertex cover in this graph is the desired optimal soln.

**Proof.**
Firstly note that in any optimal solution, the set of rectangles covered by any robot must be a subset of one of the components by reachability. Further, it costs nothing for this robot to cover any of the other rectangles in this partition. Hence wlog we can assume that OPT consists of a set of components that together cover all rectangles, i.e a set cover.

Secondly, since the graph is bipartite, we know that any rectangle is represented by exactly one edge between left and right sides. Thus, covering all rectangles actually requires covering all edges in this graph.

QED

VC in bipartite graphs can be solved in polynomial time, so the overall problem can be solved in polynomial time.

Comments ?

> **Comments:**
> **username_0**: Thank you, Suresh.  I think my asking of this question must have been profoundly bad, because NS and EW are prohibited, but adjacent directions are ok. This may solve an orthogonal problem though, which could be very helpful, don't know yet.  In any case, I think I may have solved the case of a simple polygon anyway: it seems related to problems of rectilinear link center and link distance.  Choose a point in the link center, and draw the link graph to representative points in all rectangles. Then weight vertices wih (width, height) and use dynamic programming to minimize weight traversed.  
> **username_0**: That's sketchy, I know. I will post something more complete after the weekend, once I am more sure my idea works (or doesn't).  Snow and chemoinformatics have kept me from logging in here much this week.  
> **username_4**: ok that's confusing though, because in your post you were very clear that dimensions didn't matter: you merely wanted to count the number of robots needed. Your comment suggests that dimensions matter.  

---

### Answer by username_2 on 2011-01-30. Score: 0

I assume that by "best starting room" you mean that it minimizes the sum of shortest walking distances from a fixed room to all the others.

Model your floor as undirected graph. Each room is a node. Nodes are connected if and only if there is a direct physical, walkable connection between them (such as a door). You can model hallways as a series of sufficiently small rooms, such as one piece per door. If you want, you can even model actual walking distances (center nodes in their rooms) by edge weights.

Once you have done this perform a SSSP (single source shortest path) algorithm for every non-hallway node. Choose the starting node that minimises the sum of distances found to all non-hallway nodes.

Note that this solution does not account for "saving" distance when visiting several rooms in a row. Such scenarios can be solved with the same model, but would become unpleasantly close to TSP (traveling salesman), but for your input sizes things should still work out.

(I am minimising the wrong thing, aren't I?)


---

