r/pythonhelp • u/altabb • Nov 04 '19
Traveling salesman D2 matrix
Hello,
I have a 2D matrix (map) with constraints :- 0 are free boxes ;- 1 are boxes to go through ;- 2 are blocked boxes ;- 3 is the start, 4 is the exit ;
0 0 0 0 0 0 0 41 2 2 0 0 2 2 11 2 2 0 0 2 2 10 2 2 0 1 2 2 00 2 2 0 1 2 2 00 1 1 0 0 1 1 00 2 2 0 0 2 2 00 2 2 0 0 2 2 01 2 2 0 1 2 2 01 2 2 0 1 2 2 03 0 0 0 0 0 0 0
I need to draw a path walking on all marked boxes (it doesn’t matter if the path is not really optimized), it is possible to walk on a box already traveled.
I would like to find a resource (stack overflow, tutorial, etc.) talking about a similar problem to get an idea of where to start.
Thanks,
2
Upvotes
1
u/xelf Nov 05 '19 edited Nov 05 '19
Try this problem, and look at the discussion page if you get stuck:
https://www.hackerrank.com/challenges/botclean/problem
Should have some relation to what you're trying to do.
This might be more helpful:
The Traveling Salesman Problem on Grids with Forbidden Neighborhoods (pdf file)
I haven't really thought about a solution, but you might find disjoint sets to be useful, try looking at this problem "Friend Circle Queries" and the discussion for it here:
https://www.hackerrank.com/challenges/friend-circle-queries/problem
In short for squares a,b,c,d if a can reach b, and c can reach d, if you find that b can reach c, then you have a connection from a to d. Which should be useful for you.
Hope some of the above helps. Good luck.