The realization of most classification algorithms for cellular automata

Source: Internet
Author: User
Tags rand

Cellular automata (Cellular automaton)

Cellular automata automata is a grid of cells, each of which chooses to open or close according to the state of the neighborhood. All cells follow the same rules, also known as Cellular update rules, which determine the next state of the cell based on the current state of each cell neighborhood. Like the complex systems of nature, cellular automata are made up of a large number of simple individuals (cells) that do not have central control, and each individual interacts with only a small number of other individuals. Also, cellular automata can exhibit very complex behavior, and their behavior is difficult or impossible to predict by their updating rules. There are many kinds of cellular automata, the famous "Life game" is also one of cellular automata.

Elementary cellular automata (elementary cellular automaton)

The elementary cellular automata is one-dimensional two-state cellular automata, each cell is connected with only two neighboring cells. The space-time diagram of cellular automata shows the changes of cellular automata ' stereoscopic configuration over time, and the topmost row is the initial state setting of one-dimensional cellular automata, followed by the updated state of each step.

Cellular automata for "Most classification (Majority classification)" Tasks

The cellular auto-confidential can distinguish between the open state and the state in the initial state. If the number of open states is the majority, then all the cells should become open. Similarly, if the state is the majority, then all the cells should be turned off. Most classification tasks are somewhat similar to elections in that everyone knows only the nearest neighbor's political view to predict two candidates who will win.

We use a one-dimensional cellular automaton, each of which is connected to an adjacent 6 cells, so that there are 7 cells (including themselves) in the neighborhood of the cell. A reasonable idea is that "the cell should become the current majority in the neighborhood." "It's like predicting which candidate will be elected based on your own and your neighbors ' majority opinion." However, this "partial majority vote" cellular automaton does not complete the task.

We are using the rules given by Melanie Michel (Melanie Mitchell) on page No. 203 of the complex (Complexity:a Guided tour):

0000010100000110000101011000011100000111000001000001010101010111011001000111011100000101000000010111110111111111101101110 1111111

The 1th bit is the update state of the cell in the neighborhood of 0 o'clock, and the 2nd is the update state of the intermediate cell when the neighborhood is 0000001, and then the next. Because the neighborhood state has 27 = 128 possible, the rule has 128 bits. But looking at these digits does not see how the rule works, nor does it know why it is highly adaptable when it comes to most classifications.

C # program to implement this algorithm

Here is the corresponding C # source program MainForm.cs:

