js| algorithm
Foreword (excerpt from the Internet, the code is to come out oneself)
For the general public, "artificial Life", "swarm intelligence", "bionic robot" and so on may be some fresh nouns, they may ask, these new and fashionable technology content in the end is what? Do they represent the direction of future technology development? What impact will they have on people's lives? What will be the future of mankind?
For computer-related professional technicians, perhaps "cellular automata", "Genetic Algorithm", "Neural Network", "Ant Colony Algorithm", "computational intelligence" and other nouns are not unfamiliar, but what is the relationship between these technologies? While technicians struggle endlessly with bugs in computer programs, can they consider making computer programs spontaneously smarter? Can a computer program fix its own mistakes spontaneously?
For the biological professionals, they may be more concerned about the synthesis, cultivation and growth of natural biological DNA. But what exactly is the nature of "activity"? Is life a substance or a message? How can a researcher's theory be validated without expensive, bulky biological experiments?
For social scientists and managers, they may be concerned about how to get people to collaborate spontaneously, and how to make an organization more dynamic. We will see that the ants in nature can work together to move food efficiently and quickly simply by following simple rules. So, can we be like ants? It is possible for everyone to simply make simple decisions based on simple rules that can create unexpected collective effects in the human community?
These problems are, on the face of it, very different, but happily, today they can be found in a new science-the artificial life of computer science and biology. Artificial life was born at the end of 20th century. At first, graduate students engaged in artificial life were mainly computer scientists who were learning from nature, transplanting the flexible adaptations of their biology into computers, and getting the program smarter. "Genetic algorithm", "Neural Network", "Ant colony Algorithm" and so on are the results of computer scientists learning from the biological community. In addition, computers also provide simulations of natural biological systems that allow biologists to perform experiments in a computer that are difficult or impossible to perform in normal circumstances.
However, artificial life is not only concerned with some specific technical problems, it is a new bottom-up scientific thinking method. In fact, there has been an entirely new methodological change in the scientific community: this is an integrated approach instead of a reduction decomposition. We do not fully understand the phenomena of life by mastering the laws of the atomic world. Pure reductionism has come to an end, and with the help of computers people can organize the individual laws that have been decomposed and restored. Not only do we care about the attributes of each cell, but we care about the overall dynamics of these unit combinations. A single unit may be inactive, but the combination of cells may emerge as "active". This is the method of artificial life.
The subject of artificial life is still very young and in many ways immature, and many scholars have their own views on the development of the new subject, even the scope of the subject is not very certain. We refer to artificial life in technology mainly refers to the virtual version of artificial life created in the digital world and in the real world created by the robot version of Artificial life, in methodology, the main emphasis on the bottom-up emerging methods and spontaneous adaptation of evolutionary methods. Therefore, the basic idea of all kinds of artificial life models is to minimize human external intervention and let the system develop and evolve spontaneously.
Artificial life from the beginning is a theory and practice closely combined with the subject, it requires people to use abstract rational thinking of life, on the other hand, special emphasis on computer simulation experiments. In this way, each person's life is as far as possible to write out the core code. Therefore, people who are familiar with computer programming can realize all kinds of lifelike artificial life models directly on their computers from these narratives.
Ant Colony algorithm
has not completed, now put a preliminary results up, we help together under the study, thank you!
At present, the trajectory length (path), Quantity (unit), Velocity (V), Angle (R) and Acceleration (DV,DR) of the ants can be realized randomly.
KR and KV are constants and are intended to be used as a gene for controlling the degree of activity of ants in the future.
But the total number of DIV is limited by machine speed, the number will be very slow, my machine can only run 3,000 ants (of course to reduce to 1), has been set to the exercise delay and the number of ants related, hoping to have a master to help optimize. Thanks again!
Run Code Box
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "><ptml xmlns=" http://www.w3.org/1999/xhtml "><pead><meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/><title> ant colony algorithm js version </title><style>.point{position:absolute;background-color:# 000000;overflow:hidden;width:2px;height:2px;} </style><script type= "Text/javascript" >//============================//system parameter initialization//------------------- The number of---------//life body and the length of unit=10; The path=10;//of life body velocity v0=2;vm=10;//The change range of life body acceleration kr=0.1; Kv=0.1* (vm-v0);//life-body Motion range x0=0;xm=document.documentelement.clientwidth;y0=0;ym= Document.documentelement.clientheight;//============================var r=new Array (); var v=new array (); var dr=new Array (); var dv=new array (); var x=new array (); var y=new array (); var life=new array ();/click Suspend function Document.onclick () { if (window.status!= ' playing ') {window.status= ' playing '; init (0);} Else{window.status=unit}} border with Window resize function Window.onresize () {xm=document.documentelement.clientwidth;ym=document.documentelement.clientheight;} initializer function init (i) {if (window.status== ' playing ' &&i<unit) {if (!life[i]) {obj=life[i]= Document.createelement ("div"); obj.classname= "point"; obj.style.left=x[i]= (X0+XM)/2;obj.style.top=y[i]= (Y0+yM)/2 ;d ocument.body.appendChild (obj); R[i]=math.random (); V[i]=1/math.random ();d r[i]=kr*math.random ();d v[i]=kv* Math.random ();} Move (i); SetTimeout (' Init (' + (i+1) + ') ', I);} Motion function Total=unit*path; Pi=math.pi;function Move (i) {if (window.status== ' playing ') {k=i%unit; X=X[K]; Y=Y[K]; R=R[K]; V=v[k];if (!life[i]) {obj=life[i]=document.createelement ("div"); obj.classname= "point"; obj.style.left=x;o Bj.style.top=y;document.body.appendchild (obj);} Obj=life[i]; r+=dr[k]* (2*math.random ()-1); v+=dv[k]* (2*math.random ()-1); v[k]=v= (V<v0) V0: ((V<VM)? V:VM); X+=math.sin (2*pi*r) *v; Y+=math.cos (2*pi*r) *v;//collision boundary Rebound R= (x<x0| | X>XM)?-r:r; R= (y<y0| | Y>YM)? 0.5-r:r;r[k]=r>1? R-1:r<0? R+1:r; X=x[k]+=math.sin (2*pi*r) *v; Y=y[k]+=math.cos (2*pi*r) *v;/*================================*///overflow boundary regeneration (similar to meteor effect) if (x<x0| | x>xm| | y<y0| | Y>ym) {x=x[k]= (X0+XM)/2; y=y[k]= (Y0+YM)/2;} Else{x[k]=x;y[k]=y;} /*----------------------------------/*================================*/obj.style.left=x;obj.style.top=y;i+= Unit;i= (i<total)? I:i-total;settimeout (' Move (' +i+ ') ', unit);} Automatically load animation switch (Navigator.appName.toLowerCase ()) {case "Netscape": Window.addeventlistener ("load") according to the browser Document.onclick,false break;case "Microsoft Internet Explorer":d efault:window.attachEvent ("onload"), Document.onclick); </script></pead><body scroll= "No" ></body></ptml>
[Ctrl + A ALL SELECT hint: You can modify some of the code, and then run]
Use div do dot always feel is not very worthwhile, which heroes have a better way also please guide Fan Sutra!