Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
ws1314:cellulaere_automaten [2014/02/13 16:17] Jimmendorf |
ws1314:cellulaere_automaten [2016/05/10 14:46] (aktuell) |
||
---|---|---|---|
Zeile 78: | Zeile 78: | ||
Zielvorstellungen: die richtige Regel, | Zielvorstellungen: die richtige Regel, | ||
- | + | der untenstehende Code ist der Grundbaustein zur Forschungsreihe an unserem "finalen" Automaten. | |
- | _____________________________________________________________________________________ | + | |
- | + | ||
- | Der untenstehende Code ist der Grundbaustein zur Forschungsreihe an unserem "finalen" Automaten. | + | |
Wir haben uns, inspiriert vom Artikel "Emergence of Macro Spatial Structures in Dissipative Cellular Automata" von Andrea Rolli und Franco Zambonelli, dazu entschieden uns mit sogenannten "Dissipativen Zellulären Automaten" zu beschäftigen. | Wir haben uns, inspiriert vom Artikel "Emergence of Macro Spatial Structures in Dissipative Cellular Automata" von Andrea Rolli und Franco Zambonelli, dazu entschieden uns mit sogenannten "Dissipativen Zellulären Automaten" zu beschäftigen. | ||
Diese bieten sich an, da | Diese bieten sich an, da | ||
Zeile 100: | Zeile 97: | ||
| | ||
<code python> | <code python> | ||
- | |||
import numpy as np | import numpy as np | ||
import matplotlib.pyplot as plt | import matplotlib.pyplot as plt | ||
- | + | ||
- | x = 10 | + | x = 50 |
- | y = 10 | + | y = 50 |
+ | |||
def setup(x,y): | def setup(x,y): | ||
Z = np.random.randint(2, size = (x,y)) | Z = np.random.randint(2, size = (x,y)) | ||
return Z | return Z | ||
- | | + | |
+ | |||
def deamon(x,y): | def deamon(x,y): | ||
- | |||
return (np.random.randint(x),np.random.randint(y)) | return (np.random.randint(x),np.random.randint(y)) | ||
+ | |||
+ | def updateB(Z): | ||
+ | i,j = deamon(x,y) | ||
+ | k = (Z[(i-1)%x,(j-1)%y]+Z[(i-1)%x,j]+Z[(i-1)%x,(j+1)%y]\ | ||
+ | +Z[i,(j-1)%y]+Z[i,(j+1)%y]+Z[(i+1)%x,(j-1)%y]+\ | ||
+ | Z[(i+1)%x,j]+Z[(i+1)%x,(j+1)%y])+Z[(i+2)%x,j]+\ | ||
+ | +Z[(i-2)%x,j]+Z[i,(j+2)%y]+Z[i,(j-2)%y] | ||
+ | if Z[i,j] == 1: | ||
+ | if (k < 3 or k > 6): | ||
+ | Z[i,j] = 0 | ||
+ | else: | ||
+ | if k == 6: | ||
+ | Z[i,j] = 1 | ||
+ | return Z | ||
- | def update(Z): | + | def updateA(Z): |
i,j = deamon(x,y) | i,j = deamon(x,y) | ||
- | k = (Z[i-1,j-1]+Z[i-1,j]+Z[i-1,(j+1)%y]\ | + | k = (Z[(i-1)%x,(j-1)%y]+Z[(i-1)%x,j]+Z[(i-1)%x,(j+1)%y]+Z[i,(j-1)%y]+Z[i,(j+1)%y]+Z[(i+1)%x,(j-1)%y]+Z[(i+1)%x,j]+Z[(i+1)%x,(j+1)%y]) |
- | +Z[i,j-1]+Z[i,(j+1)%y]+Z[(i+1)%x,j-1]+\ | + | |
- | Z[(i+1)%x,j]+Z[(i+1)%x,(j+1)%y]) | + | |
if Z[i,j] == 1: | if Z[i,j] == 1: | ||
if (k > 3) or (k < 2): | if (k > 3) or (k < 2): | ||
Zeile 129: | Zeile 136: | ||
return Z | return Z | ||
- | def killall(Z): | ||
- | i,j = deamon(x,y) | ||
- | Z[i,j]= 0 | ||
- | return Z | ||
- | | ||
A = setup(x,y) | A = setup(x,y) | ||
plt.ion() | plt.ion() | ||
- | im=plt.imshow(A,interpolation='nearest') | + | im=plt.imshow(A,interpolation='nearest', cmap = plt.cm.gray_r) |
plt.xticks([]),plt.yticks([]) | plt.xticks([]),plt.yticks([]) | ||
- | for s in xrange(100): | + | for s in range(10000000): |
- | A = killall(A) | + | A = updateB(A) |
- | im.set_data(A) | + | if s%100 == 0: |
- | plt.draw() | + | im.set_data(A) |
+ | plt.draw() | ||
plt.ioff() | plt.ioff() | ||
plt.show() | plt.show() | ||
+ | |||
+ | |||
+ | #für josh!: | ||
+ | #codezeilen die du wolltest | ||
+ | #viel spaß | ||
+ | import numpy as np | ||
+ | import matplotlib.pyplot as plt | ||
+ | |||
+ | x = 100 | ||
+ | y = 100 | ||
+ | |||
+ | def setup(x,y): | ||
+ | #'''Erstellung der Welt mit Zuflliger An/Aus Verteilung ''' | ||
+ | Z = np.random.randint(2, size = (x,y)) | ||
+ | return Z | ||
+ | |||
+ | |||
+ | def deamon(x,y): | ||
+ | #'''Whlt zufllige Zelle fr asynchrones Update aus ''' | ||
+ | return (np.random.randint(x),np.random.randint(y)) | ||
+ | |||
+ | def intrinsic(Z, rule, mode): | ||
+ | i,j = deamon(x,y) | ||
+ | if mode == '2-radial': | ||
+ | k = (Z[(i-1)%x,(j-1)%y]+Z[(i-1)%x,j]+Z[(i-1)%x,(j+1)%y]\ | ||
+ | +Z[i,(j-1)%y]+Z[i,(j+1)%y]+Z[(i+1)%x,(j-1)%y]+\ | ||
+ | Z[(i+1)%x,j]+Z[(i+1)%x,(j+1)%y])+Z[(i+2)%x,j]+\ | ||
+ | +Z[(i-2)%x,j]+Z[i,(j+2)%y]+Z[i,(j-2)%y] | ||
+ | if mode == 'Moore': | ||
+ | k =(Z[(i-1)%x,(j-1)%y]+Z[(i-1)%x,j]+Z[(i-1)%x,(j+1)%y]\ | ||
+ | +Z[i,(j-1)%y]+Z[i,(j+1)%y]+Z[(i+1)%x,(j-1)%y]+\ | ||
+ | Z[(i+1)%x,j]+Z[(i+1)%x,(j+1)%y]) | ||
+ | if rule=='Diagonal': | ||
+ | if Z[i,j] == 1: | ||
+ | if (k < 3 or k > 6): | ||
+ | Z[i,j] = 0 | ||
+ | else: | ||
+ | if k == 6: | ||
+ | Z[i,j] = 1 | ||
+ | if rule=='Life': | ||
+ | if Z[i,j] == 1: | ||
+ | if (k > 3) or (k < 2): | ||
+ | Z[i,j] = 0 | ||
+ | else: | ||
+ | if k == 3: | ||
+ | Z[i,j] = 1 | ||
+ | if rule == 'Striche': | ||
+ | if Z[i,j] ==1: | ||
+ | if k > 2: | ||
+ | Z[i,j] = 0 | ||
+ | else: | ||
+ | if k == 2: | ||
+ | Z[i,j] = 1 | ||
+ | return Z | ||
+ | |||
+ | |||
+ | def environment(Z): | ||
+ | i,j = deamon(x,y) | ||
+ | Z[i,j] = 1 | ||
+ | return Z | ||
+ | |||
+ | |||
+ | A = setup(x,y) | ||
+ | stoer = (True, 21) | ||
+ | plt.ion() | ||
+ | |||
+ | im=plt.imshow(A,interpolation='nearest', cmap = plt.cm.gray_r) | ||
+ | plt.xticks([]),plt.yticks([]) | ||
+ | |||
+ | for s in range(10000000): | ||
+ | A = intrinsic(A, 'Diagonal', '2-radial') | ||
+ | if stoer[0] == True: | ||
+ | if s%stoer[1] == 0: | ||
+ | A = environment(A) | ||
+ | if s%100 == 0: | ||
+ | im.set_data(A) | ||
+ | plt.draw() | ||
+ | |||
+ | plt.ioff() | ||
+ | plt.show() | ||
+ | |||
</code> | </code> |