dev:program_ulam
                Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| dev:program_ulam [2015/05/27 17:47] – [Run] xychen | dev:program_ulam [2016/01/14 07:13] (current) – ackley | ||
|---|---|---|---|
| Line 18: | Line 18: | ||
| Similarly, the first letter of every variable name, and of the name of every function or method (both terms mean the same thing in ULAM), must be a **lowercase** letter. | Similarly, the first letter of every variable name, and of the name of every function or method (both terms mean the same thing in ULAM), must be a **lowercase** letter. | ||
| + | |||
| + | ==== EventWindow Indices ==== | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | The '' | ||
| + | |||
| + | In general, when code is referring to individual fixed sites within the event window, the 1D coordinate system is used (see the ' | ||
| Line 28: | Line 36: | ||
| EventWindow ew; | EventWindow ew; | ||
| Void behave(){ | Void behave(){ | ||
| - | ew[1]=ew[0]; | + | ew[1]=ew[0]; | 
| } | } | ||
| } | } | ||
| Line 44: | Line 52: | ||
| / | / | ||
| </ | </ | ||
| - | Running ulam with the '' | + | Running ulam with the '' | 
| - | + | ==== Run ==== | |
| - | {{: | + | |
| We also must specify where the simulator '' | We also must specify where the simulator '' | ||
| < | < | ||
| Line 59: | Line 66: | ||
| Two other useful panels are '' | Two other useful panels are '' | ||
| - | === draw First === | + | === experiment the First element | 
| - | To place a '' | + | To place a '' | 
| - | {{:dev:mfms_first_0001kps.png? | + | |
| + | {{:dev:mfms_first_0000kps.png? | ||
| + | |||
| + | From the left to the right, these pictures shows a sequence of how '' | ||
| ===== The ' | ===== The ' | ||
| Line 76: | Line 87: | ||
| */ | */ | ||
| element Second{ | element Second{ | ||
| + | EventWindow ep; | ||
| Void behave(){ | Void behave(){ | ||
| - | EventWindow ep; | ||
| ep[1]=ep[0]; | ep[1]=ep[0]; | ||
| } | } | ||
| Line 87: | Line 97: | ||
| But that's not all: We can specify // | But that's not all: We can specify // | ||
| - | **TODO** Screenshots | + | {{: | 
| + | |||
| + | '' | ||
| + | |||
| ===== The ' | ===== The ' | ||
| We already know duplicate. Then we can swap. | We already know duplicate. Then we can swap. | ||
| - | < | + | < | 
| /** | /** | ||
| Third is a demo element. | Third is a demo element. | ||
| Line 99: | Line 112: | ||
| */ | */ | ||
| element Third{ | element Third{ | ||
| + | EventWindow ep; | ||
| Void behave(){ | Void behave(){ | ||
| - | EventWindow ep; | ||
| ep.swap(0, | ep.swap(0, | ||
| } | } | ||
| Line 108: | Line 121: | ||
| ===== The ' | ===== The ' | ||
| - | This element | + | This element | 
| - | < | + | < | 
| /** | /** | ||
| - |  | + |  | 
| \color #606 | \color #606 | ||
| - | \symbol | + | \symbol | 
| \symmetries 0 | \symmetries 0 | ||
| */ | */ | ||
| - | element | + | element | 
| Bool xFlip; | Bool xFlip; | ||
| + | EventWindow ew; | ||
| Void behave(){ | Void behave(){ | ||
| - | EventWindow ew; | ||
| if (xFlip==false){ | if (xFlip==false){ | ||
| xFlip=true; | xFlip=true; | ||
| Line 135: | Line 148: | ||
| ===== The ' | ===== The ' | ||
| This element Box will move in a loop of north, east, south, west. It seems like moving inside a box. | This element Box will move in a loop of north, east, south, west. It seems like moving inside a box. | ||
| - | < | + | < | 
| /** | /** | ||
| Box is a demo element. | Box is a demo element. | ||
| Line 167: | Line 180: | ||
| </ | </ | ||
| The '' | The '' | ||
| + | |||
| + | ===== Interaction between three Elements ===== | ||
| + | We have tried several elements above. Here we implemented a game involves three elements: '' | ||
| + | <code - Provider.ulam> | ||
| + | /** | ||
| + | Provider is a demo element. | ||
| + | \color #fba | ||
| + | \symbol Pv | ||
| + | \symmetries normal | ||
| + | */ | ||
| + | element Provider{ | ||
| + | DebugUtils du; | ||
| + | EventWindow ew; | ||
| + | AtomUtils au; | ||
| + | Random rm; | ||
| + | |||
| + | Void behave(){ | ||
| + | WindowServices ws; | ||
| + | ws.reset(1, | ||
| + | Empty e; | ||
| + | Signal s; | ||
| + | Int et=au.getType((Atom) e); | ||
| + | if(ws.scan(et)){ //check if there is empty slot to produce Signal atoms | ||
| + | if(rm.oneIn(3)){ | ||
| + | ew[ws.getPick(0)]=s;// | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | <code - Signal.ulam> | ||
| + | /** | ||
| + | Signal is a demo element. | ||
| + | \color #ac3 | ||
| + | \symbol Sg | ||
| + | \symmetries all | ||
| + | */ | ||
| + | element Signal{ | ||
| + | DebugUtils du; | ||
| + | EventWindow ew; | ||
| + | AtomUtils au; | ||
| + | Random rm; | ||
| + | Unsigned(6) density; | ||
| + | Void diffuse(){ | ||
| + | if(ew[1] is Empty){ | ||
| + | ew.swap(0, | ||
| + | } | ||
| + | } | ||
| + | Bool chkDense(){ | ||
| + | WindowServices ws; | ||
| + | ws.reset(0, | ||
| + | Signal s; | ||
| + | Int st=au.getType((Atom) s); | ||
| + | if(ws.scan(st)){ | ||
| + | density=ws.getHits(0); | ||
| + | if(density< | ||
| + | return false; | ||
| + | } | ||
| + | } | ||
| + | return true; | ||
| + | } | ||
| + | Void catchRequest(){ | ||
| + | WindowServices ws; | ||
| + | Random rdm; | ||
| + | ws.reset(1, | ||
| + | Request r; | ||
| + | Int rt=au.getType((Atom) r); | ||
| + | for(Int slot=ws.next(); | ||
| + | Atom a= ew[slot]; | ||
| + | if(a is Request){ | ||
| + | Request you=(Request) a; | ||
| + | if(density> | ||
| + | if(rdm.oneIn(2)){ | ||
| + | ew.swap(0, | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | Void behave(){ | ||
| + | Bool isAlive=true; | ||
| + | if(chkDense()){// | ||
| + | diffuse(); | ||
| + | } | ||
| + | else{ // if I am alone, I have some chance to disappear. | ||
| + | if(rm.oneIn(density*5-4)){ | ||
| + | Empty e; | ||
| + | ew[0]=e; | ||
| + | isAlive=false; | ||
| + | } | ||
| + | } | ||
| + | if(isAlive){ | ||
| + | catchRequest(); | ||
| + | // less Signal than me. | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | <code - Request.ulam> | ||
| + | /** | ||
| + | Request is a demo element. | ||
| + | \color #740 | ||
| + | \symbol Rq | ||
| + | \symmetries all | ||
| + | */ | ||
| + | element Request{ | ||
| + | DebugUtils du; | ||
| + | EventWindow ew; | ||
| + | AtomUtils au; | ||
| + | Random rm; | ||
| + | Unsigned(5) density; | ||
| + | Unsigned(5) pvdrcnt; | ||
| + | Void diffuse(){ | ||
| + | if(ew[1] is Empty){ | ||
| + | ew.swap(0, | ||
| + | } | ||
| + | } | ||
| + | Void chkDense(){ | ||
| + | WindowServices ws; | ||
| + | ws.reset(0, | ||
| + | Signal s; | ||
| + | Provider p; | ||
| + | Int st =au.getType((Atom) s); | ||
| + | Int pt =au.getType((Atom) p); | ||
| + | if(ws.scan(st, | ||
| + | density=ws.getHits(0); | ||
| + | pvdrcnt=ws.getHits(1); | ||
| + | if (pvdrcnt> | ||
| + | Empty e; | ||
| + | ew[0]=e; | ||
| + | }else{ | ||
| + | diffuse(); | ||
| + | } | ||
| + | } | ||
| + | else diffuse(); | ||
| + | } | ||
| + | |||
| + | Void behave(){ | ||
| + | chkDense(); | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Node Elements ===== | ||
| + | We have some cool features in the new MFM simulator. One of them is that an Atom can change its color dynamically. We made this little '' | ||
| + | |||
| + | {{: | ||
| + | <code - Node.ulam> | ||
| + | /** | ||
| + | Node is a demo element. | ||
| + | \color #986 | ||
| + | \symbol Nd | ||
| + | \symmetries normal | ||
| + | */ | ||
| + | element Node{ | ||
| + | typedef Unsigned(6) SiteNum; | ||
| + | typedef Int(16) Coord; | ||
| + | typedef Unary(1) FireFlag; | ||
| + | typedef Int(4) Weight; | ||
| + | typedef Unsigned(8) ARGB[4]; | ||
| + | typedef Unsigned(8) ColorValue; | ||
| + | |||
| + | DebugUtils du; | ||
| + | EventWindow ew; | ||
| + | Once oc; | ||
| + | AtomUtils au; | ||
| + | Weight wa; | ||
| + | Weight wm; | ||
| + | Weight wb; | ||
| + | FireFlag fire; | ||
| + | Weight thresh; | ||
| + | ColorValue red; | ||
| + | ColorValue grn; | ||
| + | ColorValue blu; | ||
| + | |||
| + | Int getSum(){ | ||
| + | Int sum; | ||
| + | C2D mcd; | ||
| + | WindowServices ws; | ||
| + | ws.reset(1, | ||
| + | for(Int slot=ws.next(); | ||
| + | if(ew[slot] is Node){ | ||
| + | Atom a=ew[slot]; | ||
| + | Node you=(Node) a; | ||
| + | mcd=ew.getCoord((SiteNum)slot); | ||
| + | Coord mx=mcd.getX(); | ||
| + | Coord my=mcd.getY(); | ||
| + | if(mx< | ||
| + | if(my< | ||
| + | sum=sum+wa*you.fire; | ||
| + | }else if(my==0){ | ||
| + | sum=sum+wm*you.fire; | ||
| + | }else if(my> | ||
| + | sum=sum+wb*you.fire; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | return sum; | ||
| + | } | ||
| + | FireFlag getFire(Int s){ | ||
| + | if(s> | ||
| + | return 1; | ||
| + | } | ||
| + | return 0; | ||
| + | } | ||
| + | Void initSelf(){ | ||
| + | Random rd; | ||
| + | Weight w; | ||
| + | wa=(Weight)rd.between((Int)w.minof, | ||
| + | wm=(Weight)rd.between((Int)w.minof, | ||
| + | wb=(Weight)rd.between((Int)w.minof, | ||
| + | thresh=(Weight)rd.between((Int)w.minof, | ||
| + | } | ||
| + | Void changeColor(){ | ||
| + | Random rd; | ||
| + | red=rd.between(0, | ||
| + | grn=rd.between(0, | ||
| + | blu=rd.between(0, | ||
| + | } | ||
| + | ARGB getColor(Unsigned selector){ | ||
| + | ColorUtils cu; | ||
| + | ARGB ret=cu.color(0xff00ff00u); | ||
| + | if(fire==1){ | ||
| + | ret[1]=red; | ||
| + | ret[2]=grn; | ||
| + | ret[3]=blu; | ||
| + | }else{ | ||
| + | ret=cu.color(0xff090806u); | ||
| + | } | ||
| + | return ret; | ||
| + | } | ||
| + | Void behave(){ | ||
| + | Int msum; | ||
| + | if(oc.new()){ | ||
| + | initSelf(); | ||
| + | du.printContext(); | ||
| + | } | ||
| + | msum=getSum(); | ||
| + | fire=getFire(msum); | ||
| + | changeColor(); | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | We use a '' | ||
| + | |||
| + | In the '' | ||
| + | |||
| + | Like other Neurons, our '' | ||
| + | |||
dev/program_ulam.1432748826.txt.gz · Last modified: 2015/05/27 17:47 by xychen
                
                