r/pythonhelp • • 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 4
1 2 2 0 0 2 2 1
1 2 2 0 0 2 2 1
0 2 2 0 1 2 2 0
0 2 2 0 1 2 2 0
0 1 1 0 0 1 1 0
0 2 2 0 0 2 2 0
0 2 2 0 0 2 2 0
1 2 2 0 1 2 2 0
1 2 2 0 1 2 2 0
3 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 comment sorted by

1

u/xelf Nov 05 '19 edited Nov 05 '19

Try this problem, and look at the discussion page if you get stuck:

Should have some relation to what you're trying to do.

This might be more helpful:

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:

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.