I am trying to solve ACM problem 295. The problem basically says that there is a set of point obstacles in a corridor which is W units wide and L units long. I need to find the widest
object that can go from left to right avoiding those point obstacles. My initial thinking was to somehow do a depth first search to find all possible paths through the set of obstacles. But cannot formulate the algorithm.
Can anyone give a hint on which direction I should think about?
You can check this UVa 295. You will get the idea.
It seems like a Maximum Flow problem for me.
Related
In an effort to dust off my somewhat rusty programming skills I'm trying to solve this graph traversal problem I ran across.
I want to find a path that visits all coordinates (vertices) on a 10x10 grid. There are some movement restrictions like only being able to move 3 steps in either direction (x+/-3 OR y+/-3) or 2 steps diagonally (x+/-2 AND y+/-2). From what I understand these restrictions don't really matter much since it's still just a graph with vertices and edges and I can model this easily enough in my solution.
I got so far as to being able to solve this problem for a 6x6 grid using a "simple" DFS strategy (at least I think that's what I've produced :). But going bigger than that I run into performance problems since the O(n) of my algorithm is kinda crap. 7x7 takes like 45 mins on my computer so 10x10 is just forget-about-it.
I figured out that a 5x5 grid can always be solved so I guess one viable strat would be to divide the 10x10 into 4x5x5. But that doesn't feel like a proper solution and even tho it would solve grids with sides of multiples of 5 I would still not be able to solve 8x8 and 11x11 etc.
So my question here is about what strategies can be applied to optimize for this particular problem?
Your problem is the Hamiltonian path problem, which is NP-complete for arbitrary graphs. This means there is no known efficient algorithm, so trying to solve this for arbitrary graphs will be fairly fruitless.
Instead, use the fact that you're solving it on a grid. You can simply go row-by-row, turning around at the ends.
If you have a limited set of moves you can do on a grid you can also look at knight's tour literature.
This question was already posted in robotics stackexchange but i did not get any reply.
Moreover, this question is about solving a maze with some constraints, so its not limited to making a particular robot with uC and all.
First let me explain the problem.
This is a maze made only out of black lines on a white surface. The robot has only a few IR sensors which can sense the position of the line. No other sensory input is available.
This is a maze with many self-loops and so a simple LSRB or equivalent algorithm wont work. The robot is supposed to learn the maze and then solve it as optimally as possible .
The above figure represent the possible intersections as all the paths are at 90deg to each other.
As far as my understanding goes, the robot will first scan how many nodes there are, and what their connections to each other is, thus effectively constructing the graph. Next, implement any shortest path algorithm and make your robot follow it.
However, the main problem that i cant get my head around is this:
How will this blind robot know it isnt viewing the same node multiple times if it keeps coming back to the same point after getting caught in a loop?
Also, please suggest good approaches to solving this problems along with any experience anybody has. How does one shot searching methods like DFS , Iterative deepeing DFS , hill climbing work in such scenarios ?
When it meets a crossing, the robot must keep a trace of the lanes it didn't take and backtrack later. In addition, it must be able to model the paths with enough accuracy to check that it is back in a place it has seen before.
Then I am not sure that there is a better strategy than
traverse the lanes until you find the exit;
every time you have a crossing, note the lane that you skip;
when you are back at a known place, return to a skipped lane by the shortest route.
If the map is not known beforehand, you obviously cannot find the optimal path, unless by chance.
If there is no way to estimate the geometry, all you can do is random moves.
Here is the problem: There is a map which size is anywhere from 200*200 pixels to 1000*1000 pixels. Each pixel is a third of an inch in length/width.
The map has walls coming from it (which can be of any size), and can be pre-processed by any means. However, when the problem starts, a robot (of pixel size 18*18) is placed in an unknown location, along with several obstacles and one goal, all of which are in an unknown location.
If the robot bumps into any wall/object/goal it immediately dies. As such it has a simple laser scanner that perfectly sees an 80*80 pixel square ahead of it,centered on the robot.
I have already solved the problem of localizing the robot and determining its position (within a small error) on the grid. I am having a bit of trouble with making a good algorithm for going across the entire map until the goal is found.
I have the idea of making the robot go to the lower right, and somehow sweeping left to right, avoiding obstacles, and walls, until the goal is found, however I am unsure of a good way to do that.
Are there any decent algorithms for such a thing, or are there better ones for what I am trying to do?
You are looking for Pathfinding Algorithms
Some suggestions include "Flood Fill" algorithm or "Dijkstra’s algorithm" very similar to Lee's algorithm (I might even argue they are the same), but it's just another term to search for
This is probably the most popular simple path finding algorithm: "A*search" (a star Search) this link also showcases a few other path finding algorithms. (Another helpful link).
The key with a*star search is that you must know where you are (localization) and where the goal is. Dijkstra type algorithms are able to find the goal without prior knowledge of its location.
The one and only algorithm that comes to my mind is a simple Lee algorithm. Here's a pretty decent tutorial about what it does and how it works.
Using this algorithm you should be able to find all the obstacles and eventually find the goal, also you will find the shortest path to the goal.
The only big difference is that you have to move an 80x80 object instead of a 1x1 object, but I will let you deal with the way you will implement this.
I am looking for an algorithm to solve a "sliding puzzle", the kind of puzzle where you have an image broken into 16 pieces in a 4x4 frame, that you try to reassemble for a scrambled starting position.
This particular puzzle has a restriction, the rows move only to the right (and wrap around), the whole row at once and the columns move only up (and wrap around), the whole column at once, both in one-tile steps.
Is the math too complex?
Anyone has experience with this kind of problem?
This link will provide you the answer. They talk about the different distance functions used by the heuristic. A* is simpler to find open source implementations of.
as for pretty much any problem, one "easy/simple" method to solve such a problem is to represent puzzle states as a graph, and use a graph search / path finding algorithm (DFS,BFS,Dijkstra,A*,etc.). Maybe there is some genius special algorithm that fits this problem better, but you would probably need quite a lot of insight to get better than A* / bidirectional dijkstra.
I have the shape in my 2dArray like this (for example):
It is known that the points A and B (I do not know where) and a path that covers the entire shape (must walk through each cell) must exist. Can you give me some help on how to determine points A and B and then the "cover-all" path? Maybe there are some known algorithms for such case. Or some help with a pseudo-code algorithm. Thanks in advance.
Check nhahdth's link to see that your problem in general is np-hard. this mathoverflow article cites a paper establishing the result for graphs on grids with holes - you won't fare significantly better than using brute force unless you can come up with more constraints.
You may be lucky in identifying at least one of your start and end nodes by searching for vertices of degree 1 in the underlying grid cell graph.