-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_chunk_utility.py
More file actions
180 lines (167 loc) · 7.16 KB
/
test_chunk_utility.py
File metadata and controls
180 lines (167 loc) · 7.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# test chunk utility
from CMCed.production_cycle import ProductionCycle
from CMCed.Cognitive_Functions import *
# Initialize memories
working_memory = {'focus_buffer': {'step': 1},
'target_buffer': {'name': 'fries',
'condition': 'good',
'side_order': 'yes',
'extra': 'yes'}}
# note, all chunks need to have a different name
# if two have the same name the second one will overwrite the first
declarative_memory = {'fries': {'name': 'fries',
'condition': 'good',
'side_order': 'yes',
'extra': 'yes',
'utility':7},
'house_salad': {'name': 'house_salad',
'condition': 'good',
'side_order': 'yes',
'utility':5},
'house_salad2': {'name': 'house_salad',
'condition': 'bad',
'side_order': 'yes',
'utility':5},
'poutine': {'name': 'poutine',
'condition': 'good',
'side_order': 'yes',
'utility':0},
'ceasar_salad': {'name': 'ceasar_salad',
'condition': 'bad',
'side_order': 'yes',
'utility':4}}
environment_memory = {}
memories = {
'working_memory': working_memory,
'declarative_memory': declarative_memory,
'environment_memory': environment_memory}
def do_steps(memories): # function for stepping through productions by counting
current_step = memories['working_memory']['focus_buffer']['step'] # Accessing 'step' within 'focus_buffer'
#print('The current step is', current_step)
# Increment the step
memories['working_memory']['focus_buffer']['step'] = current_step + 1
next_step = memories['working_memory']['focus_buffer']['step']
#print('Next step is', next_step)
# Initialize productions
ProceduralProductions = []
def p1(memories):
# boost a chunk you have described using utility_change_by_description
do_steps(memories)
print('house salad utility should be boosted to 7')
# describe the chunk you want boosted
chunk_description = {'name': 'house_salad', 'condition': 'good'}
print(chunk_description)
# boost utility
utility_change_by_description(memories, 'declarative_memory', chunk_description, amount=2, max_utility=10)
#report_memory_contents(declarative_memory)
ProceduralProductions.append({
'matches': {'working_memory': {'focus_buffer': {'step': 1}}},
'negations': {},
'utility': 10,
'action': p1,
'report': "step 1"
})
def p2(memories):
# boost a chunk with a description from a buffer using utility_change_by_description
do_steps(memories)
print('fries utility should be boosted to 9')
# Access the target buffer directly
chunk_description = memories['working_memory']['target_buffer']
# Print the chunk description for clarity
print("Extracted chunk description:", chunk_description)
# Boost utility
utility_change_by_description(memories, 'declarative_memory', chunk_description, amount=2, max_utility=10)
#report_memory_contents(declarative_memory)
ProceduralProductions.append({
'matches': {'working_memory': {'focus_buffer': {'step': 2}}},
'negations': {},
'utility': 10,
'action': p2,
'report': "step 2"
})
def p3(memories):
#boost a chunk by using its name using "utility_change" ****** different function for this shortcut
do_steps(memories)
print('poutine utility should be boosted to 2')
chunk_name = 'poutine' # Use the chunk name directly
print('poutine is the name of the chunk')
utility_change(memories, 'declarative_memory', chunk_name, amount=2, max_utility=10)
#report_memory_contents(declarative_memory)
ProceduralProductions.append({
'matches': {'working_memory': {'focus_buffer': {'step': 3}}},
'negations': {},
'utility': 10,
'action': p3,
'report': "step 3"
})
def p4(memories):
# use a partial match, this is important because it means you don't need to specify the utility slot
# you can also skip other slots
do_steps(memories)
print('house salad utility should be boosted to 9')
# describe the chunk you want boosted
# note that the description can be partial as long as it only matches one chunk
chunk_description = {'condition': 'good', 'name': 'house_salad'}
print(chunk_description)
# boost utility
utility_change_by_description(memories, 'declarative_memory', chunk_description, amount=2, max_utility=10)
#report_memory_contents(declarative_memory)
ProceduralProductions.append({
'matches': {'working_memory': {'focus_buffer': {'step': 4}}},
'negations': {},
'utility': 10,
'action': p4,
'report': "step 4"
})
def p5(memories):
# if two chunks match you will get an error message and nothing is boosted
do_steps(memories)
print('should be an error')
chunk_description = {'side_order': 'yes', 'name': 'house_salad'}
print(chunk_description)
# boost utility
utility_change_by_description(memories, 'declarative_memory', chunk_description, amount=2, max_utility=10)
#report_memory_contents(declarative_memory)Procedural
ProceduralProductions.append({
'matches': {'working_memory': {'focus_buffer': {'step': 5}}},
'negations': {},
'utility': 10,
'action': p5,
'report': "step 5"
})
# def p6(memories):
# do_steps(memories)
# # boost a chunk with a description from a buffer using utility_change_by_description
#
# # Step 1: Access the target buffer
# target_buffer = memories['working_memory']['target_buffer']
# # Step 2: Retrieve all the values from the dictionary
# chunk_values = list(target_buffer.values())
# # Step 3: Get the first (and only) chunk (index=0)
# chunk_description = chunk_values[0]
# # Print the result for clarity
# print("Extracted chunk description:", chunk_description)
# #boost utility
# utility_change_by_description(memories, 'declarative_memory', chunk_description, amount=2, max_utility=10)
# #report_memory_contents(declarative_memory)
# ProceduralProductions.append({
# 'matches': {'working_memory': {'focus_buffer': {'step': 6}}},
# 'negations': {},
# 'utility': 10,
# 'action': p6,
# 'report': "step 6"
# })
# Production system delays in ticks
ProductionSystem1_Countdown = 1
# Stores the number of cycles for a production system to fire and reset
DelayResetValues = {
'ProductionSystem1': ProductionSystem1_Countdown,
}
# Dictionary of all production systems and delays
AllProductionSystems = {
'ProductionSystem1': [ProceduralProductions, ProductionSystem1_Countdown],
}
# Initialize ProductionCycle
ps = ProductionCycle()
# Run the cycle with custom parameters
ps.run_cycles(memories, AllProductionSystems, DelayResetValues, cycles=7, millisecpercycle=50)