1 usingSystem;2 usingSystem.Drawing;3 usingSystem.Windows.Forms;4 5 namespaceSkyiv.CellularAutomaton.MajorityClassification6 {7   Sealed classMainform:form8   {9     Static ReadOnly intSizecellular =3;Ten     Static ReadOnly intNcellular =201; One     Static ReadOnly intLines =Ncellular; A     Static ReadOnlyPen pen =NewPen (Color.Black, sizecellular); -     Static ReadOnly stringStrruler = -       "0000010100000110000101011000011100000111000001000001010101"+ the       "0101110110010001110111000001010000000101111101111111111011"+ -       "011101111111"; -     Static ReadOnly BOOL[] Ruler =New BOOL[strruler.length]; -  + Graphics GC; -  + mainform () A     { atText ="Majority Classification"; -BackColor =Color.White; -ClientSize =NewSize (Ncellular * sizecellular +1, lines * sizecellular +1+ +); -        for(vari =0; I < ruler. Length; i++) Ruler[i] = strruler[i] = ='1'; -     } -  in     protected Override voidOnPaint (PaintEventArgs e) -     { toGC =E.graphics; +DrawGrid (true); -       varCellulars =getinitcellulars (); theDrawcellulars (Cellulars,0); * DisplayMessage (cellulars); $        for(vari =1; i < lines; i++)Panax Notoginseng       { - StepIt (cellulars); the Drawcellulars (Cellulars, i); +       } A       Base. OnPaint (e); the     } +  -     voidStepIt (BOOL[] cellulars) $     { $       varBUF =New BOOL[Cellulars. Length]; -        for(vari =0; i < ncellular; i++) -Buf[i] =Ruler[getvalue (Cellulars, i)]; the array.copy (buf, Cellulars, Cellulars. Length); -     }Wuyi  the     intGetValue (BOOL[] Cellulars,intidx) -     { Wu       varn =0; -IDX = (idx +3) %Ncellular; About        for(vari =0; I <7; i++) $         if(cellulars[(idx-i + ncellular)%Ncellular]) -n + =1<<i; -       returnN; -     } A  +     voidDrawcellulars (BOOL[] Cellulars,intLine ) the     { -        for(vari =0; I < Cellulars. Length; i++) $         if(Cellulars [i]) the Set (i, line); the     } the  the     voidDisplayMessage (BOOL[] cellulars) -     { in       varblacks =0; the       foreach(varCellularinchcellulars) the         if(Cellular) Aboutblacks++; theOut ("black:{0} white:{1}", blacks, Cellulars. Length-blacks); the     } the  +     voidOut (stringFmtparams Object[] args) -     { theGc. DrawString (string. Format (FMT, args),NewFont ("Courier New",Ten),BayiBrushes.blue,NewPoint (5, lines * sizecellular +9)); the     } the  -     BOOL[] getinitcellulars () -     { the       varRand =NewRandom (); the       varCellulars =New BOOL[ncellular]; the        for(vari =0; I < Cellulars. Length; i++) theCellulars [i] = rand. Next ()%2==0; -       returnCellulars; the     } the  the     voidDrawGrid (BOOLOnlyborder)94     { the       varPen =NewPen (Color.Red,1); the       varLen = Ncellular *Sizecellular; the        for(vari = Onlyborder? Lines:0; I <= lines; i++)98       { About         varK = i *Sizecellular; -Gc. DrawLine (pen,0, K, Len, K);101       }102Len = lines *Sizecellular;103        for(vari = Onlyborder? Ncellular:0; I <= ncellular; i++)104       { the         varK = i *Sizecellular;106Gc. DrawLine (pen, K,0, K, Len);107       }108     }109  the     voidSet (intXinty)111     { the       vary2 = y * sizecellular + sizecellular/2;113Gc. DrawLine (pen, x * sizecellular, Y2, (x +1) *sizecellular, y2); the     } the  the     Static voidMain ()117     {118Application.Run (Newmainform ());119     } -   }121}
Brief analysis
    1. The static read-only variable sizecellular on line 9th represents the edge length of each cell square and must be an odd number.
    2. The static read-only variable ncellular on line 10th indicates how many cells each row has, preferably an odd number, to avoid a tie when most classifications are in progress.
    3. The static read-only variable lines of line 11th indicates how many times to iterate.
    4. The static read-only variable in line 13th strruler the rule for the iteration.
    5. The main work is done in the OnPaint method from line 29th to line 42.
    6. The Getinitcellulars method of line 84th through 91st initializes the initial state of the cell randomly.
    7. Lines 36th through 40th iterate according to the specified rules.
    8. The StepIt method of line 44th through 50th performs a specific iterative step.
    9. The GetValue method of line 52nd through 60th calculates the value of the cell neighborhood.
Run results

Several typical operating results of the program are as follows:

Shows white-dominated and the results are correct. This is a common situation.

Shows black-dominated and the results are correct. This is also a common situation.

Shows white-dominated, resulting in an error. This is a relatively rare situation.

Show black dominant, result error. The result is that the final iteration results are not all black, but mixed with a small amount of white cells. This program only iterates 200 steps, in fact, as long as the iteration of a few steps to get the correct results. This is a very rare situation.

Resources
    1. Wikipedia:majority problem (cellular automaton)
    2. Wikipedia:cellular Automaton
    3. Wikipedia:elementary Cellular automaton
    4. "Complex", Melanie Michel, Tang Lu, Hunan Science and Technology Press, June 2011, 1th Edition

The realization of most classification algorithms for cellular automata

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.