-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinitialization.lisp
334 lines (295 loc) · 12.4 KB
/
initialization.lisp
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
;---------------------------------------------
; INITIALIZATION: This file contains functions for initializing the program.
;---------------------------------------------
(in-package 'user)
(defun init-ccat (initial-string-input modified-string-input
target-string-input &key random-state no-graphics
&aux command quit)
; Initialize the random-number generator and make a copy of *random-state*
; that can be stored and used again to replay this run.
(if* (null random-state)
then (setq *random-state* (make-random-state t))
else (setq *random-state* (make-random-state random-state)))
(setq *random-state-this-run* (make-random-state *random-state*))
; Initialize some global variables.
(setq *workspace-initialized* nil) ; T if the workspace has been
; initialized.
(setq *coderack-initialized* nil) ; T if the coderack has been
; initialized.
(setq *slipnet-initialized* nil) ; T if the slipnet has been initialized.
(setq *rule* nil)
(setq *translated-rule* nil)
(setq *answer-string* nil)
(setq *quit-program* nil)
(setq *codelet-count* 0)
(setq *codelets-to-post* nil)
(setq *found-answer* nil)
(setq *temperature* 100)
(setq *snag-object* nil)
(setq *snag-condition* nil)
(setq *snag-count* 0)
(setq *length-description-count* 0)
(setq *length-relevant-at-end* nil)
(setq *single-letter-group-count* 0) ; For statistics purposes.
(setq *single-letter-group-at-end-count* 0)
(setq *clamp-temperature* nil)
(setq *description-graphics-obj-list* nil)
(setq *break-on-each-step* nil)
(setq *amount-length-changed* nil) ; involving group-length changes.
; Initialize the constants for the program.
(init-constants)
(if* %demo-graphics%
then (setq %coderack-graphics% nil)
(setq %minimal-coderack-graphics% t)
(setq %description-graphics% nil))
(if* no-graphics
then (setq %workspace-graphics% nil)
(setq %coderack-graphics% nil)
(setq %minimal-coderack-graphics% nil)
(setq %temperature-graphics% nil)
(setq %slipnet-graphics% nil)
(setq %description-graphics% nil))
(if* %workspace-graphics%
then (open-window %graphics-viewport-width%
%graphics-viewport-height%
%graphics-viewport-x%
%graphics-viewport-y%)
(clear-window)
(format t "~%Please initialize parameters.~&")
(loop until quit do
(init-init-time-menu)
(if* (eq (get-init-time-menu-command target-string-input) 'okay)
then (setq quit t)))
(format t "Parameters are initialized.~&")
(format t "Please wait...~&"))
(if* (and (not no-graphics) %demo-graphics%)
; This appears here too, in case %demo-graphics%
; was set to t when the parameters were set.
then (setq %coderack-graphics% nil)
(setq %minimal-coderack-graphics% t)
(setq %description-graphics% nil))
; Initialize the coderack, slipnet, and workspace.
(init-coderack)
(init-slipnet)
(init-workspace initial-string-input modified-string-input
target-string-input)
(if* %workspace-graphics% then (init-workspace-graphics))
; Clamp the activation of the slipnet nodes that are a priori relevant and
; thus should stay active for at least the initial part of the run.
(loop for node in *initially-clamped-slipnodes* do
(send node :set-clamp t))
; Add initial descriptions to all letters.
(add-descriptions)
(if* %workspace-graphics% then
(loop for obj in (append (send *initial-string* :object-list)
(send *modified-string* :object-list)
(send *target-string* :object-list)) do
(loop for d in (send obj :descriptions)
do (send obj :init-description-graphics d))))
; Post the initial codelets on the coderack.
(post-initial-codelets)
; Update the slipnet.
(update-slipnet)
(if* %description-graphics%
then (display-descriptions))
(if* %temperature-graphics%
then (display-temperature))
(if* %coderack-graphics%
then (init-coderack-graphics)
(display-coderack))
(if* %minimal-coderack-graphics%
then (init-minimal-coderack-display)
(display-minimal-coderack))
(if* %slipnet-graphics%
then (init-slipnet-graphics)
(display-slipnet))
(if* %workspace-graphics%
then (format t "Initialization is complete.~&")
(format t "Please select next action.~&")
(setq quit nil)
(loop until (or (eq command 'begin-run) (eq command 'quit-program)) do
(init-begin-run-time-menu)
(setq command
(get-begin-run-time-menu-command)))
(if* (eq command 'begin-run)
then (format t "Beginning run.~&")
else (format t "Quitting program.~&")))
; Begin the run.
(if* (not (eq command 'quit-program))
then (run-ccat)))
;---------------------------------------------
(defun init-workspace (initial-string-input modified-string-input
target-string-input
&aux i-length m-length t-length)
; Initializes the three strings -- that is, fills in *initial-string*,
; *modified-string*, and *target-string* structures with letters.
; Set up the input for the three strings.
(setq initial-string-input
(mapcar 'string (coerce (symbol-name initial-string-input) 'list)))
(setq modified-string-input
(mapcar 'string (coerce (symbol-name modified-string-input) 'list)))
(setq target-string-input
(mapcar 'string (coerce (symbol-name target-string-input) 'list)))
(setq i-length (length initial-string-input))
(setq m-length (length modified-string-input))
(setq t-length (length target-string-input))
; Initialize the workspace.
(setq *workspace*
(make-instance 'workspace
:proposed-correspondence-array
(make-array (list i-length t-length)
:initial-element nil :adjustable t)
:correspondence-vector
(make-vector i-length)))
; Initialize the three strings.
(setq *initial-string*
(make-instance 'workspace-string
:highest-string-number -1
:letter-vector (make-vector i-length)
:proposed-bond-array
(make-array (list i-length i-length)
:initial-element nil
:adjustable t)
:left-right-bond-array
(make-array (list i-length i-length)
:initial-element nil
:adjustable t)
:from-to-bond-array
(make-array (list i-length i-length)
:initial-element nil
:adjustable t)
:proposed-group-array
(make-array (list i-length i-length)
:initial-element nil
:adjustable t)
:group-vector (make-vector i-length)
:object-position-vector (make-vector i-length)
:length i-length
:object-spaces i-length
:num-of-bonds-to-scan-distribution
(loop for i from 0 to (- i-length 1) do
collect i)
:pname "initial string"))
(setq *modified-string*
(make-instance 'workspace-string
:highest-string-number -1
:letter-vector (make-vector m-length)
:object-position-vector (make-vector m-length)
:length m-length
:pname "modified string"))
(setq *target-string*
(make-instance 'workspace-string
:highest-string-number -1
:letter-vector (make-vector t-length)
:proposed-bond-array
(make-array (list t-length t-length)
:initial-element nil
:adjustable t)
:left-right-bond-array
(make-array (list t-length t-length)
:initial-element nil
:adjustable t)
:from-to-bond-array
(make-array (list t-length t-length)
:initial-element nil
:adjustable t)
:proposed-group-array
(make-array (list t-length t-length)
:initial-element nil
:adjustable t)
:group-vector (make-vector t-length)
:object-position-vector (make-vector t-length)
:length t-length
:object-spaces t-length
:num-of-bonds-to-scan-distribution
(loop for i from 0 to (- t-length 1) do
collect i)
:pname "target string"))
(setq *answer-string* nil)
; Nicknames.
(setq *i* *initial-string*)
(setq *m* *modified-string*)
(setq *t* *target-string*)
(setq *a* *answer-string*)
; Initialize the letters in the three strings.
(make-letters initial-string-input *initial-string*)
(make-letters modified-string-input *modified-string*)
(make-letters target-string-input *target-string*)
(send *initial-string*
:set-letter-list (vector-to-list (send *initial-string*
:letter-vector)))
(send *modified-string*
:set-letter-list (vector-to-list (send *modified-string*
:letter-vector)))
(send *target-string*
:set-letter-list (vector-to-list (send *target-string*
:letter-vector)))
(setq *rule* nil)
(setq *translated-rule* nil)
; If one of the strings has only one letter, then activate
; plato-object-category so that "letter" will be relevant.
(if* (or (= (send *initial-string* :length) 1)
(= (send *target-string* :length) 1))
then (send plato-object-category :activate-from-workspace))
(setq *workspace-initialized* t))
;---------------------------------------------
(defun make-letters (input-letter-list string
&aux current-letter letter-category)
; Set up letter instance for each input letter.
(loop for letter-name in input-letter-list
count t into letter-count do
; Set up an instance of the letter on the workspace.
(setq letter-category (get-plato-letter letter-name))
(setq current-letter
(make-letter string letter-category
(1- letter-count)))
(send string :add-letter current-letter)))
;---------------------------------------------
(defun add-descriptions (&aux leftmost-letter middle-letter rightmost-letter)
; Adds initial descriptions to the letters in the three strings.
(loop for string
in (list *initial-string* *modified-string* *target-string*) do
(loop for letter in (send string :letter-list) do
; Add object-category description.
(send letter :add-description
(make-description letter plato-object-category
plato-letter))
; Add letter-category description
(send letter :add-description
(make-description
letter plato-letter-category
(get-plato-letter
(string-upcase (send letter :pname))))))
; Now add string-position-category descriptions to the rightmost and
; leftmost letters, and to middle letter, if there is one.
(setq leftmost-letter (send string :get-letter 0))
(if* (> (send string :length) 1) ; If there is only one letter in the
; string, it isn't described as
; either "leftmost" or "rightmost".
then (setq rightmost-letter
(send string :get-letter (1- (send string :length))))
(send leftmost-letter :add-description
(make-description leftmost-letter
plato-string-position-category
plato-leftmost))
(send rightmost-letter :add-description
(make-description rightmost-letter
plato-string-position-category
plato-rightmost))
else
(send leftmost-letter :add-description
(make-description leftmost-letter
plato-string-position-category
plato-single)))
(if* (= (send string :length) 3)
then (setq middle-letter (send string :get-letter 1))
(send middle-letter :add-description
(make-description middle-letter
plato-string-position-category
plato-middle))))
; Activate the nodes in the descriptions of the letters.
(loop for object in (send *workspace* :object-list) do
(send-method-to-list
(send-method-to-list (send object :descriptions) :descriptor)
:activate-from-workspace)))
;---------------------------------------------