Algorithm Explanation:
As the program began to run, the ants began to move out of their nests, looking for food, and they crawled through the screen until they found food and returned to their nests.
Among them, the ' F ' point means food, ' H ' means the nest, the white block represents the obstacle, ' + ' is the ant.
Expected results: The ants began to look for food without first telling them where the food was. When a food is found, it releases a pheromone to the environment, attracting other ants to come, so more and more ants will find food! Some ants do not repeat the same path as the other ants do, and if the road to open is shorter than the other roads, gradually more ants are drawn to the shorter path. Finally, after a period of time running, there may be a shortest path to be repeated by most ants.
Principle: Why can small ants find food? Do they have intelligence? Imagine how complicated the program would be if we were to design an artificial intelligence program for ants. First of all, if you want ants to be able to avoid obstacles, they must be based on the appropriate terrain to give it instructions so that they can skillfully avoid obstacles, and secondly, to let ants find food, they need to let them traverse all points in space; again, if you want the ant to find the shortest path, Then you need to calculate all the possible paths and compare their size, and more importantly, you need to be careful about programming, because the bugs in your program may be undone. What an incredible program this is! Too complicated, I'm afraid no one will be able to complete such a cumbersome redundancy program.
However, the fact is not as complex as you think, above this program each ant's core program code but more than 100 lines! Why would a simple program make an ant do such a complicated thing? The answer is: the emergence of simple rules. In fact, each ant is not the kind of information we need to know about the whole world, they are concerned with only a small range of immediate information, and based on these local information using a few simple rules to make decisions, so that in the colony of the collective, the complexity of the behavior will be highlighted. This is the law of artificial life, the scientific interpretation of complexity! So, what are these simple rules? The following detailed description:
1, Scope: The range of ants observed is a square world, the ant has a parameter for the velocity radius (generally 3), then it can observe the range is 3*3 a square world, and can move distance also within this range.
2, the environment: ants in the environment is a virtual world, where there are obstacles, and other ants, as well as pheromone, information is known as two kinds, one is to find food ants sprinkle food pheromone, one is to find the nest of ants sprinkle the nest of pheromone. Every ant can only perceive the environmental information within it. The environment at a certain rate let the pheromone disappear.
3, foraging rules: in each ant can perceive the range of whether there is food, if there is a direct past. Otherwise see if there is pheromone, and compare in the range of perception which point of pheromone most, so that it will go to the location of more pheromone, and each ant will make mistakes in small probability, so not to the point of the most pheromone move. Ants find their nests in the same rules as above, except that it reacts to the pheromone of the nest and does not respond to food pheromone.
4, move the rule: each ant is moving toward the most pheromone direction, and when there is no pheromone guide around, the ants will be in accordance with the direction of their original movement of inertia, and, in the direction of movement there is a random small disturbance. In order to prevent ants from circling, it will remember what has recently passed, and if you find that the next point to go has recently passed, it will try to avoid.
5, obstacle avoidance rules: if the ant to move in the direction of obstruction, it will randomly choose another direction, and have pheromone guidelines, it will follow the rules of foraging behavior.
7, seeding pheromone rules: each ant in just find food or nest when the most pheromone, and as it goes far away, sowing less pheromone.
According to these rules, there is no direct relationship between ants, but each ant interacts with the environment, and through the pheromone link, the ants are actually connected. For example, when an ant finds food, it does not directly tell other ants there is food, but to the environment to disseminate pheromone, when the other ants pass near it, you will feel the presence of pheromone, and then according to the guidance of pheromone found food.
Question: How do ants find food when they say so much?
In the absence of ants to find food, the environment does not have useful pheromone, then why the ants are relatively effective to find food? This is thanks to the movement rules of ants, especially when there is no pheromone. First of all, it wants to be able to keep some kind of inertia, this allows the ants to move forward as far as possible (beginning, this is a random fixed direction), rather than in situ meaningless spin or vibration, and secondly, the ants have a certain randomness, although there is a fixed direction, but it can not be like the particles of the straight movement down, But there is a random disturbance. This allows the ants to exercise a certain purpose, try to keep the original direction, but there are new temptations, especially when encountering obstacles, it will immediately change direction, this can be seen as a choice of process, that is, the environment of obstacles to the ants in a certain direction, while the other direction is not correct. This explains why individual ants can still find well concealed food in complex maps such as mazes.
Of course, when an ant finds food, other ants will quickly find food along the pheromone.
How do ants find the shortest path? This is attributed to the pheromone, in addition to the environment, specifically the computer clock. Where the pheromone is more obvious, there will be more ants, so more ants will come together. Suppose there are two roads from the nest to the food, and at the beginning, the number of ants walking the two roads is as much (or more ants on the road, which is irrelevant). When the ants come to the end of a road, they will return immediately, so that the short way the ants go back and forth for a short time, this also means that the frequency of repetition is fast, so the number of ants traversed in the unit time, sprinkle the pheromone nature will be more naturally, there will be more ants are attracted to, and thus sprinkle more pheromone ... And the long road is the opposite, therefore, more and more ants gather to the shorter path, the shortest path is approximately found. Some people may ask the local shortest path and the global most short circuit problem, in fact, the ants are approaching the global most short-circuit, why? This stems from the ants will make mistakes, that is, it will be in a certain probability does not go to the place of high pheromone, which can be understood as a kind of innovation, if this innovation can shorten the road, then according to the principle of just described, more ants will be attracted to come.
After the trail of ants, what did you find? Through the above principles and practices, it is not difficult to find that ants have intelligent behavior, thanks to its simple rules of conduct, and these rules combined with the following two features:
1, Diversity 2, positive feedback diversity ensures that ants do not enter a dead end when foraging and infinite cycle, positive feedback mechanism to ensure that relatively good information can be preserved. We can think of diversity as a creative ability, and positive feedback is a learning enhancement ability. The power of positive feedback can also be likened to authoritative opinion, and diversity is the creativity that breaks down the authority, and it is the ingenious combination of two that makes intelligent behavior emerge. [Page] by extension, the evolution of nature, social progress, human innovation is actually inseparable from these two things, diversity to ensure the system's innovative ability, positive feedback to ensure that the good features can be enhanced, the two should be just right combination. If the multiplicity is excessive, that is, the system is too active, this is equivalent to the ants will be too much random movement, it will fall into chaos State, and on the contrary, diversity is not enough, positive feedback mechanism is too strong, then the system is like backwater. This is in the ant colony in terms of performance, ant behavior is too stiff, when the environment changes, ant colony still can't adjust properly.
Since complexity and intelligent behavior are based on the underlying rules, and since the underlying rules have diversity and positive feedback characteristics, then perhaps you will ask where these rules come from? Where does diversity and positive feedback come from? My own opinion: The rule comes from the evolution of nature. And the evolution of nature is also embodied in the ingenious combination of diversity and positive feedback, according to what has just been said. And what is the ingenious combination of this? Why is the world so lifelike in your eyes? The answer is that the environment has created all this, the reason you see lifelike world, because those who can not adapt to the diversity of the environment and positive feedback of the combination are dead, be eliminated by the environment!
Parameter description: The largest pheromone: ants in the beginning of the total amount of pheromone, the larger the program in a longer period of time can exist pheromone. Pheromone-cutting speed: As time goes by, the pheromone that already exists in the world will be reduced, and the larger the number, the quicker the reduction.
The error probability indicates that the ant is not going to the largest area of pheromone, the greater the probability that the ant is more innovative.
The velocity radius represents the maximum length that an ant can walk at a time, and also indicates the extent of the ant's perception.
Memory means that the ants can remember how many of the coordinates just come through, which avoids the ants in the local circles, stagnant. The larger the value, the faster the whole system runs, the smaller the ants are, the easier it is to go in circles.