def doTest(high,prob,low,medium): p=[] for i in range(1): e=Env(high=high,prob=prob,low=low,medium=medium) e.m=SequentialModel() ccm.log_everything(e) e.run() p.append(e.p) return sum(p)/len(p)
def load(self, prodFile="") -> str: #load all the production function names from prodFile self.prodFile = prodFile prodMod = importlib.import_module(prodFile) functions_list = [o for o in getmembers(prodMod) if isfunction(o[1])] #for each production, add name and reference to CCMAgent class for x in functions_list: name = x[0] log.debug(f"Adding Production: {name}") setattr(CCMAgent, f'{name}', x[1]) self.agent = CCMAgent() self.ccm_env.agent = self.agent # self.load(self) self.perception = Perception(self.agent) self.working = WorkingMemory(self.agent) self.declarative = DeclarativeMemory(self.agent) self.procedural = ProceduralMemory(self.agent) self.motor = Motor(self.ccm_env) # generate a default file #set default options test_log = ccm.log(html=True) ccm.log_everything(self.agent, test_log) # This is how to dynamically load production rules result = "stub: load ccm actr model" # self.agent.goal.set('add 5 2 count:None sum:None') return result
b_focus.set('change_state') motor.motor_finst_reset() print 'I have exposed ', target def cut_wire(b_method='method:cut_wire target:?target state:running', b_focus='change_state'): # target is the chunk to be altered motor.change_state(target, "cut") b_method.set('method:change_state target:?target state:running') b_operator.set('operator:cut target:?target state:running') b_focus.set('cutting_wire') print 'cut wire' print 'target object = ', target def wire_cut(b_method='method:?method target:?target state:running', motor_finst='state:finished', b_focus='cutting_wire'): b_method.set('method:?method target:?target state:finished') motor.motor_finst_reset() b_focus.set('wire_is_cut') print 'I have cut ', target ############## run model ############# tim = MyAgent() # name the agent subway = MyEnvironment() # name the environment subway.agent = tim # put the agent in the environment ccm.log_everything(subway) # print out what happens in the environment subway.run() # run the environment ccm.finished() # stop the environment
def touchdown4(Focusbuffer='unit_task:touchdown task_goal:ATC_com'): print 'ATC informed of landing and intention' Focusbuffer.set('unit_task:finished_planning_unit_unit task_goal:end') ## Touch and go abort landing def touch_go1(Focusbuffer='unit_task:touch_and_go task_goal:start'): print 'Insufficient braking distance for safe touchdown' Focusbuffer.set('unit_task:touch_and_go task_goal:first_third') def touch_go2(Focusbuffer='unit_task:touch_and_go task_goal:first_third'): print 'ATC informed of touch and go decision' Focusbuffer.set('unit_task:touch_and_go task_goal:brakes') def touch_go3(Focusbuffer='unit_task:touch_and_go task_goal:brakes'): print 'touch in middle third of runway' Focusbuffer.set('unit_task:touch_and_go task_goal:ATC_com') def touch_go4(Focusbuffer='unit_task:touch_and_go task_goal:ATC_com'): print 'Aircraft re-entering airspace' Focusbuffer.set('unit_task:finished_planning_unit_unit task_goal:end') pilot=MyAgent() # the agent subway=MyEnvironment() # the environment subway.agent=pilot # the agent in the environment ccm.log_everything(subway) # print out of what happens in the environment log=ccm.log(html=True) subway.run() # runs the environment ccm.finished() # stops the environment
goal.set('say ?word') def say_response(goal='say ?word',retrieval='child ?word ?word2'): self.parent.say(word2) goal.set('imagine') def say_response_fail(goal='say',memory='error:True'): self.parent.say('unknown') goal.set('imagine') def imagine(goal='imagine',top='message:?word!None'): imaginal.set(word) goal.set('wait') def wait(goal='wait',top='message:None'): goal.set('read') e=Environment() e.model=AssociativeModel() ccm.log_everything(e) e.run() ccm.finished()
self.action=None self.busy=False class MyAgent(ACTR): focus=Buffer() body=grid.Body() motor=MotorModule() def init(): focus.set('wander') def wandering_forward(focus='wander',motor='busy:False'): motor.go_forward() def wandering_left(focus='wander',motor='busy:False'): motor.go_left() def wandering_right(focus='wander',motor='busy:False'): motor.go_right() world=grid.World(MyCell,map=mymap) agent=MyAgent() world.add(agent,x=5,y=3) ccm.display(world) ccm.log_everything(agent) world.run()
def decision_1b(focus='buffer 2', DMbuffer='action1:?action1'): print " " print action1 focus.set('buffer 1') # LOOP to buffer 1 def decision_2a(focus='buffer 1'): print " " print "Requesting action 2..." DM.request('action2:?') focus.set('buffer 3') self.reward(0.1) def decision_2b(focus='buffer 3', DMbuffer='action2:?action2'): print " " print action2 focus.set('buffer 1') # LOOP to buffer 1 def do_nothing(focus='buffer done'): print "I'm done" self.stop() tim = MyAgent() subway = MyEnvironment() subway.agent = tim ccm.log_everything(subway) subway.run( 20) # run for 5 seconds to learn that param ham is more rewarding to use ccm.finished()
focus.set('state:evaluate') def play_rock(focus='state:play', referee='signal:go'): motor.B_rock() motor.B_OK() focus.set('state:evaluate') def play_scissors(focus='state:play', referee='signal:go'): motor.B_scissors() motor.B_OK() focus.set('state:evaluate') #for i in range(100): # f = open('newLg1t-14n125_Lg2t1n28.txt', 'a') john=Ref() tim=Lag1player() tom=Lag2player() octagon=MyEnvironment() octagon.agent=john octagon.agent=tim octagon.agent=tom ccm.log_everything(octagon) # log=ccm.log(html=True) octagon.run() ccm.finished() # f.close()
print "I have a piece of bread" focus.set('sandwich cheese') def cheese(focus='sandwich cheese'): print "I have put cheese on the bread" focus.set('sandwich ham') def ham(focus='sandwich ham'): print "I have put ham on the cheese" focus.set('sandwich bread_top') def parma_ham(focus='sandwich ham'): # this production competes with the ham production print "I have put parma ham on the cheese" focus.set('sandwich bread_top') self.reward(0.1) # but using parma ham is intrinsically rewarding def bread_top(focus='sandwich bread_top'): print "I have put bread on the ham" print "I have made a ham and cheese sandwich" focus.set('sandwich bread') # make another sandwich tim=MyAgent() subway=MyEnvironment() subway.agent=tim ccm.log_everything(subway) subway.run(5) # run for 5 seconds to learn that param ham is more rewarding to use ccm.finished()
env.run() #common_model = SimpleModel() actrGameEnv = GameEnvModel() if __name__ == "__main__": #app.run(main) sc2agent = BeaconAgent() actrGameEnv.agent = ActrAgent() #actr_agent.focus.set('no_op') #sc2agent.actr_setup(deepcopy(actr_agent)) ccm.log_everything(actrGameEnv) #ccm.log(actrGameEnv) game_thread = threading.Thread(target=sc2_thread, args=sys.argv) game_thread.start() #model_thread = Process(target=actr_thread, args=sys.argv) model_thread = threading.Thread(target=actrGameEnv.run(), args=sys.argv) model_thread.start() #time.sleep(25) # game_thread = Process(target=sc2_thread, args=sys.argv)
def run(self): agent = Agent(self.text_buffer) env = AgentEnvironment() env.model = agent ccm.log_everything(env) agent.run() #self.time = 0 #self.short_memory = [] #self.long_memory = ({}, {}) #self.responses = [] #eye = self.eye #last_line = self.text_buffer.shape[0] - 1 #fovea = [i for i, s in enumerate(eye.retina.slots) #if s == Retina.SLOT_HIGH_RES] #fovea_start = min(fovea) #fovea_stop = max(fovea) #fovea_idx = slice(fovea_start, fovea_stop + 1) #while True: #code_str = eye.view() #fix_start = self.time #self.time += PythonDummyModel.ENCODING_TIME #self.short_memory.append(code_str[fovea_idx]) ## Record fixation #self.fixations.append([eye.pos[0], eye.pos[1], #fix_start, self.time - fix_start]) ## Decide on next fixation #next_pos = (self.eye.pos[0] + len(fovea), self.eye.pos[1]) ## Look for whitespace on right #if len(code_str[(fovea_stop + 1):].strip()) == 0: ## Execute line in memory (if not blank) #full_line = "".join(self.short_memory) #if len(full_line.strip()) > 0: #mem_globals, mem_locals = self.long_memory #response = "" #with stdoutIO() as out: #exec(full_line, mem_globals, mem_locals) #response = out.getvalue().strip() #if len(response) > 0: #self.time += (len(response) * PythonDummyModel.KEYSTROKE_TIME) #self.responses.append(response) ## Move to next line #next_pos = (0, self.eye.pos[1] + 1) #self.short_memory = [] #if next_pos[1] > last_line: #break ## Move eye #self.time += eye.move_to(next_pos) return agent.now(), agent.responses
def init(): focus.set('goal:boardbus object:busstop') def correct_bus(focus='goal:boardbus object:busstop'): # if focus buffer has this chunk then.... print "I see the route 8 bus" # print focus.set('goal:boardbus object:stop_at_flag') # change chunk in focus buffer def stop_at_flag(focus='goal:boardbus object:stop_at_flag'): # the rest of the productions are the same print "I am standing at the flag" # but carry out different actions focus.set('goal:boardbus object:open_door') def open_door(focus='goal:boardbus object:open_door'): print "I am waiting for the door to open" focus.set('goal:boardbus object:climb_in') def climb_in(focus='goal:boardbus object:climb_in'): print "I have climbed in" print "I have boarded the bus" focus.set('goal:stop') def stop_production(focus='goal:stop'): self.stop() # stop the agent gautam=MyAgent() # name the agent octranspo=MyEnvironment() # name the environment octranspo.agent=gautam # put the agent in the environment ccm.log_everything(octranspo) # print out what happens in the environment octranspo.run() # run the environment ccm.finished() # stop the environment
print "I have pressed the letter u" focus.set('goal:typejumped object:letterm') def letterm(focus='goal:typejumped object:letterm'): print "I have pressed the letter m" focus.set('goal:typejumped object:letterp') def letterp(focus='goal:typejumped object:letterp'): print "I have pressed the letter p" focus.set('goal:typejumped object:lettere') def lettere(focus='goal:typejumped object:lettere'): print "I have pressed the letter e" focus.set('goal:typejumped object:letterd') def letterd(focus='goal:typejumped object:letterd'): print "I have pressed the letter d" print "I have typed the word 'jumped'" focus.set('goal:stop') def stop_production(focus='goal:stop'): self.stop() matthew=MyAgent() typingclass=MyEnvironment() typingclass.agent=matthew ccm.log_everything(typingclass) typingclass.run() ccm.finished()
print 'ATC informed of landing and intention' Focusbuffer.set('unit_task:touchdown task_goal:complete') ## Touch and go abort landing def touch_go1(Focusbuffer='unit_task:touch_and_go task_goal:start'): print 'Insufficient braking distance for safe touchdown' Focusbuffer.set('unit_task:touch_and_go task_goal:first_third') def touch_go2(Focusbuffer='unit_task:touch_and_go task_goal:first_third'): print 'ATC informed of touch and go decision' Focusbuffer.set('unit_task:touch_and_go task_goal:brakes') def touch_go3(Focusbuffer='unit_task:touch_and_go task_goal:brakes'): print 'touch in middle third of runway' Focusbuffer.set('unit_task:touch_and_go task_goal:ATC_com') def touch_go4(Focusbuffer='unit_task:touch_and_go task_goal:ATC_com'): print 'Aircraft re-entering airspace' Focusbuffer.set('unit_task:touch_and_go task_goal:complete') pilot = MyAgent() # the agent airfield = MyEnvironment() # the environment airfield.agent = pilot # the agent in the environment ccm.log_everything(airfield) # print out of what happens in the environment log = ccm.log(html=True) airfield.run() # runs the environment ccm.finished() # stops the environment
import ccm from ccm.lib.actr import * # get environment elements from Objects import Objects from Coffee_Machine import Coffee_Machine_Objects # put objects together Lofi_Cafe = type('Lofi_Cafe', (Objects, Coffee_Machine_Objects), dict(lofi='lofi')) # create environment lofi_cafe = Lofi_Cafe() # get agent descriptions from Barista_Dave import Barista_Dave from Coffee_Machine import Coffee_Machine # create agents for environment dave = Barista_Dave() coffee_machine = Coffee_Machine() # put agents into environment lofi_cafe.agent = dave lofi_cafe.agent = coffee_machine # run ccm.log_everything(lofi_cafe) lofi_cafe.run() ccm.finished()
goal.set('choose rock') def recall_fail_s(goal='recall',memory='error:True'): goal.set('choose scissors') def recall_success_r(goal='recall',retrieval='history ? ? rock'): goal.set('choose paper') def recall_success_p(goal='recall',retrieval='history ? ? paper'): goal.set('choose scissors') def recall_success_s(goal='recall',retrieval='history ? ? scissors'): goal.set('choose rock') def choose(goal='choose ?option'): choice.choose(option) goal.set('check response') def check_response(goal='check response',choice='opponent:?choice',imaginal='?last ?last2'): memory.add('history ?last ?last2 ?choice') retrieval.clear() imaginal.set('?last2 ?choice') goal.set('play rps') env=RockPaperScissors() env.model1=MemoryPlayer() env.model1.choice=env.choice1 ccm.log_everything(env.model1) ccm.display(env) env.run()
sandwich.append(ingred) goal.set("build_sandwich 4 turkey") def place_turkey(goal="build_sandwich 4 ?meat"): sandwich.append(meat) goal.set("build_sandwich 5 provolone") def place_cheese(goal="build_sandwich 5 ?cheese"): sandwich.append(cheese) goal.set("build_sandwich 6 top_bread") def forgot_mayo(goal="build_sandwich 6 top_bread"): goal.set("build_sandwich 6 mayo") def place_mayo_top(goal="build_sandwich 6 mayo"): sandwich.append("mayo") goal.set("build_sandwich 7 top_bread") def place_top_bread(goal="build_sandwich 7 top_bread"): sandwich.append("top_bread") self.stop() class EmptyEnvironment(ccm.Model): pass env_name = EmptyEnvironment() agent_name = SandwichBuilder() env_name.agent = agent_name ccm.log_everything(env_name) env_name.run()
print "With a plum shirt I should wear an appropriate tie." print "Aubergine is the best colour" DM.request('tie:tie1 tie:?colour') focus.set('consider_tie') def fetch(focus='consider_tie', DMbuffer='tie:? colour:?colour'): print "I will wear this tie, it is" print colour focus.set('tie_it') def confused(focus='consider_tie', DMbuffer=None, DM='error:True'): print "I will wear this tie, it is" print "Oh dear... these colours are too similar. Try again." focus.set('decide_tie') def tie_it(focus='tie_it'): print "Tie a full windsor knot." print "I am now a snappy gentleman." focus.set('stop') def stop_production(focus='stop'): self.stop() reg=MyAgent() # name the agent boudoire=MyEnvironment() # name the environment boudoire.agent=reg # put the agent in the environment ccm.log_everything(boudoire) # print out what happens in the environment boudoire.run() # run the environment ccm.finished() # stop the environment
DM.add("customer:customer1 order:42") focus.set("rehearse") def request_chunk(focus="rehearse"): print "recalling the order" DM.request("customer:customer1 order:?42") focus.set("recall") def recall_chunk(focus="recall", DMbuffer="customer:customer1 order:?order"): print "Customer 1 wants......." print order # note - outside the quotes you do not need the ? DM.add("customer:customer1 ?order") # but inside you do DMbuffer.clear() # each time you put something in memory (DM.add) it increases activation focus.set("rehearse") def forgot(focus="recall", DMbuffer=None, DM="error:True"): # DMbuffer=none means the buffer is empty # DM='error:True' means the search was unsucessful print "I recall they wanted......." print "I forgot" focus.set("stop") tim = MyAgent() # name the agent burgershop = MyEnvironment() # name the environment burgershop.agent = tim # put the agent in the environment ccm.log_everything(burgershop) # print out what happens in the environment log = ccm.log(html=True) burgershop.run(2) # run the environment FOR 2 SECONDS ccm.finished() # stop the environment
goal.modify(current="four") def countFromFour(goal="action:counting current:four target:!four"): goal.modify(current="five") def countFromFive(goal="action:counting current:five target:!five"): goal.modify(current="six") def countFromSix(goal="action:counting current:six target:!six"): goal.modify(current="seven") def countFromSeven(goal="action:counting current:seven target:!seven"): goal.modify(current="eight") def countFromEight(goal="action:counting current:eight target:!eight"): goal.modify(current="nine") def countFromNine(goal="action:counting current:nine target:!nine"): goal.modify(current="ten") def countFinished(goal="action:counting current:?x target:?x"): print "Finished counting to", x goal.clear() # run the model model = ExpertCountingModel() ccm.log_everything(model) model.goal.set("action:counting current:one target:five") model.run()
#if you take the unit_task out of this one too, it will also be recycled. def manage_heading_look_failed(b_operator='operator:see_the_movement', vision_module='error:True', b_vision=None): #should fire ~%50 of the time with _so_return b_operator.set('operator:look_for_movement') def manage_heading_look_failed_so_return(b_unit_task='unit_task:manage_heading', b_operator='operator:see_the_movement', vision_module='error:True', b_vision=None): b_operator.set('operator:none') b_unit_task.set('unit_task:none') #should reset and find a new unit task VisualReturn = ccm.scheduler.TC pilot=MyAgent() Cockpit=MyEnvironment() Cockpit.differencesList = [] Cockpit.agent=pilot pilot.toDo = ccm.scheduler.aTodo pilot.toDo[3] = '0;' #rudder initialization Cockpit.VisualReturn = ccm.scheduler.TC pilot.VisualReturn = ccm.scheduler.TC ccm.log_everything(Cockpit) Cockpit.run(25) ccm.finished()
motor.reset_hand() focus.set('state:request_a deck:a') else: focus.set('stop') def stop_production(focus='stop'): global total_win global total_loss global output f = open("output.txt", "w") x = 0 line = "" for i in output: x+=1 line += "%s " % i if not x%3: line += "\n" f.write(line+"\n") f.close() print("total win = {}".format(total_win)) print("total loss = {}".format(total_loss)) self.stop() matthew=MyAgent() empty_environment=MyEnvironment() empty_environment.agent=matthew ccm.log_everything(empty_environment) log=ccm.log(html=False) empty_environment.run() ccm.finished()
def finishing_touch(focus='finishing_touch'): motor.do_clean() motor.arrange_razor() focus.set('stylehair') def stylehair(focus='stylehair'): print "Arrange the newly coiffed hair into a style" motor.do_comb() motor.arrange_comb() focus.set('done') def done(focus='done'): motor.Bea_speak() print "All done, sir" focus.set('complete') def stop_production(focus='end'): self.stop() Reginald=MyAgent() Beasly=MyAgent2() barbershop=MyEnvironment() barbershop.agent=Reginald barbershop.agent=Beasly ccm.log_everything(barbershop) barbershop.run() ccm.finished()
def wandering_left(focus='wander'): body.turn_left() body.go_forward() def wandering_right(focus='wander'): body.turn_right() body.go_forward() world=grid.World(MyCell,map=mymap) agent=MyAgent() agent.body.color='blue' world.add(agent,x=5,y=3) agent2=MyAgent() agent2.body.color='green' world.add(agent2,x=9,y=6) agent3=MyAgent() agent3.body.color='red' world.add(agent3,x=2,y=6) ccm.log_everything(agent,log.blue) ccm.log_everything(agent2,log.green) ccm.log_everything(agent3,log.red) ccm.display(world) world.run()
def touchdown4(Focusbuffer='unit_task:touchdown task_goal:ATC_com'): print 'ATC informed of landing and intention' Focusbuffer.set('unit_task:touchdown task_goal:complete') ## Touch and go abort landing def touch_go1(Focusbuffer='unit_task:touch_and_go task_goal:start'): print 'Insufficient braking distance for safe touchdown' Focusbuffer.set('unit_task:touch_and_go task_goal:first_third') def touch_go2(Focusbuffer='unit_task:touch_and_go task_goal:first_third'): print 'ATC informed of touch and go decision' Focusbuffer.set('unit_task:touch_and_go task_goal:brakes') def touch_go3(Focusbuffer='unit_task:touch_and_go task_goal:brakes'): print 'touch in middle third of runway' Focusbuffer.set('unit_task:touch_and_go task_goal:ATC_com') def touch_go4(Focusbuffer='unit_task:touch_and_go task_goal:ATC_com'): print 'Aircraft re-entering airspace' Focusbuffer.set('unit_task:touch_and_go task_goal:complete') pilot=MyAgent() # the agent airfield=MyEnvironment() # the environment airfield.agent=pilot # the agent in the environment ccm.log_everything(airfield) # print out of what happens in the environment log=ccm.log(html=True) airfield.run() # runs the environment ccm.finished() # stops the environment
memory.add('lawyer in store') def start_person(goal='test ?person ?location'): memory.request('?person in ?') goal.set('recall ?person ?location') def start_location(goal='test ?person ?location'): memory.request('? in ?location') goal.set('recall ?person ?location') def respond_yes(goal='recall ?person ?location', retrieval='?person in ?location'): print 'yes' goal.clear() def respond_no_person(goal='recall ?person ?location', retrieval='? in !?location'): print 'no' goal.clear() def respond_no_location(goal='recall ?person ?location', retrieval='!?person in ?'): print 'no' goal.clear() model = FanModel() ccm.log_everything(model) model.goal.set('test hippie park') model.run()
def PRO_3_do_dofinish_CONFLICT_ERROR_PHYSICAL_HELP_FAIL( goal='pro_3 dofinish require physical help to continue', utility=params.utility_fail): print "------------------- REQUIRE PHYSICAL HELP FAIL AND CONTINUE ------------------------------------------" goal.set('pro_3 dofinish require physical help by caregiver') def PRO_3_do_dofinish_CONFLICT_ERROR_PHYSICAL_HELP_INCAPABLE( goal='pro_3 dofinish require physical help by caregiver'): print "------------------- INCAPABLE AND CONTINUE ------------------------------------------" goal.set('stop') ## END OF 2 BEHAVIOR DO SAME ACTION def stop_production(goal='stop'): self.stop() class MyEnvironment(ccm.Model): pass dementia_user = MyAgent() # name the agent smart_home = MyEnvironment() # name the environment smart_home.agent = dementia_user # put the agent in the environment log = ccm.log(html=True) ccm.log_everything(smart_home) # print out what happens in the environment smart_home.run() # run the environment #smarthome.run(1000) # run the environment ccm.finished() # stop the environment
print "choosing a type of protein" add = '24' DM.request('protein:?add') focus.set('goal:chilli object:protein') def order(focus='goal:chilli object:protein', DMbuffer='protein:!?protein'): #will choose a type of protein to add to chilli print "I've decided to add", protein if protein == 'meat': print "We are having meat chilli" #prints if it chooses meat else: print "We are having vegetarian chilli" #prints if it chooses chickpeas focus.set('add_sourcream') def sourcream(focus='add_sourcream'): print "I have added the sourcream" print "the chilli is ready to eat!" focus.set('stop') def stop_production(focus='stop'): self.stop() matthew=MyAgent() tacoplace=MyEnvironment() tacoplace.agent=matthew ccm.log_everything(tacoplace) tacoplace.run() ccm.finished()
goal.set('choose scissors') def recall_success_r(goal='recall', retrieval='history ? ? rock'): goal.set('choose paper') def recall_success_p(goal='recall', retrieval='history ? ? paper'): goal.set('choose scissors') def recall_success_s(goal='recall', retrieval='history ? ? scissors'): goal.set('choose rock') def choose(goal='choose ?option'): choice.choose(option) goal.set('check response') def check_response(goal='check response', choice='opponent:?choice', imaginal='?last ?last2'): memory.add('history ?last ?last2 ?choice') retrieval.clear() imaginal.set('?last2 ?choice') goal.set('play rps') env = RockPaperScissors() env.model1 = MemoryPlayer() env.model1.choice = env.choice1 ccm.log_everything(env.model1) ccm.display(env) env.run()
): Behaviour ## Operators def New Operator(Firing Condition, ): Behaviour ## Global productions for retrieving Unit Tasks from DM def request_next_unit_task(b_plan_unit='planning_unit:?planning_unit cuelag:?cuelag cue:?cue unit_task:?unit_task state:running', b_unit_task='unit_task:?unit_task state:finished'): DM.request('planning_unit:?planning_unit cue:?unit_task unit_task:? cuelag:?cue') b_plan_unit.set('planning_unit:?planning_unit cuelag:?cuelag cue:?cue unit_task:?unit_task state:retrieve') def retrieve_next_unit_task(b_plan_unit='state:retrieve', b_DM='planning_unit:?planning_unit cuelag:?cuelag cue:?cue!finished unit_task:?unit_task'): b_plan_unit.set('planning_unit:?planning_unit cuelag:?cuelag cue:?cue unit_task:?unit_task state:running') b_unit_task.set('unit_task:?unit_task state:start') def last_unit_task(b_unit_task='unit_task:finished state:start', b_plan_unit='planning_unit:?planning_unit'): b_unit_task.set('stop') ## Code to run the model tim = MyAgent() env = MyEnvironment() env.agent = tim ccm.log_everything(env) env.run() ccm.finished()
def read_word(goal='read', top='message:?word!None'): goal.set('respond ?word') def get_response(goal='respond ?word', memory='busy:False'): memory.request('child ?word ?') goal.set('say ?word') def say_response(goal='say ?word', retrieval='child ?word ?word2'): self.parent.say(word2) goal.set('imagine') def say_response_fail(goal='say', memory='error:True'): self.parent.say('unknown') goal.set('imagine') def imagine(goal='imagine', top='message:?word!None'): imaginal.set(word) goal.set('wait') def wait(goal='wait', top='message:None'): goal.set('read') e = Environment() e.model = AssociativeModel() ccm.log_everything(e) e.run() ccm.finished()
print 'it has ^ ^ ^' print feature1 ## same trick - used to compare feature1 in focus to a feature in imaginal ## fires with a match def check_no( focus_buffer='isa:?object location:?loc feature1:?feature1 action:check', imaginalbuffer='feature1:!?feature1'): focus_buffer.set('isa:?object location:?loc action:look') visual_buffer.clear print 'it has a @ @ @' print feature1 ## same trick - used to compare feature1 in focus to a feature in imaginal ## fires with a not match def not_found(focus_buffer='isa:?object location:?loc action:get', visual_buffer=None): focus_buffer.set('isa:?object location:?loc action:look') visual_buffer.clear print 'where is that % % %' print object tim = MyAgent() env = Sock_drawer() env.agent = tim ccm.log_everything(env) env.run() ccm.finished()
print "i have put the condiment on the sandwich" focus.set('sandwich bread_top') def bread_top(focus='sandwich bread_top'): print "I have put bread on the ham" print "I have made a ham and cheese sandwich" focus.set('get_side') def side(focus='get_side'): print "recalling side order" DM2.request('side:?') # retrieve a chunk from DM2 into the DM2 buffer focus.set('sandwich side') def sideorder(focus='sandwich side', DM2buffer='side:?side'): # match to DM2buffer as well print "I recall they wanted..." # put slot 2 value in ?side print side print "I have added the side order" focus.set('stop') def stop_production(focus='stop'): self.stop() gautam=MyAgent() # name the agent harveys=MyEnvironment() # name the environment harveys.agent=gautam # put the agent in the environment ccm.log_everything(harveys) # print out what happens in the environment harveys.run() # run the environment ccm.finished() # stop the environment
focus.set("goal:pizza object:dough") def dough(focus="goal:pizza object:dough"): # if focus buffer has this chunk then.... print "I have made a round piece of dough" # print focus.set("goal:pizza object:cheese") # change chunk in focus buffer def cheese(focus="goal:pizza object:cheese"): # the rest of the productions are the same print "I have put cheese on the dough" # but carry out different actions focus.set("goal:pizza object:ham") def chicken(focus="goal:pizza object:ham"): print "I have put chicken on the cheese" focus.set("goal:pizza object:sauce") def sauce(focus="goal:pizza object:cheese"): print "I have put sauce on the chicken" print "I have made a chicken and cheese pizza" focus.set("goal:stop") def stop_production(focus="goal:stop"): self.stop() # stop the agent tim = MyAgent() # name the agent pizzashop = MyEnvironment() # name the environment pizzashop.agent = tim # put the agent in the environment ccm.log_everything(pizzashop) # print out what happens in the environment pizzashop.run() # run the environment ccm.finished() # stop the environment
env.render() steps += 1 ############################################################## ###################### MAIN ############################## ############################################################## if __name__ == "__main__": logger = logging.getLogger() logger.setLevel(logging.INFO) # Set up agent envModel = ActrEnvModel() agent = ActrAgent() #ccm.log_everything(agent) #agent.focus.set('game:play') envModel.agent = ActrAgent() ccm.log_everything(envModel) # Run experiment, with monitor #outdir = '/tmp/random-agent-results' #env_thread = threading.Thread(target=gym_env, args=sys.argv) #env_thread.start() agent_thread = threading.Thread(target=envModel.run(), args=sys.argv) agent_thread.start()