I am trying to find a good A* heuristic function for the problem "alien tiles", found at www.alientiles.com for a uni project.
In alien tiles you have a board with NxN tiles, all colored red. By clicking on a tile, all tiles in the same row and column advance by a color, the color order being red->green->blue->purple, resetting to red after purple. The goal is to change all tiles to the specified colors. The simplest goal state is all the tiles going from red to green, blue or purple. The board doesn't have to be 7x7 as the site suggests.
I've thought of summing the difference between each tile and the target tile and dividing by 2N-1 for an NxM board or or finding possible patterns of clicks as the minimum number of clicks, but neither has been working well. I can't think of a way to apply relaxation to the problem or divide it into sub-problems either, since a single click affects an entire row and column.
Of course I'm not asking for anyone to find a solution for me, but some tips or some relevant, simpler problems that I can look at (rubik's cube is such an example that I'm looking at).
Thanks in advance.
The problem you are trying to solve is similar to NIM FOCUS name. Please have a look at it. The solutions for it can be found in Stuart J. Russell book under heuristics section. Hope this helps
Although it is a relatively 'dumb' way of thinking around the problem, one heuristic mechanism i have found that drastically cuts down on the number of states that a star expands, tries to figure out a relationship between the cell that has been clicked most recently and the number of states that clicking on it again would expand. Its like telling a star: "If you have clicked on a cell in your last move, try clicking on another one this time." Obviously in special scenarios,
(e.g. having all the board on your target colour, say green, and only a purple cross where clicking on the center of the cross twice changes the cross colour to green and then you are done)
this way of thinking is actually detrimental. But, it is a place to start.
Please let me know if u figure anything out, as it is something i am working on as well.
Related
I'm solving a task from an old programming competition. The task is to make a program that can find if there exists a possible solution, and what the shortest solution is, for a version of the well known game "lights out". In short, we have several lights connected. By clicking on of the lights you change the status of it, and the two adjacent lights. The goal is to activate all the lights.
In the classic version of "lights out" we are working with two dimensions, but in this version the lights are connected in a "one dimensional" string, where the "edges" are connected. Basically a circle of lights.
The number of lights can go up to 10000, so the bruteforce method I tried was obviously not good enough. It only manages to solve the versions that have a solution, and where there are under ~10 lights. Here is an example of a solveable setup. The 1's mark lights that are activated, and the 0's mark lights that are deactivated. The first line includes the number of lights in the string. If a solution doesn't excist, the program will output that it isn't possible. Remember that the edges are connected.
5
10101
Click one of the "edges" (doesn't matter which one, I clicked the left one).
01100
Click the opposite edge
11111
If a solution doesn't excist the program outputs a message. If not, it outputs the shortest solution, in this case: 2.
Could anyone help me find an algorithm?
Thanks for the help.
Suppose you knew whether in the solution (if one exists) you need to click on the first and second light.
Once we have this information, we can immediately deduce whether we need to click on the third light as this is the last choice that can affect the second light (clicking on the first light changes the last/first/second, clicking on the second light changes the first/second/third, clicking on the third light changes the second/third/fourth - but no other clicks can change the second light).
Similarly, we can then immediately deduce whether to click the fourth light, as this is the last choice that can affect the third light.
You can then work all the way round to the end to find out whether you have a consistent solution (with all lights out).
Simply try all 4 options for the first 2 switches, and pick the best scoring one.
Complexity O(4n)
I have a pool of balls of 30 different color patterns(solid green, green and red striped, etc), and I also have 6 boxes ordered from 1 to 6. Now randomly I select 6 balls out of the pool and put each ball in one box so that each box contains exactly one ball. And among the 6 balls, the color pattern of each ball can be different from or the same as color pattern of other balls in other boxes. Now I want you to guess the color pattern of the ball in each box by doing the following:
Every time you make a request to me and I will randomly select 3 balls and display the balls in front of you in the same order of the box order. You can make unlimited requests.
The problem is how to tell the color pattern of the ball in each box by making least requests, I feel like there should be a well-known algorithm for this problem, but I can not find any. Has anybody seen this before?
I think there is a lot of statistics in this. First of all, I would make the simplifying assumption that (if you don't know which colour balls are present) the only colours and patterns available are those which you have seen.
Now write down, or work out how to calculate, a formula that gives you the probability of the observed data given the listing of which balls are present in which boxes.
Now all you have to do is find the combination of balls in boxes that gives the highest probability to the observed data, and hope that as you get more and more data the right answer wins out.
You could think of this as a generic optimisation problem, and try hill-climbing from multiple random starts, or genetic programming, or whatever your favourite heuristic is.
Or you could do a bit more web-searching about statistics and recognise that this is a missing data problem, where the hidden data is the knowledge of which box each sampled ball came from. Statisticians often solve hidden data problems with the EM algorithm. There is an introduction for mathematicians at http://www.inf.ed.ac.uk/teaching/courses/pmr/docs/EM.pdf. Your problem can be thought of as a simple case of a hidden Markov model, with the hidden state being the box which produced a particular ball.
I have a "complex" problem where I have a bunch of tooltips (orange) on top of elements (black) that can be randomly placed on screen. The tooltips are a big square with a triangle in the middle of one of it's 4 sides pointing though the element direction. By default, the triangle will be in the middle of the element, but can be moved as long as it stay close to it, so we can't easily understand it refer to this element and not another one.
The problem is, the tooltip must NOT overlap each other, and can't be out of screen.
Image of my tooltip problem
I thought about first placing every tooltips to their default position (triangle pointing down), and then check if they are out of screen or overlap another one, and if so, try another position. But using this technique (which is probably the simplest one), I do not guarantee the best placement since once a tooltip has been placed, I will not replace him if another one can't fit anywhere otherwise it become too complex.
Does someone have any tips/idea how to deal with this type of problem?
Thanks!!
This looks like an instance of the map labelling problem. Wikipedia has an article about it.
You could place all the tooltips using some sort of physical simulation of repulsive electrical charges, similar to what is done in some algorithms for drawing graphs. You could model each tooltip as an object attached with a soft spring to its black box, while simulating a strong repulsive force between all the tooltips and between a tooltip and the edge of the image. You calculate all the forces and move the tooltips iteratively, until all positions converge. You could play with making the force scale as inverse square, inverse cube, etc to find nice results.
This might be a bit of work to implement, but should probably give decent results for simple cases. It is probably impossible to guarantee that a good solution always exists, since if you add too many tooltips, your image will be full.
When Selecting the Album View in iTunes and clicking on a cover art, iTunes expands a colored band, that matches the cover art. Interestingly, font colors and highlight colors are also chosen to create a good match to the cover. I am working on an algorithm that does the same, but did not come up with a good solution to automatically find dominant colors in an image. My best solution is to take the respective median values of r, g and b. Any better ideas?
There was an excellent blog post recently about finding dominant colors in images by using k-means clustering. I'm not sure how well it will apply to your situation, but it might be a great starting point.
Hope this helps!
I solved this question Maximize the rectangular area under Histogram today.
This left me thinking, are there any real life application to this algorithm ?
If you wanted to attach a label or some text to a histogram inside the bars, one good place to put it is the center of the maximum rectangle.
And even if this particular problem isn't very interesting at first glance, there are a ton of data visualization problems that are related. And the techniques used to solve this problem can be applied elsewhere.