r/computerscience • u/theron- • Mar 22 '25
City walking algorithm
NOTE: This is not a homework assignment, rather a business problem we are trying to solve for a maintenance contract in the downtown core of a major city.
Given a square grid/map of the downtown of a modern city, what is the most efficient way to walk the entire surface area of the sidewalks (two on each street, north/south and east/west) with the least amount of overlap and in the least amount of time?
Assumptions:
- a constant speed is assumed
- 4 people are available to do the walking
74
Upvotes
View all comments
Show parent comment
17
u/a_cloud_moving_by Mar 22 '25
I agree OP, this sounds more like your problem than the Traveling Salesman. Quoting wikipedia:
You do want to visit every edge (sidewalk) and you know you'll have to repeat nodes ("the least amount of overlap").
If you treat each intersection as a node, then the sidewalks form a multigraph since there are 2 edges between each node (2 sidewalks on either side of the road). Alternatively, you could think of each corner of an intersection as a node, with sidewalks/crosswalks as edges, in which case it no longer needs to be a multigraph but is more complicated graph. To improve accuracy, you could weight crosswalks vs sidewalks differently, since crossing the street presumably takes more time.
But you stated that it was a "grid" layout. If so, I suspect you could arrive at a pretty optimal solution just by reasoning about it. Off the top of my head I think a zig-zagging diagonally in "diagonal rows" back and forth across the grid seems pretty optimal. However that might cause a lot of street crossing, which might be more time-consuming than solutions that go straight down a road for a long time.