Philosopher/0000700010252200001470000000000011472535073013217 5ustar cspjamdcsotherPhilosopher/layout.e0000600010252200001470000001070311326717236014706 0ustar cspjamdcsother%eden statusColorA="yellow"; statusColorB="yellow"; statusColorC="yellow"; statusColorD="yellow"; doorStatus=0; chop1=1; chop2=1; chop3=1; chop4=1; %donald viewport Layout int width,length point NW,NE,SW,SE,Centre line N,S,E,W N=[NW,NE] S=[SW,SE] W=[NW,SW] E=[NE,SE] SW={100,100} SE=SW+{width,0} NE=SW+{width,length} NW=SW+{0,length} Centre={(SW.1+NE.1) div 2, (SW.2+NE.2) div 2} width,length=800,800 ##### table openshape table within table { int radius point Centre circle table radius=180 Centre=~/Centre table=circle(Centre,radius) } %scout integer chop1; integer chop2; integer chop3; integer chop4; string statusColorA; string statusColorB; string statusColorC; string statusColorD; integer doorStatus; window table={ type:DONALD box:[{0,0},{500,500}] pict:"Layout" bgcolor:"grey" }; window doorShut={ type:TEXT bgcolor:"grey" bdcolor: if doorStatus==0 then "black"else "grey" endif border:1 frame:([{50,70},{50,110}]) }; window doorOpen={ type:TEXT bgcolor:"grey" bdcolor:if doorStatus==1 then "black"else "grey" endif border:1 frame:([{50,70},{90,70}]) }; window chop_1={ type:TEXT bgcolor:"grey" bdcolor:if chop1==1 then "black" else "grey" endif border:1 frame:([{250,180},{250,200}]) }; window chop_2={ type:TEXT bgcolor:"grey" bdcolor:if chop2==1 then "black" else "grey" endif border:1 frame:([{300,250},{320,250}]) }; window chop_3={ type:TEXT bgcolor:"grey" bdcolor:if chop3==1 then "black" else "grey" endif border:1 frame:([{250,300},{250,320}]) }; window chop_4={ type:TEXT bgcolor:"grey" bdcolor:if chop4==1 then "black" else "grey" endif border:1 frame:([{180,250},{200,250}]) }; window buttonA={ type:TEXT string: " A" bgcolor:statusColorA bdcolor:"black" border:1 sensitive:ON frame:([{325,140},{350,165}]) }; window buttonB={ type:TEXT string: " B" bgcolor:statusColorB bdcolor:"black" border:1 sensitive:ON frame:([{325,335},{350,360}]) }; window buttonC={ type:TEXT string: " C" bgcolor:statusColorC bdcolor:"black" border:1 sensitive:ON frame:([{150,335},{175,360}]) }; window buttonD={ type:TEXT string: " D" bgcolor:statusColorD bdcolor:"black" border:1 sensitive:ON frame:([{150,140},{175,165}]) }; window machine1={ type:TEXT string: "1" fgcolor:"grey" bgcolor:"blue" bdcolor:"black" border:1 sensitive:ON frame:([{245,125},{255,140}]) }; window machine2={ type:TEXT string: "2" fgcolor:"grey" bgcolor:"blue" bdcolor:"black" border:1 sensitive:ON frame:([{360,245},{370,260}]) }; window machine3={ type:TEXT string: "3" fgcolor:"grey" bgcolor:"blue" bdcolor:"black" border:1 sensitive:ON frame:([{245,360},{255,375}]) }; window machine4={ type:TEXT string: "4" fgcolor:"grey" bgcolor:"blue" bdcolor:"black" border:1 sensitive:ON frame:([{135,245},{145,260}]) }; window thinking={ type:TEXT string:"philosopher thinking" fgcolor:"blue" bgcolor:"grey" frame:([{90,395},{250,410}]) }; window eating={ type:TEXT string:"philosopher eating" fgcolor:"blue" bgcolor:"grey" frame:([{90,410},{250,425}]) }; window waiting={ type:TEXT string:"philosopher waiting" fgcolor:"blue" bgcolor:"grey" frame:([{90,425},{250,440}]) }; window chopstickMachine={ type:TEXT string:"chopstick machine" fgcolor:"blue" bgcolor:"grey" frame:([{295,425},{450,440}]) }; window yellowbox={ type:TEXT bgcolor:"yellow" bdcolor:"black" border:1 frame:([{70,395},{85,410}]) }; window greenbox={ type:TEXT bgcolor:"green" bdcolor:"black" border:1 frame:([{70,410},{85,425}]) }; window redbox={ type:TEXT bgcolor:"red" bdcolor:"black" border:1 frame:([{70,425},{85,440}]) }; window bluebox={ type:TEXT bgcolor:"blue" bdcolor:"black" border:1 frame:([{275,425},{285,440}]) }; screen=< buttonA/ buttonB/ buttonC/ buttonD / machine1/ machine2/ machine3/ machine4/ chop_1/ chop_2/ chop_3/ chop_4/ thinking/ eating/ waiting/ chopstickMachine/ yellowbox/ greenbox/ redbox/ bluebox/ doorShut/ doorOpen/ table >; Philosopher/TriggerToDoste.e0000600010252200001470000000461311326713466016302 0ustar cspjamdcsother%eden MOUSE_BUTTON_PRESSED=4; MOUSE_BUTTON_RELEASED=5; actionTry_A=0; actionStop_A=0; actionTry_B=0; actionStop_B=0; actionTry_C=0; actionStop_C=0; actionTry_D=0; actionStop_D=0; actionMachine_1=0; actionMachine_2=0; actionMachine_3=0; actionMachine_4=0; ## triggers to 4 philosophers proc buttonA_Trigger:buttonA_mouse_1{ if(buttonA_mouse_1[2]==MOUSE_BUTTON_PRESSED && statusColorA=="yellow") {actionTry_A=1;} if(buttonA_mouse_1[2]==MOUSE_BUTTON_PRESSED && statusColorA=="green") {actionStop_A=1;} if(buttonA_mouse_1[2]==MOUSE_BUTTON_RELEASED){ actionTry_A=0; actionStop_A=0; } } proc buttonB_Trigger:buttonB_mouse_1{ if(buttonB_mouse_1[2]==MOUSE_BUTTON_PRESSED && statusColorB=="yellow") {actionTry_B=1;} if(buttonB_mouse_1[2]==MOUSE_BUTTON_PRESSED && statusColorB=="green") {actionStop_B=1;} if(buttonB_mouse_1[2]==MOUSE_BUTTON_RELEASED){ actionTry_B=0; actionStop_B=0; } } proc buttonC_Trigger:buttonC_mouse_1{ if(buttonC_mouse_1[2]==MOUSE_BUTTON_PRESSED && statusColorC=="yellow") {actionTry_C=1;} if(buttonC_mouse_1[2]==MOUSE_BUTTON_PRESSED && statusColorC=="green") {actionStop_C=1;} if(buttonC_mouse_1[2]==MOUSE_BUTTON_RELEASED){ actionTry_C=0; actionStop_C=0; } } proc buttonD_Trigger:buttonD_mouse_1{ if(buttonD_mouse_1[2]==MOUSE_BUTTON_PRESSED && statusColorD=="yellow") {actionTry_D=1;} if(buttonD_mouse_1[2]==MOUSE_BUTTON_PRESSED && statusColorD=="green") {actionStop_D=1;} if(buttonD_mouse_1[2]==MOUSE_BUTTON_RELEASED){ actionTry_D=0; actionStop_D=0; } } ## triggers to 4 chopstick machines proc machine1_Trigger:machine1_mouse_1{ if(machine1_mouse_1[2]==MOUSE_BUTTON_PRESSED) {actionMachine_1=1;} if(machine1_mouse_1[2]==MOUSE_BUTTON_RELEASED) {actionMachine_1=0;} } proc machine2_Trigger:machine2_mouse_1{ if(machine2_mouse_1[2]==MOUSE_BUTTON_PRESSED) {actionMachine_2=1;} if(machine2_mouse_1[2]==MOUSE_BUTTON_RELEASED) {actionMachine_2=0;} } proc machine3_Trigger:machine3_mouse_1{ if(machine3_mouse_1[2]==MOUSE_BUTTON_PRESSED) {actionMachine_3=1;} if(machine3_mouse_1[2]==MOUSE_BUTTON_RELEASED) {actionMachine_3=0;} } proc machine4_Trigger:machine4_mouse_1{ if(machine4_mouse_1[2]==MOUSE_BUTTON_PRESSED) {actionMachine_4=1;} if(machine4_mouse_1[2]==MOUSE_BUTTON_RELEASED) {actionMachine_4=0;} } Philosopher/toRun0000600010252200001470000000240511472535073014254 0ustar cspjamdcsother ///step1///////////////// IN Cadence %include "eden/eden.dasm"; ////// step2 //////////////// IN Cadence .eden H = (new type = Handle ) //////step3//////// IN Cadence .eden O = (new type = Oracle chop1=1 chop2=1 chop3=1 chop4=1 statusColorA="yellow" statusColorB="yellow" statusColorC="yellow" statusColorD="yellow" ) ////////// step 4////////////////////////// IN Cadence .eden H clickTry_A=0 clickTry_B=0 clickTry_C=0 clickTry_D=0 clickStop_A=0 clickStop_B=0 clickStop_C=0 clickStop_D=0 clickMachine_1=0 clickMachine_2=0 clickMachine_3=0 clickMachine_4=0; ///////step 5 //////////// IN Cadence open the Logic.dasm ////////step 6 //////////// IN Cadence .interface := { .eden H}; ////////step 7 ////////////// IN EDEN !!! open the layout.e open the TriggerToDoste.e open the connection.e ///////step 8 ////////// IN Cadence .eden O chop1 := {@root interface2 chop1}; .eden O chop2 := {@root interface2 chop2}; .eden O chop3 := {@root interface2 chop3}; .eden O chop4 := {@root interface2 chop4}; .eden O statusColorA := {@root interface2 statusColorA}; .eden O statusColorB := {@root interface2 statusColorB}; .eden O statusColorC := {@root interface2 statusColorC}; .eden O statusColorD := {@root interface2 statusColorD}; NOW , it's Done!Philosopher/toRun~0000600010252200001470000000240511472534555014456 0ustar cspjamdcsother ///step1///////////////// IN Cadence %include "eden/eden.dasm"; ////// step2 //////////////// IN Cadence .eden H = (new type = Handle ) //////step3//////// IN Cadence .eden O = (new type = Oracle chop1=1 chop2=1 chop3=1 chop4=1 statusColorA="yellow" statusColorB="yellow" statusColorC="yellow" statusColorD="yellow" ) ////////// step 4////////////////////////// IN Cadence .eden H clickTry_A=0 clickTry_B=0 clickTry_C=0 clickTry_D=0 clickStop_A=0 clickStop_B=0 clickStop_C=0 clickStop_D=0 clickMachine_1=0 clickMachine_2=0 clickMachine_3=0 clickMachine_4=0; ///////step 5 //////////// IN Cadence open the logic.dasm ////////step 6 //////////// IN Cadence .interface := { .eden H}; ////////step 7 ////////////// IN EDEN !!! open the layout.e open the TriggerToDoste.e open the connection.e ///////step 8 ////////// IN Cadence .eden O chop1 := {@root interface2 chop1}; .eden O chop2 := {@root interface2 chop2}; .eden O chop3 := {@root interface2 chop3}; .eden O chop4 := {@root interface2 chop4}; .eden O statusColorA := {@root interface2 statusColorA}; .eden O statusColorB := {@root interface2 statusColorB}; .eden O statusColorC := {@root interface2 statusColorC}; .eden O statusColorD := {@root interface2 statusColorD}; NOW , it's Done!Philosopher/connection.e0000600010252200001470000000115211472534217015524 0ustar cspjamdcsother%eden H::clickTry_A is actionTry_A; H::clickTry_B is actionTry_B; H::clickTry_C is actionTry_C; H::clickTry_D is actionTry_D; H::clickStop_A is actionStop_A; H::clickStop_B is actionStop_B; H::clickStop_C is actionStop_C; H::clickStop_D is actionStop_D; H::clickMachine_1 is actionMachine_1; H::clickMachine_2 is actionMachine_2; H::clickMachine_3 is actionMachine_3; H::clickMachine_4 is actionMachine_4; chop1 is O::chop1; chop2 is O::chop2; chop3 is O::chop3; chop4 is O::chop4; statusColorA is O::statusColorA; statusColorB is O::statusColorB; statusColorC is O::statusColorC; statusColorD is O::statusColorD;Philosopher/Logic.dasm0000600010252200001470000002611511472534360015127 0ustar cspjamdcsother @root interface=(new); @root interface .interface clickTry_A=0; .interface clickTry_B=0; .interface clickTry_C=0; .interface clickTry_D=0; .interface clickStop_A=0; .interface clickStop_B=0; .interface clickStop_C=0; .interface clickStop_D=0; .interface clickMachine_1=0; .interface clickMachine_2=0; .interface clickMachine_3=0; .interface clickMachine_4=0; #################### ##%dasm @root philosopher=(new); @root philosopher .philosopher eating_A=false .philosopher eating_B=false .philosopher eating_C=false .philosopher eating_D=false chop_1=true chop_2=true chop_3=true chop_4=true clickTry_A=false ##change it back to false afterwards clickTry_B=false clickTry_C=false clickTry_D=false clickStop_A=false ##change it back to false afterwards clickStop_B=false clickStop_C=false clickStop_D=false ############ dealing with the with the interface: change true/false to 1/0 for eden clickTry_A := { if(@root interface clickTry_A>0) {true} else {false} } clickTry_B := { if(@root interface clickTry_B>0) {true} else {false} } clickTry_C := { if(@root interface clickTry_C>0) {true} else {false} } clickTry_D := { if(@root interface clickTry_D>0) {true} else {false} } clickStop_A := { if(@root interface clickStop_A>0) {true} else {false} } clickStop_B := { if(@root interface clickStop_B>0) {true} else {false} } clickStop_C := { if(@root interface clickStop_C>0) {true} else {false} } clickStop_D := { if(@root interface clickStop_D>0) {true} else {false} } clickMachine_1 := { if(@root interface clickMachine_1>0) {true} else {false} } clickMachine_2 := { if(@root interface clickMachine_2>0) {true} else {false} } clickMachine_3 := { if(@root interface clickMachine_3>0) {true} else {false} } clickMachine_4 := { if(@root interface clickMachine_4>0) {true} else {false} } ######################## try_A := { if (.chop_1 and (.chop_2 )) { if (..clickTry_A ) { true } else { false } } else { false } } try_B := { if (.chop_2 and (.chop_3 )) { if (..clickTry_B ) { true } else { false } } else { false } } try_C := { if (.chop_3 and (.chop_4 )) { if (..clickTry_C ) { true } else { false } } else { false } } try_D := { if (.chop_4 and (.chop_1 )) { if (..clickTry_D ) { true } else { false } } else { false } } #################### stop_A := { if (.eating_A and (.clickStop_A )) { true } else { false } } stop_B := { if (.eating_B and (.clickStop_B )) { true } else { false } } stop_C := { if (.eating_C and (.clickStop_C )) { true } else { false } } stop_D := { if (.eating_D and (.clickStop_D )) { true } else { false } } ############### eating_A:= { if (.stop_A not ) { if (..try_A ) { true } else { ..eating_A } } else { false } } eating_B:= { if (.stop_B not ) { if (..try_B ) { true } else { ..eating_B } } else { false } } eating_C:= { if (.stop_C not ) { if (..try_C ) { true } else { ..eating_C } } else { false } } eating_D:= { if (.stop_D not ) { if (..try_D ) { true } else { ..eating_D } } else { false } } ############################################################### ############################################################## ############################################################ ## chopstick and chopstick_machine clickMachine_1=false isMachineOn_1=false ##before A or D successfully try to eat action,click machine can make sure there will be a chopstick at the corresponding place. isMachineOn_1 := { if (.clickMachine_1 and (.try_A not) and (.try_D not )) { true } else { if (..try_A or (..try_D )) { false } else { ..isMachineOn_1 } } } Machine_1 := { if (.isMachineOn_1 and (.chop_1 not )) { .chop_1 not } else { false } } watcher_1=false watcher_1 := { if (.clickStop_A or (.clickStop_D )) { true } else { if (..try_A or (..try_D )) { false } else { ..watcher_1 } } } w_1 := {.eating_D or(.eating_A)} ##chop_1 depends on first if there is any machine_1 clicking, chop_1 is true; if not,at that instant, A or D eating and no one (A or D) take the stopEating action. chop_1 will be false. chop_1 := { if (.Machine_1 not and (.isMachineOn_1 not )) { if (..w_1 and (..watcher_1 not )) { false } else { true } } else { true } } ### ## chopstick and chopstick_machine clickMachine_2=false isMachineOn_2=false isMachineOn_2 := { if (.clickMachine_2 and (.try_A not) and (.try_B not )) { true } else { if (..try_A or (..try_B )) { false } else { ..isMachineOn_2 } } } Machine_2 := { if (.isMachineOn_2 and (.chop_2 not )) { .chop_2 not } else { false } } watcher_2=false watcher_2 := { if (.clickStop_A or (.clickStop_B )) { true } else { if (..try_A or (..try_B )) { false } else { ..watcher_2 } } } w_2 := {.eating_A or(.eating_B)} chop_2 := { if (.Machine_2 not and (.isMachineOn_2 not )) { if (..w_2 and (..watcher_2 not )) { false } else { true } } else { true } } ## ### ## chopstick and chopstick_machine clickMachine_3=false isMachineOn_3=false isMachineOn_3 := { if (.clickMachine_3 and (.try_B not) and (.try_C not )) { true } else { if (..try_B or (..try_C )) { false } else { ..isMachineOn_3 } } } Machine_3 := { if (.isMachineOn_3 and (.chop_3 not )) { .chop_3 not } else { false } } watcher_3=false watcher_3 := { if (.clickStop_B or (.clickStop_C )) { true } else { if (..try_B or (..try_C )) { false } else { ..watcher_3 } } } w_3 := {.eating_B or(.eating_C)} chop_3 := { if (.Machine_3 not and (.isMachineOn_3 not )) { if (..w_3 and (..watcher_3 not )) { false } else { true } } else { true } } ## clickMachine_4=false isMachineOn_4=false isMachineOn_4 := { if (.clickMachine_4 and (.try_C not) and (.try_D not )) { true } else { if (..try_C or (..try_D )) { false } else { ..isMachineOn_4 } } } Machine_4 := { if (.isMachineOn_4 and (.chop_4 not )) { .chop_4 not } else { false } } watcher_4=false watcher_4 := { if (.clickStop_C or (.clickStop_D )) { true } else { if (..try_C or (..try_D )) { false } else { ..watcher_4 } } } w_4 := {.eating_C or(.eating_D)} chop_4 := { if (.Machine_4 not and (.isMachineOn_4 not )) { if (..w_4 and (..watcher_4 not )) { false } else { true } } else { true } } ##formalization, to connect with eden########################################### isStatusSame is {if(.statusIsThinking_A and(.statusIsThinking_B) and (.statusIsThinking_C) and (.statusIsThinking_D)) {0} else if(..statusIsEating_A and (..statusIsEating_B) and (..statusIsEating_C) and (..statusIsEating_D)) {0} else {1}} ## ,when 0, door will shut, in this case there is no chance 4 people waiting at the same time to make door shut. ## input ## output to connect to eden statusIsEating_A is {.eating_A} statusIsEating_B is {.eating_B} statusIsEating_C is {.eating_C} statusIsEating_D is {.eating_D} doorStatus is {.isStatusSame} statusIsThinking_A is {if(.statusIsEating_A not and (.chop_1) and (.chop_2)) {true} else {false}} statusIsThinking_B is {if(.statusIsEating_B not and (.chop_2) and (.chop_3)) {true} else {false}} statusIsThinking_C is {if(.statusIsEating_C not and (.chop_3) and (.chop_4)) {true} else {false}} statusIsThinking_D is {if(.statusIsEating_D not and (.chop_4) and (.chop_1)) {true} else {false}} statusIsWaiting_A is {if(.statusIsEating_A or (.statusIsThinking_A)) {false} else {true}} statusIsWaiting_B is {if(.statusIsEating_B or (.statusIsThinking_B)) {false} else {true}} statusIsWaiting_C is {if(.statusIsEating_C or (.statusIsThinking_C)) {false} else {true}} statusIsWaiting_D is {if(.statusIsEating_D or (.statusIsThinking_D)) {false} else {true}} ; ###################################### @root interface2=(new); @root interface2 .interface2 chop1 is {if( @root philosopher chop_1) {1} else {0}} .interface2 chop2 is {if( @root philosopher chop_2) {1} else {0}} .interface2 chop3 is {if( @root philosopher chop_3) {1} else {0}} .interface2 chop4 is {if( @root philosopher chop_4) {1} else {0}} .interface2 statusColorA is {if(@root philosopher statusIsEating_A){"green"} else if(@root philosopher statusIsThinking_A){"yellow"} else {"red"}}; .interface2 statusColorB is {if(@root philosopher statusIsEating_B){"green"} else if(@root philosopher statusIsThinking_B){"yellow"} else {"red"}}; .interface2 statusColorC is {if(@root philosopher statusIsEating_C){"green"} else if(@root philosopher statusIsThinking_C){"yellow"} else {"red"}}; .interface2 statusColorD is {if(@root philosopher statusIsEating_D){"green"} else if(@root philosopher statusIsThinking_D){"yellow"} else {"red"}};