0

This image shows a made-up trail with a restroom (cyan point). I would like to add 2 more restrooms where the maximum distance along trail from anywhere on the trail to the closest of the 3 restrooms is minimized.

# Data

# trail is a list of segments between the magenta and/or cyan points (in the image).
# Each of the segments in turn is a list of endpoints.
trail = [[[0, 0], [1, 0]], [[2, 0], [3, 0]], [[3, 0], [4, 0]], [[4, 0], [5, 0]], [[6, 0], [7, 0]], [[5, 1], [6, 1]], [[1, 2], [2, 2]], [[4, 2], [5, 2]], [[1, -1], [2, -1]], [[3, -1], [4, -1]], [[5, -1], [6, -1]], [[4, -2], [5, -2]], [[1, 2], [1, 0]], [[1, 0], [1, -1]], [[2, 2], [2, 0]], [[2, 0], [2, -1]], [[3, 2], [3, 0]], [[4, 2], [4, 0]], [[4, 0], [4, -1]], [[4, -1], [4, -2]], [[5, 2], [5, 1]], [[5, 1], [5, 0]], [[5, 0], [5, -1]], [[5, -1], [5, -2]], [[6, 1], [6, 0]], [[6, 0], [6, -1]], [[3, -1], [4, 0]]]

restroom = [0, 0]

This is a simplified version of this question.

Hints will be appreciated as well. Thanks.

Community
  • 1
  • 1
user24397
  • 21
  • 4
  • It would be very helpful to have the image posted in some public urls. and just include the url in your question :) – Yeo Dec 05 '13 at 05:30
  • Do the new restrooms have to be on the trail, and are the distances along the trail? – user2357112 Dec 05 '13 at 05:39
  • Wait, is this going to be directly applied to the problem of building more bathrooms on a physical trail? The other question seems to have GPS data in it. – user2357112 Dec 05 '13 at 05:40
  • @Yeo Thanks for your nice suggestion. I have just done it. – user24397 Dec 05 '13 at 05:43
  • @user2357112 Could you clalify what is meant by "the distances along the trail"? This will not be directly applied to the GPS data. However, I am hoping this question will help me solve the GPS one. – user24397 Dec 05 '13 at 05:47
  • Are we minimizing the distances assuming people walk along the trail to get to the bathrooms? – user2357112 Dec 05 '13 at 05:49
  • @user2357112 Yes, exactly. – user24397 Dec 05 '13 at 07:10

3 Answers3

1

I think this could be effectively tackled with a relaxation approach.

  1. Take your graph and place two new mobile toilets at random.
  2. Use Dijkstra's algorithm to find the node in the graph that is furthest from any toilet.
  3. Move the closest mobile toilet towards that point, again using Dijkstra to find the shortest path on which to move. The toilet should only be moved some fraction of the total distance to the destination point.
  4. Repeat steps 2 and 3 until the system stabilises and the mobile toilets stop moving.

The fidelity of the solution will be improved by adding further degenerate nodes such that the maximum distance between nodes is below some threshold.

I wouldn't be at all surprised if there were some local-minima problems with some graphs that meant you wouldn't always get the same solution from different random starting placements, but this technique would at least refine an initial guess at a solution.

ryanm
  • 2,979
  • 18
  • 22
0

Randomly place two new mobile toilets along the trail. Use Dijkstra's algorithm to find the farthest node from any toilet. Gradually move the closest toilet towards the identified node using Dijkstra's algorithm for the shortest path. Repeat steps 2 and 3 until the system stabilizes and toilets stop moving.

-1

It might make a fun interactive graphic game if you drag the restrooms around the trail, and light up the most distant point on the trail, and also show some analog measure of the current maximum distance, and also the minimum maximum distance found so far. A more continuous coloring of the trail, indicating distances to the nearest restroom might give cues to aid in finding the minimax.

PaulQ
  • 308
  • 2
  • 9