From 27124f640cd8a8df934cc736216c7bda6a2e9f8c Mon Sep 17 00:00:00 2001 From: "Dobbertin, Niclas" Date: Fri, 10 May 2024 18:22:08 +0200 Subject: procedures progress --- modeling/prod_procedure.py | 111 +++++++++++++++++++++++++++++++++++++++++++ modeling/productions_math.py | 77 ++++++++++++++++++++++-------- 2 files changed, 168 insertions(+), 20 deletions(-) create mode 100644 modeling/prod_procedure.py (limited to 'modeling') diff --git a/modeling/prod_procedure.py b/modeling/prod_procedure.py new file mode 100644 index 0000000..9b1cbaf --- /dev/null +++ b/modeling/prod_procedure.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python3 + + +def procedures(Model): + prods = [] + + proc_start = Model.productionstring( + name="proc_start", + string=""" + =g> + isa math_goal + proc =proc + op None + nextop None + ?retrieval> + state free + ==> + +retrieval> + isa procedure + proc =proc + + """, + ) + prods.append(proc_start) + + proc_start_task1 = Model.productionstring( + name="proc_start_task1", + string=""" + =g> + isa math_goal + proc =proc + op None + nextop None + =retrieval> + isa procedure + proc =proc + result1 None + op1 =op + arg1_1 =arg1 + arg1_2 =arg2 + ==> + +g> + isa math_goal + proc =proc + task 1 + op =op + arg1 =arg1 + arg2 =arg2 + """, + ) + prods.append(proc_start_task1) + + proc_harvest_task1 = Model.productionstring( + name="proc_harvest_task1", + string=""" + =g> + isa math_goal + proc =proc + task 1 + op done + nextop None + =imaginal> + isa math_op + ?retrieval> + state free + ==> + +retrieval> + isa procedure + proc =proc + """, + ) + + proc_harvest_task1_done = Model.productionstring( + name="proc_harvest_task1_done", + string=""" + =g> + isa math_goal + proc =proc + task 1 + op done + nextop None + =imaginal> + isa math_op + result =result1 + =retrieval> + isa procedure + proc =proc + op1 =op1 + arg1_1 =arg1_1 + arg1_2 =arg1_2 + op2 =op2 + arg2_1 =arg2_1 + arg2_2 =arg2_2 + result2 =result2 + ==> + +g> + isa math_goal + proc =proc + +imaginal> + isa procedure + proc =proc + op1 =op1 + arg1_1 =arg1_1 + arg1_2 =arg1_2 + result1 =result1 + op2 =op2 + arg2_1 =arg2_1 + arg2_2 =arg2_2 + result2 =result2 + """, + ) diff --git a/modeling/productions_math.py b/modeling/productions_math.py index 635efff..9e0911a 100644 --- a/modeling/productions_math.py +++ b/modeling/productions_math.py @@ -4,6 +4,8 @@ import pyactr as actr import prod_addition import prod_comp import prod_multi +import prod_numbers +import prod_procedure # https://stackoverflow.com/a/39644726 @@ -19,7 +21,20 @@ def init(): imaginal = Model.set_goal(name="imaginal", delay=0.2) actr.chunktype("number", ("number", "next", "ones", "tens", "hundreds")) - actr.chunktype("procedure", ("proc", "op1", "arg1_1", "arg1_2")) + actr.chunktype( + "procedure", + ( + "proc", + "op1", + "arg1_1", + "arg1_2", + "result1", + "op2", + "arg2_1", + "arg2_2", + "result2", + ), + ) actr.chunktype( "math_goal", ( @@ -30,7 +45,6 @@ def init(): "arg2", "result", "expand_slot", - "contract_slot", "hundreds1", "tens1", "ones1", @@ -41,7 +55,8 @@ def init(): "tens_ans", "ones_ans", "mul_counter", - "carry", + "ones_carry", + "tens_carry", ), ) actr.chunktype( @@ -54,6 +69,21 @@ def init(): ), ) + # Add procedures + DM.add( + actr.makechunk( + "procedure1", + "procedure", + proc="proc1", + op1="add", + arg1_1=9, + arg1_2=2, + op2="greater", + arg2_1=100, + arg2_2=200, + ) + ) + # Add numbers 0-999 to decmem for i in range(0, 1000): DM.add( @@ -116,7 +146,7 @@ def add_goal(goal, op, arg1, arg2): # tens2=get_digit(arg2, 1), # hundreds2=get_digit(arg2, 2), # ) - #) + # ) def general_prod(Model): @@ -143,14 +173,21 @@ def wait_input(): arg2 = input("arg2\n") return op, int(arg1), int(arg2) +def add_proc(goal, proc): + input() + goal.add(actr.makechunk("", "math_goal", proc=proc, ones_carry="hello")) + def start(): while True: - op, arg1, arg2 = wait_input() + # op, arg1, arg2 = wait_input() Model, DM, goal, imaginal = init() - add_goal(goal, op, arg1, arg2) + # add_goal(goal, op, arg1, arg2) + add_proc(goal, "proc1") general_prod(Model) + prod_procedure.procedures(Model) + number_prods = prod_numbers.number(Model) add_prods = prod_addition.addition(Model) greater_prods = prod_comp.greater_than(Model) less_prods = prod_comp.less_than(Model) @@ -161,27 +198,27 @@ def start(): # print("\n") print("goal: ", goal) - print("imaginal: ", imaginal) + # print("imaginal: ", imaginal) x = Model.simulation() - x.run() + x.run(max_time=3) print("goal: ", goal) - print("imaginal: ", imaginal) + # print("imaginal: ", imaginal) # imaginal.show("hundreds_ans") # imaginal.show("tens_ans") # imaginal.show("ones_ans") - result_ones = str(getattr(imaginal._data.copy().pop(), "ones_ans")) - result_tens = str(getattr(imaginal._data.copy().pop(), "tens_ans")) - result_huns = str(getattr(imaginal._data.copy().pop(), "hundreds_ans")) + # result_ones = str(getattr(imaginal._data.copy().pop(), "ones_ans")) + # result_tens = str(getattr(imaginal._data.copy().pop(), "tens_ans")) + # result_huns = str(getattr(imaginal._data.copy().pop(), "hundreds_ans")) - result_num = result_huns + result_tens + result_ones - print(result_num) + # result_num = result_huns + result_tens + result_ones + # print(result_num) # print(list(DM)) - numbers = [ - x for x in list(DM) if x.typename != "number" and x.typename != "math_op" - ] - numbers = [ - x for x in list(DM) if x.typename != "number" and x.typename == "math_op" - ] + # numbers = [ + # x for x in list(DM) if x.typename != "number" and x.typename != "math_op" + # ] + # numbers = [ + # x for x in list(DM) if x.typename != "number" and x.typename == "math_op" + # ] # print(numbers) -- cgit v1.2.3