;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; VARIABLES DECLARATION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Criterias and help variables
(defvar *help* "no-help")
(defvar *initiation* 0)
(defvar *organization* 0)
(defvar *all-steps* 0)
(defvar *sequencing* 0)
(defvar *judgment-safety* 0)
(defvar *completion* 0)
;; For each criteria, we sum the total of verbal, physical and not capable cues used  
(defvar *initiation100*)
(defvar *organization100*)
(defvar *all-steps100*)
(defvar *sequencing100*)
(defvar *judgment-safety100*)
(defvar *completion100*)
(defvar *score-total-100*)
(defvar *results-list*)
(defvar *standard-deviation*)

(defvar *time-var* 0)
;; variables used in the fourth stage
(defvar *current-dish*)
(defvar *second-help* "no-help")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PARAMETERS DECLARATION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar *ga_param*) ;parameter for the differents stages of Alzheimer disease
(defvar *mp_param*) ;parameter for commission errors
(defvar *rt_param*) ;retrieval treshold: parameter for omission errors
(defvar *sucesses_param*)
(defvar *failures_param*)

(defvar *mp_param_cst_0* 2.0)
(defvar *mp_param_cst_0.5* 3.97)
(defvar *mp_param_cst_1* 4.15)
(defvar *mp_param_cst_2* 4.25)
(defvar *mp_param_cst_3* 4.45)
(defvar *mp_param_cst*)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; MAIN FUNCTIONS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Main function that execute the KTA for one patient
(defun kta (CDR)
  	(kta-exe CDR)
	(open-exp-window "KTA Results" :visible t :width 250 :height 250)
	(print_score CDR)
)

;; Main function that execute the KTA for one hundred patients
(defun kta100 (CDR)
  	(reset_variables100)
  	(dotimes (i 100)	 
  		(kta-exe CDR)
		(record_results)
  	)
	(setq *score-total-100* (float (/ *score-total-100* 100)))
	(standard_deviation_calcul)
	(open-exp-window "KTA Results" :visible t :width 400 :height 500)
  	(print_score_percentage CDR)
)

(defun kta-exe (CDR)
	(reset)
  	(reset_variables)
	(fit_parameters CDR)
	(print "**** Stage 0 : Task initiation ****")
  	(pm-run 30.0)	
	(print "**** End of the task****")
	(reset)
	(delete_created_chunks)
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PARAMETERS FITTING
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun fit_parameters (cdr)
	(cond   ((equal cdr "CDR-0") 
			(setf *ga_param* 1.0)
			(setf *mp_param_cst* *mp_param_cst_0*)
			(setf *sucesses_param* 100)
			(setf *failures_param* 0)
	       	)
		((equal cdr "CDR-0.5") 
			(setf *ga_param* 0.74)
			(setf *mp_param_cst* *mp_param_cst_0.5*)
			(setf *sucesses_param* 59)
			(setf *failures_param* 41)
	       	)
		((equal cdr "CDR-1") 
			(setf *ga_param* 0.68)
			(setf *mp_param_cst* *mp_param_cst_1*)
			(setf *sucesses_param* 53)
			(setf *failures_param* 47)
	       	)
		((equal cdr "CDR-2") 
			(setf *ga_param* 0.61)
			(setf *mp_param_cst* *mp_param_cst_2*)
			(setf *sucesses_param* 46.5)
			(setf *failures_param* 53.5)
	       	)
		((equal cdr "CDR-3") 
			(setf *ga_param* 0.60)
			(setf *mp_param_cst* *mp_param_cst_3*)
			(setf *sucesses_param* 41)
			(setf *failures_param* 59)
	       	)
	)
	(sgp-fct (list :ga *ga_param* :mp *mp_param_cst*))
	(spp-fct (list '0_INITIATION :failures *failures_param* :successes *sucesses_param*))
	(spp-fct (list '0_WAITING_TO_START :failures *sucesses_param* :successes *failures_param*))
	(spp-fct (list 'TRANSITION_0_1 :failures *failures_param* :successes *sucesses_param*))
	(spp-fct (list 'TRANSITION_0_1_ERROR1 :failures *sucesses_param* :successes *failures_param*))
	(spp-fct (list 'TRANSITION_1_2 :failures *failures_param* :successes *sucesses_param*))
	(spp-fct (list 'TRANSITION_1_2_ERROR1 :failures *sucesses_param* :successes *failures_param*))
	(spp-fct (list '2_STIR :failures *failures_param* :successes *sucesses_param*))
	(spp-fct (list '2_WAITING_WITHOUT_STIRING :failures *sucesses_param* :successes *failures_param*))		
	(spp-fct (list 'TRANSITION_2_3 :failures *failures_param* :successes *sucesses_param*))
	(spp-fct (list 'TRANSITION_2_3_BIS :failures *failures_param* :successes *sucesses_param*))
	(spp-fct (list 'TRANSITION_2_3_ERROR1 :failures *sucesses_param* :successes *failures_param*))		
	(spp-fct (list 'TRANSITION_2_3_ERROR1_BIS :failures *sucesses_param* :successes *failures_param*))
	(spp-fct (list '3_LIGHT_STOVE :failures *failures_param* :successes *sucesses_param*))
	(spp-fct (list '3_WAITING_WITHOUT_LIGHTING_STOVE :failures *sucesses_param* :successes *failures_param*))				
	(spp-fct (list '3_TURN_OFF_STOVE :failures *failures_param* :successes *sucesses_param*))
	(spp-fct (list '3_COMPLETE_COOK_STAGE :failures *sucesses_param* :successes *failures_param*))		
	(spp-fct (list '3_STOP_WAITING_AND_STIRING :failures *failures_param* :successes *sucesses_param*))
	(spp-fct (list '3_WAIT_AND_STIR :failures *sucesses_param* :successes *failures_param*))		
	(spp-fct (list 'TRANSITION_3_4 :failures *failures_param* :successes *sucesses_param*))
	(spp-fct (list 'TRANSITION_3_4_ERROR1 :failures *sucesses_param* :successes *failures_param*))	
	(spp-fct (list 'TRANSITION_4_5 :failures *failures_param* :successes *sucesses_param*))
	(spp-fct (list 'TRANSITION_4_5_ERROR1 :failures *sucesses_param* :successes *failures_param*))			
	(spp-fct (list '4_STOP_SCRAPPING_SAUCEPAN :failures *failures_param* :successes *sucesses_param*))
	(spp-fct (list '4_SCRAP_SAUCEPAN :failures *sucesses_param* :successes *failures_param*))
	(spp-fct (list '4_POUR :failures *failures_param* :successes *sucesses_param*))
	(spp-fct (list '4_BAD_POUR :failures *sucesses_param* :successes (/ *failures_param* 2)))
	(spp-fct (list '4_WAITING_WITHOUT_POURING :failures *sucesses_param* :successes (/ *failures_param* 2)))	


)

(defun stage_parameters_fitting (stage)
	(cond	
		; Stage 1: goal has 2 parameters   
		((= stage 1) 
		(setf *rt_param* 0.411)
		(setf *mp_param* (/ *mp_param_cst* 2))
		(Delete-Chunk-fct (no-output (SDM isa Initiate)))
		(Reset-IA)
		(Update-activation)
		)
		; Stage 2: goal has 4 parameters
		((= stage 2)
		(setf *rt_param* 0.084)
		(setf *mp_param* (/ *mp_param_cst* 6))
		(Delete-Chunk-fct (no-output (SDM isa Measure)))
		(Reset-IA)
		(Update-activation)
		)
		; Intermediate Stage: goal has 1 parameter
		((= stage 2.5)
		(setf *rt_param* 1.064)
		(setf *mp_param* *mp_param_cst*)
		(Delete-Chunk-fct (no-output (SDM isa Stir)))
		(Reset-IA)
		(Update-activation)
		)
		; Stage 3: goal has 3 parameters
		((= stage 3)
		(setf *rt_param* 0.193)
		(setf *mp_param* (/ *mp_param_cst* 4))
		(Delete-Chunk-fct (no-output (SDM isa Stir)))
		(Delete-Chunk-fct (no-output (SDM isa Transvase)))
		(Reset-IA)
		(Update-activation)
		)
		; Stage 4: goal has 6 parameters (to do)
		((= stage 4)
		(setf *rt_param* -0.025)
		(setf *mp_param* (/ *mp_param_cst* 10))
		(Delete-Chunk-fct (no-output (SDM isa Cook)))
		(Reset-IA)
		(Update-activation)
		)
		; Stage 5: goal has 1 parameter (to do)
		((= stage 5)
		(setf *rt_param* 1.091)
		(setf *mp_param* *mp_param_cst*)
		(Delete-Chunk-fct (no-output (SDM isa Pour)))
		(Reset-IA)
		(Update-activation)
		)
	)
	(sgp-fct (list :rt *rt_param* :mp *mp_param*))
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; RESET FUNCTIONS that we have to do before each kta simulation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun reset_variables ()
	(Reset_help)
	(setf *initiation* 0)
	(setf *organization* 0)
	(setf *all-steps* 0)
	(setf *sequencing* 0)
	(setf *judgment-safety* 0)
	(setf *completion* 0)
)

(defun reset_variables100 ()
	(setq *score-total-100* 0)
	(setq *standard-deviation* 0)
	(setq *initiation100* (list '0 '0 '0 '0 ))
	(setq *organization100* (list '0 '0 '0 '0))
	(setq *all-steps100* (list '0 '0 '0 '0))
	(setq *sequencing100* (list '0 '0 '0 '0))
	(setq *judgment-safety100* (list '0 '0 '0 '0))
	(setq *completion100* (list '0 '0 '0 '0))
	(setq *results-list* nil)
)

(defun Reset_help ()
	(setf *help* "no-help")
)

(defun delete_created_chunks ()
	(Delete-chunk measured-milk)
	(Delete-chunk the-measured-milk)
	(Delete-chunk milk+pudding-mix)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; HELP MODELISATION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun Utility_verbal_help (criteria_name production_name)
	(evaluate_criteria_score criteria_name 1)
	(setf *help* "verbal")
	(evaluate_utility production_name)
)

;; used when there is a conflict situation between 3 productions 
(defun Utility_verbal_help_second (criteria_name production_name)
	(evaluate_criteria_score criteria_name 1)
	(setf *second-help* "verbal")
	(evaluate_utility production_name)
)

(defun Utility_physical_help (criteria_name production_name)
	(evaluate_criteria_score criteria_name 2)
	(setf *help* "physical")
	(evaluate_utility production_name)
)

;; used when there is a conflict situation between 3 productions 
(defun Utility_physical_help_second (criteria_name production_name)
	(evaluate_criteria_score criteria_name 2)
	(setf *second-help* "physical")
	(evaluate_utility production_name)
)

(defun Activation_verbal_help (criteria_name)
	(evaluate_criteria_score criteria_name 1)
	(setf *help* "verbal")
)

(defun Activation_physical_help (criteria_name chunk_name)
	(evaluate_criteria_score criteria_name 2)
	(setf *help* "physical")
	(evaluate_base_level_physical chunk_name)
)

(defun Not_capable_help (criteria_name)
	(evaluate_criteria_score criteria_name 3)
	(setf *help* "no-help")
	(setf *second-help* "no-help")
)

(defun evaluate_criteria_score (criteria_name h)
	(cond   ((equal criteria_name "initiation") 
		(if (< *initiation* h) (setf *initiation* h))
	       	)
		((equal criteria_name "organization") 
		(if (< *organization* h) (setf *organization* h))
	       	)
	      	((equal criteria_name "all-steps") 
		(if (< *all-steps* h) (setf *all-steps* h))
	       	)
		((equal criteria_name "sequencing") 
		(if (< *sequencing* h) (setf *sequencing* h))
	       	)
		((equal criteria_name "judgment-safety") 
		(if (< *judgment-safety* h) (setf *judgment-safety* h))
	       	)
		((equal criteria_name "completion") 
		(if (< *completion* h) (setf *completion* h))
	       	)
	) 
)

;; Increases manually the sucesses of the production in order to modelise help given by
;; the test supervisor
;; Is used for verbal and physical help (when the test supervisor give verbal or physic cue to the patient)
(defun evaluate_utility (production_name)
	(cond   ((equal production_name "0_INITIATION") 
		(spp-fct (list '0_INITIATION :successes (+ 10 (first (first (first (no-output (spp (0_INITIATION) :successes))))))))
		)
		((equal production_name "TRANSITION_0_1") 
		(spp-fct (list 'TRANSITION_0_1 :successes (+ 10 (first (first (first (no-output (spp (TRANSITION_0_1) :successes))))))))
		)
		((equal production_name "TRANSITION_1_2") 
		(spp-fct (list 'TRANSITION_1_2 :successes (+ 10 (first (first (first (no-output (spp (TRANSITION_1_2) :successes))))))))
		)
		((equal production_name "2_STIR") 
		(spp-fct (list '2_STIR :successes (+ 10 (first (first (first (no-output (spp (2_STIR) :successes))))))))
		)
		((equal production_name "TRANSITION_2_3") 
		(spp-fct (list 'TRANSITION_2_3 :successes (+ 10 (first (first (first (no-output (spp (TRANSITION_2_3) :successes))))))))
		)
		((equal production_name "TRANSITION_2_3_BIS") 
		(spp-fct (list 'TRANSITION_2_3_BIS :successes (+ 10 (first (first (first (no-output (spp (TRANSITION_2_3_BIS) :successes))))))))
		)
		((equal production_name "3_LIGHT_STOVE") 
		(spp-fct (list '3_LIGHT_STOVE :successes (+ 10 (first (first (first (no-output (spp (3_LIGHT_STOVE) :successes))))))))
		)
		((equal production_name "3_TURN_OFF_STOVE") 
		(spp-fct (list '3_TURN_OFF_STOVE :successes (+ 10 (first (first (first (no-output (spp (3_TURN_OFF_STOVE) :successes))))))))
		)
		((equal production_name "3_STOP_WAITING_AND_STIRING") 
		(spp-fct (list '3_STOP_WAITING_AND_STIRING :successes (+ 10 (first (first (first (no-output (spp (3_STOP_WAITING_AND_STIRING) :successes))))))))
		)
		((equal production_name "TRANSITION_3_4") 
		(spp-fct (list 'TRANSITION_3_4 :successes (+ 10 (first (first (first (no-output (spp (TRANSITION_3_4) :successes))))))))
		)
		((equal production_name "TRANSITION_4_5") 
		(spp-fct (list 'TRANSITION_4_5 :successes (+ 10 (first (first (first (no-output (spp (TRANSITION_4_5) :successes))))))))
		)
		((equal production_name "4_STOP_SCRAPPING_SAUCEPAN") 
		(spp-fct (list '4_STOP_SCRAPPING_SAUCEPAN :successes (+ 10 (first (first (first (no-output (spp (4_STOP_SCRAPPING_SAUCEPAN) :successes))))))))
		)
		((equal production_name "4_POUR") 
		(spp-fct (list '4_POUR :successes (+ 10 (first (first (first (no-output (spp (4_POUR) :successes))))))))
		)
	)
)


;; Increases manually the base level of a specific chunk
;; Is used for physical help (when the test supervisor give physic cue to the patient)
(defun evaluate_base_level_physical (chunk_name)
	(cond   ((equal chunk_name "milk") 
		(set-base-levels-fct (list (list 'milk (+ (first (no-output (get-base-level milk))) .025))))
	 	)
		((equal chunk_name "measuring-cup") 
		(set-base-levels-fct (list (list 'measuring-cup (+ (first (no-output (get-base-level measuring-cup))) .025))))
	 	)	
		((equal chunk_name "saucepan") 
		(set-base-levels-fct (list (list 'saucepan (+ (first (no-output (get-base-level saucepan))) .025))))
	 	)
		((equal chunk_name "measured-milk") 
		(set-base-levels-fct (list (list 'measured-milk (+ (first (no-output (get-base-level measured-milk))) .025))))
	 	)
		((equal chunk_name "pudding-mix") 
		(set-base-levels-fct (list (list 'pudding-mix (+ (first (no-output (get-base-level pudding-mix))) .025))))
	 	)
		((equal chunk_name "wooden-spoon") 
		(set-base-levels-fct (list (list 'wooden-spoon (+ (first (no-output (get-base-level wooden-spoon))) .025))))
	 	)
		((equal chunk_name "milk+pudding-mix") 
		(set-base-levels-fct (list (list 'milk+pudding-mix (+ (first (no-output (get-base-level milk+pudding-mix))) .025))))
	 	)
		((equal chunk_name "rubber-scraper") 
		(set-base-levels-fct (list (list 'rubber-scraper (+ (first (no-output (get-base-level rubber-scraper))) .025))))
	 	)
		((equal chunk_name "Dish") 
		(update_dishes_activation)
	 	)
	)	
)

; Find the first empty dish and rehearse its activation level base
(defun update_dishes_activation ()
	(cond 	((equal (chunk-slot-value dish1 state) "empty")
	    	(setf *current-dish* (chunk-slot-value dish1 other))
	    	(set-base-levels-fct (list (list 'dish1 (+ (first (no-output (get-base-level dish1))) .025))))
	       	)
	       	((equal (chunk-slot-value dish2 state) "empty")
	    	(setf *current-dish* (chunk-slot-value dish2 other))
	    	(set-base-levels-fct (list (list 'dish2 (+ (first (no-output (get-base-level dish2))) .025))))
	   	)
		((equal (chunk-slot-value dish3 state) "empty")
	    	(setf *current-dish* (chunk-slot-value dish3 other))
	    	(set-base-levels-fct (list (list 'dish3 (+ (first (no-output (get-base-level dish3))) .025))))
	   	)
		((equal (chunk-slot-value dish4 state) "empty")
	    	(setf *current-dish* (chunk-slot-value dish4 other))
	    	(set-base-levels-fct (list (list 'dish4 (+ (first (no-output (get-base-level dish4))) .025))))
	   	)
	)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; OTHERS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Mofify the state of a dish to "full"
(defun set_dish_state (chunk_name)
	(cond   ((equal chunk_name "1") 
		(mod-chunk dish1 state "full")
	 	)
	 	((equal chunk_name "2") 
		(mod-chunk dish2 state "full")
	 	)
		((equal chunk_name "3") 
		(mod-chunk dish3 state "full")
	 	)
		 ((equal chunk_name "4") 
		(mod-chunk dish4 state "full")
	 	)
	)
)

;; keep in memory the time when the subject was ready to stir.
;; It will be needed to evaluate if subject needs help or not
(defun set_var_time (time)
	(setf *time-var* time)
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; STATISTICS AND OUTPUT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun record_results ()
(setq *score-total-100* (+ *score-total-100* *initiation* *organization* *all-steps* *sequencing* *judgment-safety* *completion*))

(setq *results-list* (append (list (+ *initiation* *organization* *all-steps* *sequencing* *judgment-safety* *completion*)) *results-list*))

(if (= 0 *initiation*) (setq *initiation100* (list (+ 1 (first *initiation100*)) (second *initiation100*) (third *initiation100*) (nth 3 *initiation100*) )))
(if (= 1 *initiation*) (setq *initiation100* (list (first *initiation100*) (+ 1 (second *initiation100*)) (third *initiation100*) (nth 3 *initiation100*) )))
(if (= 2 *initiation*) (setq *initiation100* (list (first *initiation100*) (second *initiation100*) (+ 1 (third *initiation100*)) (nth 3 *initiation100*) )))
(if (= 3 *initiation*) (setq *initiation100* (list (first *initiation100*) (second *initiation100*) (third *initiation100*) (+ 1 (nth 3 *initiation100*)) )))
(if (= 0 *organization*) (setq *organization100* (list (+ 1 (first *organization100*)) (second *organization100*) (third *organization100*) (nth 3 *organization100*) )))
(if (= 1 *organization*) (setq *organization100* (list (first *organization100*) (+ 1 (second *organization100*)) (third *organization100*) (nth 3 *organization100*) )))
(if (= 2 *organization*) (setq *organization100* (list (first *organization100*) (second *organization100*) (+ 1 (third *organization100*)) (nth 3 *organization100*) )))
(if (= 3 *organization*) (setq *organization100* (list (first *organization100*) (second *organization100*) (third *organization100*) (+ 1 (nth 3 *organization100*)) )))
(if (= 0 *all-steps*) (setq *all-steps100* (list (+ 1 (first *all-steps100*)) (second *all-steps100*) (third *all-steps100*) (nth 3 *all-steps100*) )))
(if (= 1 *all-steps*) (setq *all-steps100* (list (first *all-steps100*) (+ 1 (second *all-steps100*)) (third *all-steps100*) (nth 3 *all-steps100*) )))
(if (= 2 *all-steps*) (setq *all-steps100* (list (first *all-steps100*) (second *all-steps100*) (+ 1 (third *all-steps100*)) (nth 3 *all-steps100*) )))
(if (= 3 *all-steps*) (setq *all-steps100* (list (first *all-steps100*) (second *all-steps100*) (third *all-steps100*) (+ 1 (nth 3 *all-steps100*)) )))
(if (= 0 *sequencing*) (setq *sequencing100* (list (+ 1 (first *sequencing100*)) (second *sequencing100*) (third *sequencing100*) (nth 3 *sequencing100*) )))
(if (= 1 *sequencing*) (setq *sequencing100* (list (first *sequencing100*) (+ 1 (second *sequencing100*)) (third *sequencing100*) (nth 3 *sequencing100*) )))
(if (= 2 *sequencing*) (setq *sequencing100* (list (first *sequencing100*) (second *sequencing100*) (+ 1 (third *sequencing100*)) (nth 3 *sequencing100*) )))
(if (= 3 *sequencing*) (setq *sequencing100* (list (first *sequencing100*) (second *sequencing100*) (third *sequencing100*) (+ 1 (nth 3 *sequencing100*)) )))
(if (= 0 *judgment-safety*) (setq *judgment-safety100* (list (+ 1 (first *judgment-safety100*)) (second *judgment-safety100*) (third *judgment-safety100*) (nth 3 *judgment-safety100*) )))
(if (= 1 *judgment-safety*) (setq *judgment-safety100* (list (first *judgment-safety100*) (+ 1 (second *judgment-safety100*)) (third *judgment-safety100*) (nth 3 *judgment-safety100*) )))
(if (= 2 *judgment-safety*) (setq *judgment-safety100* (list (first *judgment-safety100*) (second *judgment-safety100*) (+ 1 (third *judgment-safety100*))(nth 3 *judgment-safety100*) )))
(if (= 3 *judgment-safety*) (setq *judgment-safety100* (list (first *judgment-safety100*) (second *judgment-safety100*) (third *judgment-safety100*) (+ 1 (nth 3 *judgment-safety100*)) )))
(if (= 0 *completion*) (setq *completion100* (list (+ 1 (first *completion100*)) (second *completion100*) (third *completion100*) (nth 3 *completion100*) )))
(if (= 1 *completion*) (setq *completion100* (list (first *completion100*) (+ 1 (second *completion100*)) (third *completion100*) (nth 3 *completion100*) )))
(if (= 2 *completion*) (setq *completion100* (list (first *completion100*) (second *completion100*) (+ 1 (third *completion100*)) (nth 3 *completion100*) )))
(if (= 3 *completion*) (setq *completion100* (list (first *completion100*) (second *completion100*) (third *completion100*) (+ 1 (nth 3 *completion100*)) )))
)

(defun standard_deviation_calcul()

 		(dotimes (i 100)	 
  			(setq *standard-deviation* (+ *standard-deviation* (* (- (nth i *results-list*) *score-total-100*) (- (nth i *results-list*) *score-total-100*))))
  		)
		(setq *standard-deviation* (float (/ *standard-deviation* 100)))
 		(setq *standard-deviation* (sqrt *standard-deviation*))
	
)

(defun print_score (CDR)
	(Add-text-to-exp-window :text (format nil "***** KTA results (~s) *****" CDR) :x 40 :y 20)
	(Add-text-to-exp-window :text (format nil "initiation      : ~s" *initiation*) :x 20 :y 60)
	(Add-text-to-exp-window :text (format nil "organization    : ~s" *organization*) :x 20 :y 80)
	(Add-text-to-exp-window :text (format nil "all-steps       : ~s" *all-steps*) :x 20 :y 100)
	(Add-text-to-exp-window :text (format nil "sequencing      : ~s" *sequencing*) :x 20 :y 120)
	(Add-text-to-exp-window :text (format nil "judgment-safety : ~s" *judgment-safety*) :x 20 :y 140)
	(Add-text-to-exp-window :text (format nil "completion      : ~s" *completion*) :x 20 :y 160)
	(Add-text-to-exp-window :text (format nil "Score = ~s" (+ *initiation* *organization* *all-steps* *sequencing* *judgment-safety* *completion*)) :x 20 :y 210)
)

(defun print_score_criteria (list coord-y)
	(Add-text-to-exp-window :text (format nil " ~s" (first list)) :x 150 :y coord-y)
	(Add-text-to-exp-window :text (format nil " ~s" (second list)) :x 210 :y coord-y)
	(Add-text-to-exp-window :text (format nil " ~s" (third list)) :x 270 :y coord-y)
	(Add-text-to-exp-window :text (format nil " ~s" (nth 3 list)) :x 330 :y coord-y)
)

(defun print_score_percentage (CDR)
	(Add-text-to-exp-window :text (format nil "***** KTA results for 100 subjects (~s) *****" CDR) :x 40 :y 20)
	(Add-text-to-exp-window :text (format nil "criterion            indep.   verb.   phy.    inc.") :x 20 :y 60)
	(Add-text-to-exp-window :text "initiation      : " :x 20 :y 80)
	(print_score_criteria *initiation100* 80)
	(Add-text-to-exp-window :text  "organization    : " :x 20 :y 100)
	(print_score_criteria *organization100* 100)
	(Add-text-to-exp-window :text  "all-steps       : " :x 20 :y 120)
	(print_score_criteria *all-steps100* 120)
	(Add-text-to-exp-window :text  "sequencing      : " :x 20 :y 140)
	(print_score_criteria *sequencing100* 140)
	(Add-text-to-exp-window :text  "judgment-safety :" :x 20 :y 160)
	(print_score_criteria *judgment-safety100* 160)
	(Add-text-to-exp-window :text  "completion      : " :x 20 :y 180) 
	(print_score_criteria *completion100* 180)
	(Add-text-to-exp-window :text  "*****************" :x 20 :y 210)
	(Add-text-to-exp-window :text  (format nil "Mean score = ~s" *score-total-100*) :x 20 :y 240)
	(Add-text-to-exp-window :text  (format nil "Standard deviation = ~s" *standard-deviation*) :x 20 :y 270)
)

(clear-all)
(pm-reset)
; Global Parameters
(sgp :esc t :pm t :pl t
     :bll nil :mas 2.0 :ans 0.03 :ol t ;parameters for chunk activation
     :egs 1.5 :ut -100.0 ;parameters for conflicts resolution
     :act nil :dmt nil :pmt nil :v t :ct nil)(chunk-type Ingredient 
	name
	type 
	place 
	container)
(chunk-type Ustensile 
	name
	place 
	function 
	state 
	clean-state
	other)

(chunk-type Initiate state)
(chunk-type Measure ingredient ustensile state)
(chunk-type Stir container ingredient1 ingredient2 ustensile state)
(chunk-type Cook ingredient container ustensile state stove-state)
(chunk-type Transvase new-container state)
(chunk-type Pour state container first-dish second-dish third-dish fourth-dish current-dish ustensile dishes-state)
(chunk-type Clean state previous-stage)

; goals "impasses", created all along the process (correspond to sequencing errors)
(chunk-type Light-Stove state previous-goal)
(chunk-type Pour-Cold-Mix state transition)
(chunk-type Task-Completed state previous-stage);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  DECLARATIVE MEMORY
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-dm
;; Ingredients
(milk isa Ingredient name the-milk)
(pudding-mix isa Ingredient name the-pudding-mix)
;; Ustensiles
(wooden-spoon isa Ustensile name the-wooden-spoon clean-state "clean")
(rubber-scraper isa Ustensile name the-rubber-scraper clean-state "clean")
(measuring-cup isa Ustensile name the-measuring-cup state "empty" clean-state "clean")
(saucepan isa Ustensile name the-saucepan state "empty" clean-state "clean")
(dish1 isa Ustensile name the-dish1 function "dish" state "empty" clean-state "clean" other "1")
(dish2 isa Ustensile name the-dish2 function "dish" state "empty" clean-state "clean" other "2")
(dish3 isa Ustensile name the-dish3 function "dish" state "empty" clean-state "clean" other "3")
(dish4 isa Ustensile name the-dish4 function "dish" state "empty" clean-state "clean" other "4")

;; initial goal
(initiate isa Initiate state "ready-to-proceed")

)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Stage 0 : Initiation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(P 0_INITIATION
	=goal>
		ISA Initiate
		state "ready-to-proceed"
==>
	!eval! (Reset_help)
	=goal>
		state "complete"
	!output! ("The subject has begun the task")
				
)

(P 0_WAITING_TO_START
	=goal>
		ISA Initiate
		state "ready-to-proceed"
==>
	=goal>
		state "ready-to-proceed"
	!output! ("..............")
)

(P 0_INITIATION_VERBAL_HELP
	=goal>
		ISA Initiate
		state "ready-to-proceed"
	!eval! (equal *help* "no-help")
	!eval!  (> (pm-get-time) 50)
==>
	!eval! (Utility_verbal_help "initiation" "0_INITIATION")
	!output! ("The subject does not begin the task: Initiation problem --> VERBAL HELP")
)

(P 0_INITIATION_PHYSICAL_HELP
	=goal>
		ISA Initiate
		state "ready-to-proceed"
	!eval! (equal *help* "verbal")
	!eval!  (> (pm-get-time) 150)
==>
	!eval! (Utility_physical_help "initiation" "0_INITIATION")
	!output! ("The subject does not begin the task: Initiation problem--> PHYSICAL HELP")

)

(P 0_INITIATION_NOT_CAPABLE
	=goal>
		ISA Initiate
		state "ready-to-proceed"
	!eval! (equal *help* "physical")
	!eval!  (> (pm-get-time) 250)
==>
	!eval! (Not_capable_help "initiation")
	=goal>
		state "complete"
	!output! ("The subject is unable to begin the task: Initiation problem--> UNABLE")
	!output! ("Le supervisor tells him to begin")
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Transition from stage 0 to stage 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(P TRANSITION_0_1
	=goal>
		ISA Initiate
		state "complete"
==>
	=measure>
		ISA Measure
		ingredient milk 
		ustensile measuring-cup 
		state "ready-to-proceed"
	!push! =measure
	!eval! (stage_parameters_fitting 1)
)

(P TRANSITION_0_1_ERROR1
	=goal>
		ISA Initiate
		state "complete"
==>
	=light-stove>
		ISA Light-Stove
		state "ready-to-proceed"
		previous-goal "initiate"
	!push! =light-stove
	!output! ("~&**** Erroneous stage: Turn on the stove ****")
)

(P TRANSITION01_ERROR_LIGHT_STOVE	
	=goal>
		ISA Light-Stove
		state "ready-to-proceed"
		previous-goal "initiate"
==>
	=goal>
		state "turn-on"
	!output! ("The subject wants to turn on the stove")
)

(P TRANSITION01_ERROR_LIGHT_STOVE_VH	
	=goal>
		ISA Light-Stove
		state "turn-on"
		previous-goal "initiate"
	!eval! (equal *help* "no-help")	
==>
	!eval! (Utility_verbal_help "sequencing" "TRANSITION_0_1")
	!output! ("Sequencing error--> VERBAL HELP")
	!pop!
)

(P TRANSITION01_ERROR_LIGHT_STOVE_PH	
	=goal>
		ISA Light-Stove
		state "turn-on"
		previous-goal "initiate"
	!eval! (equal *help* "verbal")	
==>
	!eval! (Utility_physical_help "sequencing" "TRANSITION_0_1")
	!output! ("Sequencing error--> PHYSICAL HELP")
	!pop!
)

(P TRANSITION01_ERROR_LIGHT_STOVE_NC	
	=goal>
		ISA Light-Stove
		state "turn-on"
		previous-goal "initiate"
	!eval! (equal *help* "physical")	
==>
	!eval! (Not_capable_help "sequencing")
	!pop!
	=measure>
		ISA Measure
		ingredient milk 
		ustensile measuring-cup 
		state "ready-to-proceed"
	!push! =measure
	!eval! (stage_parameters_fitting 1)
	!output! ("Sequencing error--> UNABLE")
	!output! ("The supervisor tells him to measure the milk")
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Stage 1 : Measure
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(P 1_RETRIEVE_MILK
	=goal>
		ISA Measure
		state "ready-to-proceed"
		ingredient =name-ingredient
==>
	!eval! (Reset_help)
	=goal>
		state "find-milk"	
	+retrieval>
		=name-ingredient
	!output! ("~&**** Stage 1 : Measure ****")
)

(P 1_RETRIEVE_MILK_ERROR_OMISSION_VERBAL_HELP
	=goal>
		ISA Measure
		state "find-milk"
		ingredient =name-ingredient
	!eval! (equal *help* "no-help")
	=retrieval>
		ISA error
==>
	!eval! (Activation_verbal_help "organization")
	+retrieval>
		=name-ingredient
	!output! ("Milk research: Omission--> VERBAL HELP")
)

(P 1_RETRIEVE_MILK_ERROR_OMISSION_PHYSICAL_HELP
	=goal>
		ISA Measure
		state "find-milk"
		ingredient =name-ingredient
	!eval! (equal *help* "verbal")
	=retrieval>
		ISA error
==>
	!eval! (Activation_physical_help "organization" "milk")	
	+retrieval>
		=name-ingredient
	!output! ("Milk research: Omission--> PHYSICAL HELP")
)

(P 1_RETRIEVE_MILK_ERROR_OMISSION_NOT_CAPABLE
	=goal>
		ISA Measure
		state "find-milk"
		ingredient =name-ingredient
		ustensile =name-ustensile
	!eval! (equal *help* "physical")
	=retrieval>
		ISA error
==>
	!eval! (Not_capable_help "organization")
	=goal>
		state "find-measuring-cup"
	+retrieval>
		ISA Ustensile
		name the-measuring-cup
	!output! ("Milk research: Omission--> UNABLE")
	!output! ("The supervisor gives the milk to him")
)

(P 1_RETRIEVE_MEASURING_CUP
	=goal>
		ISA Measure
		state "find-milk"
		ustensile =name-ustensile
	=retrieval>
		ISA Ingredient
		name the-milk
==>
	!eval! (Reset_help)
	=goal>
		state "find-measuring-cup"	
	+retrieval>
		ISA Ustensile
		name the-measuring-cup
	!output! ("The subject took the milk")
)

(P 1_RETRIEVE_MEASURING_CUP_ERROR_OMISSION_VERBAL_HELP
	=goal>
		ISA Measure
		state "find-measuring-cup"
		ustensile =name-ustensile
	!eval! (equal *help* "no-help")
	=retrieval>
		ISA error
==>
	!eval! (Activation_verbal_help "organization")
	+retrieval>
		=name-ustensile
	!output! ("Measuring cup research: Omission--> VERBAL HELP")
)

(P 1_RETRIEVE_MEASURING_CUP_ERROR_OMISSION_PHYSICAL_HELP
	=goal>
		ISA Measure
		state "find-measuring-cup"
		ustensile =name-ustensile
	!eval! (equal *help* "verbal")
	=retrieval>
		ISA error
==>
	!eval! (Activation_physical_help "organization" "measuring-cup")	
	+retrieval>
		=name-ustensile
	!output! ("Measuring cup research: Omission--> PHYSICAL HELP")
)

(P 1_RETRIEVE_MEASURING_CUP_ERROR_OMISSION_NOT_CAPABLE
	=goal>
		ISA Measure
		state "find-measuring-cup"
		ustensile =name-ustensile
	!eval! (equal *help* "physical")
	=retrieval>
		ISA error
==>
	!eval! (Not_capable_help "organization")
	=goal>
		state "measure"
	!output! ("Measuring cup research: Omission--> UNABLE")
	!output! ("The supervisor gives the measuring cup to him")
)

(P 1_RETRIEVE_MEASURING_CUP_ERROR_ALL_STEPS_VERBAL_HELP
	=goal>
		ISA Measure
		state "find-measuring-cup"
		ustensile =name-ustensile
	!eval! (equal *help* "no-help")
	=retrieval>
		ISA Ustensile
		- name the-measuring-cup
==>
	!eval! (Activation_verbal_help "all-steps")
	+retrieval>
		ISA Ustensile
		name the-measuring-cup
	!output! ("Measuring cup research: Confusion with (~s) --> VERBAL HELP" =retrieval) 
)

(P 1_RETRIEVE_MEASURING_CUP_ERROR_ALL_STEPS_PHYSICAL_HELP
	=goal>
		ISA Measure
		state "find-measuring-cup"
		ustensile =name-ustensile
	!eval! (equal *help* "verbal")
	=retrieval>
		ISA Ustensile
		- name the-measuring-cup
==>
	!eval! (Activation_physical_help "all-steps" "measuring-cup")
	+retrieval>
		ISA Ustensile
		name the-measuring-cup
	!output! ("Measuring cup research: Confusion with (~s) --> PHYSICAL HELP" =retrieval)
)

(P 1_RETRIEVE_MEASURING_CUP_ERROR_ALL_STEPS_NOT_CAPABLE
	=goal>
		ISA Measure
		state "find-measuring-cup"
		ustensile =name-ustensile
	!eval! (equal *help* "physical")
	=retrieval>
		ISA Ustensile
		- name the-measuring-cup
==>
	!eval! (Not_capable_help "all-steps")
	=goal>
		state "measure"
	!output! ("Measuring cup research: Confusion with (~s) --> UNABLE" =retrieval)
	!output! ("The supervisor the measuring cup to him")
)

(P 1_READY_TO_MEASURE
	=goal>
		ISA Measure
		state "find-measuring-cup"
	=retrieval>
		ISA Ustensile
		name the-measuring-cup
==>
	!eval! (Reset_help)
	=goal>
		state "measure"	
	!output! ("The subject took the measuring cup")
)

(P 1_MEASURE
	=goal>
		ISA Measure
		state "measure"
==>
	!eval! (Reset_help)
	!eval! (add-dm (measured-milk ISA Ingredient name the-measured-milk))
	=goal>
		state "complete"	
	!output! ("The subject measured correctly the milk")
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Transition from stage 1 to stage 2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(P TRANSITION_1_2
	=goal>
		ISA Measure
		state "complete"
==>
	=stir>
		ISA Stir
		container saucepan
		ingredient1 measured-milk 
		ingredient2 pudding-mix
		ustensile wooden-spoon 
		state "ready-to-proceed"
	!push! =stir
	!eval! (stage_parameters_fitting 2)
)

(P TRANSITION_1_2_ERROR1
	=goal>
		ISA Measure
		state "complete"
==>
	=light-stove>
		ISA Light-Stove
		state "ready-to-proceed"
		previous-goal "measure"
	!push! =light-stove
	!output! ("~&**** Erroneous stage: Turn on the stove ****")
)

(P TRANSITION12_ERROR_LIGHT_STOVE	
	=goal>
		ISA Light-Stove
		state "ready-to-proceed"
		previous-goal "measure"
==>
	=goal>
		state "turn-on"
	!output! ("The subject wants to turn on the stove")
)

(P TRANSITION12_ERROR_LIGHT_STOVE_VH	
	=goal>
		ISA Light-Stove
		state "turn-on"
		previous-goal "measure"
	!eval! (equal *help* "no-help")	
==>
	!eval! (Utility_verbal_help "sequencing" "TRANSITION_1_2")
	!output! ("Sequencing error--> VERBAL HELP")
	!pop!
)

(P TRANSITION12_ERROR_LIGHT_STOVE_PH	
	=goal>
		ISA Light-Stove
		state "turn-on"
		previous-goal "measure"
	!eval! (equal *help* "verbal")	
==>
	!eval! (Utility_physical_help "sequencing" "TRANSITION_1_2")
	!output! ("Sequencing error--> PHYSICAL HELP")
	!pop!
)

(P TRANSITION12_ERROR_LIGHT_STOVE_NC	
	=goal>
		ISA Light-Stove
		state "turn-on"
		previous-goal "measure"
	!eval! (equal *help* "physical")	
==>
	!eval! (Not_capable_help "sequencing")
	!output! ("Sequencing error--> UNABLE")
	!output! ("The supervisor tells him to stir the ingredients")
	!pop!
	=stir>
		ISA Stir
		container saucepan
		ingredient1 measured-milk 
		ingredient2 pudding-mix
		ustensile wooden-spoon 
		state "ready-to-proceed"
	!push! =stir
	!eval! (stage_parameters_fitting 2)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Stage 2 : Stir
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(P 2_RETRIEVE_CONTAINER
	=goal>
		ISA Stir
		state "ready-to-proceed"
		container =name-container
==>
	!eval! (Reset_help)
	=goal>
		state "find-container"	
	+retrieval>
		ISA Ustensile
		name the-saucepan
	!output! ("~&**** Stage 2 : Stir ****")
)

(P 2_RETRIEVE_SAUCEPAN
	=goal>
		ISA Stir
		state "find-container"
	=retrieval>
		ISA Ustensile
		name the-saucepan
==>
	=goal>
		state "find-measured-milk0"	
		container =retrieval
	!output! ("The subject took the saucepan")
)

(P 2_RETRIEVE_MEASURING_CUP
	=goal>
		ISA Stir
		state "find-container"
	=retrieval>
		ISA Ustensile
		name the-measuring-cup
==>
	=goal>
		state "find-measured-milk0"	
		container =retrieval
	!output! ("The subject took the measuring cup")
)

(P 2_RETRIEVE_CONTAINER_OMISSION_VH
	=goal>
		ISA Stir
		state "find-container"
	=retrieval>
		ISA error
	!eval! (equal *help* "no-help")
==>
	!eval! (Activation_verbal_help "organization")
	+retrieval>
		ISA Ustensile
		name the-saucepan
	!output! ("Container research: Omission--> VERBAL HELP")
)

(P 2_RETRIEVE_CONTAINER_OMISSION_PH
	=goal>
		ISA Stir
		state "find-container"
	=retrieval>
		ISA error
	!eval! (equal *help* "verbal")
==>
	!eval! (Activation_physical_help "organization" "saucepan")
	+retrieval>
		ISA Ustensile
		name the-saucepan
	!output! ("Container research: Omission--> PHYSICAL HELP")
)

(P 2_RETRIEVE_CONTAINER_OMISSION_NC
	=goal>
		ISA Stir
		state "find-container"
	=retrieval>
		ISA error
	!eval! (equal *help* "physical")
==>
	!eval! (Not_capable_help "organization")
	=goal>
		state "find-measured-milk0"
	!output! ("Container research: Omission--> UNABLE")
	!output! ("The supervisor gives the saucepan to him")
)

(P 2_RETRIEVE_MEASURED_MILK
	=goal>
		ISA Stir
		state "find-measured-milk0"
		ingredient1 =name-ingredient1 
==>
	!eval! (Reset_help)
	=goal>
		state "find-measured-milk"
	+retrieval>
		=name-ingredient1
)

(P 2_RETRIEVE_MEASURED_MILK_ERROR_OMISSION_VH
	=goal>
		ISA Stir
		state "find-measured-milk"
		ingredient1 =name-ingredient1
	!eval! (equal *help* "no-help")
	=retrieval>
		ISA error
==>
	!eval! (Activation_verbal_help "organization")
	+retrieval>
		=name-ingredient1
	!output! ("Measured milk research: Omission--> VERBAL HELP")
)

(P 2_RETRIEVE_MEASURED_MILK_ERROR_OMISSION_PH
	=goal>
		ISA Stir
		state "find-measured-milk"
		ingredient1 =name-ingredient1
	!eval! (equal *help* "verbal")
	=retrieval>
		ISA error
==>
	!eval! (Activation_physical_help "organization" "measured-milk")	
	+retrieval>
		=name-ingredient1
	!output! ("Measured milk research: Omission--> PHYSICAL HELP")
)

(P 2_RETRIEVE_MEASURED_MILK_ERROR_OMISSION_NC
	=goal>
		ISA Stir
		state "find-measured-milk"
		ingredient1 =name-ingredient1
		ingredient2 =name-ingredient2
	!eval! (equal *help* "physical")
	=retrieval>
		ISA error
==>
	!eval! (Not_capable_help "organization")
	=goal>
		state "find-pudding-mix"
	+retrieval>
		=name-ingredient2
	!output! ("Measured milk research: Omission--> UNABLE")
	!output! ("The supervisor gives the measured milk to him")
)

(P 2_RETRIEVE_PUDDING_MIX
	=goal>
		ISA Stir
		state "find-measured-milk"
		ingredient1 =name-ingredient1
		ingredient2 =name-ingredient2
	=retrieval>
		ISA Ingredient
		name the-measured-milk
==>
	!eval! (Reset_help)
	=goal>
		state "find-pudding-mix"
	+retrieval>
		=name-ingredient2
	!output! ("The subject pourred the measured milk into the container")
)

(P 2_RETRIEVE_PUDDING_MIX_ERROR_OMISSION_VH
	=goal>
		ISA Stir
		state "find-pudding-mix"
		ingredient2 =name-ingredient2
	!eval! (equal *help* "no-help")
	=retrieval>
		ISA error
==>
	!eval! (Activation_verbal_help "organization")
	+retrieval>
		=name-ingredient2
	!output! ("Pudding mix research: Omission--> VERBAL HELP")
)

(P 2_RETRIEVE_PUDDING_MIX_ERROR_OMISSION_PH
	=goal>
		ISA Stir
		state "find-pudding-mix"
		ingredient2 =name-ingredient2
	!eval! (equal *help* "verbal")
	=retrieval>
		ISA error
==>
	!eval! (Activation_physical_help "organization" "pudding-mix")	
	+retrieval>
		=name-ingredient2
	!output! ("Pudding mix research: Omission--> PHYSICAL HELP")
)

(P 2_RETRIEVE_PUDDING_MIX_ERROR_OMISSION_NC
	=goal>
		ISA Stir
		state "find-pudding-mix"
		ingredient2 =name-ingredient2
	!eval! (equal *help* "physical")
	=retrieval>
		ISA error
==>
	!eval! (Not_capable_help "organization")
	=goal>
		state "find-wooden-spoon"
	+retrieval>
		ISA Ustensile
		name the-wooden-spoon
	!output! ("Pudding mix research: Omission--> UNABLE")
	!output! ("The supervisor gives the pudding mix to him")
)

(P 2_RETRIEVE_WOODEN_SPOON
	=goal>
		ISA Stir
		state "find-pudding-mix"
		ingredient2 =name-ingredient2
	=retrieval>
		ISA Ingredient
		name the-pudding-mix
==>
	!eval! (Reset_help)
	=goal>
		state "find-wooden-spoon"
	+retrieval>
		ISA Ustensile
		name the-wooden-spoon
	!output! ("The subject pourred the pudding mix into the container")
)

(P 2_RETRIEVE_WOODEN_SPOON_ERROR_OMISSION_VERBAL_HELP
	=goal>
		ISA Stir
		state "find-wooden-spoon"
		ustensile =name-ustensile
	!eval! (equal *help* "no-help")
	=retrieval>
		ISA error
==>
	!eval! (Activation_verbal_help "organization")
	+retrieval>
		=name-ustensile
	!output! ("Wooden spoon research: Omission--> VERBAL HELP")
)

(P 2_RETRIEVE_WOODEN_SPOON_ERROR_OMISSION_PHYSICAL_HELP
	=goal>
		ISA Stir
		state "find-wooden-spoon"
		ustensile =name-ustensile
	!eval! (equal *help* "verbal")
	=retrieval>
		ISA error
==>
	!eval! (Activation_physical_help "organization" "measuring-cup")	
	+retrieval>
		=name-ustensile
	!output! ("Wooden spoon research: Omission--> PHYSICAL HELP")
)

(P 2_RETRIEVE_WOODEN_SPOON_ERROR_OMISSION_NOT_CAPABLE
	=goal>
		ISA Stir
		state "find-wooden-spoon"
		ustensile =name-ustensile
	!eval! (equal *help* "physical")
	=retrieval>
		ISA error
==>
	!eval! (Not_capable_help "organization")
	=goal>
		state "stir-mix"
	!eval! (set_var_time (pm-get-time))
	!output! ("Wooden spoon research: Omission--> UNABLE")
	!output! ("The supervisor gives the wooden spoon to him")
)

(P 2_RETRIEVE_WOODEN_SPOON_ERROR_COMMISSION_VERBAL_HELP
	=goal>
		ISA Stir
		state "find-wooden-spoon"
	!eval! (equal *help* "no-help")
	=retrieval>
		ISA Ustensile
		- name the-wooden-spoon
==>
	!eval! (Activation_verbal_help "organization")
	+retrieval>
		ISA Ustensile
		name the-wooden-spoon
	!output! ("Wooden spoon research: Confusion with(~s) --> VERBAL HELP" =retrieval)
)

(P 2_RETRIEVE_WOODEN_SPOON_ERROR_COMMISSION_PHYSICAL_HELP
	=goal>
		ISA Stir
		state "find-wooden-spoon"
		ustensile =name-ustensile
	!eval! (equal *help* "verbal")
	=retrieval>
		ISA Ustensile
		- name the-wooden-spoon
==>
	!eval! (Activation_physical_help "organization" "measuring-cup")
	+retrieval>
		ISA Ustensile
		name the-wooden-spoon
	!output! ("Wooden spoon research: Confusion with(~s) --> PHYSICAL HELP" =retrieval)
)

(P 2_RETRIEVE_WOODEN_SPOON_ERROR_COMMISSION_NOT_CAPABLE
	=goal>
		ISA Stir
		state "find-wooden-spoon"
		ustensile =name-ustensile
	!eval! (equal *help* "physical")
	=retrieval>
		ISA Ustensile
		- name the-wooden-spoon
==>
	!eval! (Not_capable_help "organization")
	=goal>
		state "stir-mix"
	!eval! (set_var_time (pm-get-time))
	!output! ("Wooden spoon research: Confusion with(~s) --> UNABLE" =retrieval)
	!output! ("The supervisor gives the wooden spoon to him")
)

(P 2_READY_TO_STIR
	=goal>
		ISA Stir
		state "find-wooden-spoon"
		ustensile =name-ustensile
	=retrieval>
		ISA Ustensile
		name the-wooden-spoon
==>
	!eval! (Reset_help)
	=goal>
		state "stir-mix"
	!eval! (set_var_time (pm-get-time))
	!output! ("The subject took the wooden spoon")
)

(P 2_STIR
	=goal>
		ISA Stir
		state "stir-mix"
==>
	=goal>
		state "create-mix"	
	!output! ("The subject stired the ingredients")
)

(P 2_STIR_END
	=goal>
		ISA Stir
		state "create-mix"
		container saucepan
==>
	!eval! (add-dm (milk+pudding-mix ISA Ingredient name the-mix container saucepan))
	=goal>
		state "complete"	
)

(P 2_STIR_END_BIS
	=goal>
		ISA Stir
		state "create-mix"
		container measuring-cup
==>
	!eval! (add-dm (milk+pudding-mix ISA Ingredient name the-mix container measuring-cup))
	=goal>
		state "complete"	
)

(P 2_WAITING_WITHOUT_STIRING
	=goal>
		ISA Stir
		state "stir-mix"
==>	
	!output! ("..............")
)

(P 2_STIR_VERBAL_HELP
	=goal>
		ISA Stir
		state "stir-mix"
	!eval! (equal *help* "no-help")
	!eval!  (> (pm-get-time) (+ 50 *time-var*))
==>
	!eval! (Utility_verbal_help "all-steps" "2_STIR")
	!output! ("The subject does not stir the ingredients: Performance of all steps problem --> VERBAL HELP")
)

(P 2_STIR_PHYSICAL_HELP
	=goal>
		ISA Stir
		state "stir-mix"
	!eval! (equal *help* "verbal")
	!eval!  (> (pm-get-time) (+ 150 *time-var*))
==>
	!eval! (Utility_physical_help "all-steps" "2_STIR")
	!output! ("The subject does not stir the ingredients: Performance of all steps problem --> PHYSICAL HELP")

)

(P 2_STIR_NOT_CAPABLE
	=goal>
		ISA Stir
		state "stir-mix"
	!eval! (equal *help* "physical")
	!eval!  (> (pm-get-time) (+ 250 *time-var*))
==>
	!eval! (Not_capable_help "all-steps")
	=goal>
		state "create-mix"
	!output! ("The subject does not stir the ingredients: Performance of all steps problem --> UNABLE")
	!output! ("The supervisora stired the ingredients")
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Transition from stage 2 to stage 3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(P BEFORE_TRANSITION_2_3
	=goal>
		ISA Stir
		state "complete"
==>
	!eval! (Reset_help)
	=goal>	
		state "all-complete"
)


(P TRANSITION_2_3
	=goal>
		ISA Stir
		state "all-complete"
		container saucepan
==>
	=cook>
		ISA Cook
		ingredient milk+pudding-mix
		container saucepan
		ustensile wooden-spoon 
		state "ready-to-proceed"
		stove-state "off"
	!push! =cook
	!eval! (stage_parameters_fitting 3)
)

(P TRANSITION_2_3_BIS
	=goal>
		ISA Stir
		state "all-complete"
		container measuring-cup
==>
	=transvase>
		ISA Transvase
		new-container saucepan
		state "ready-to-proceed"
	!push! =transvase
	!eval! (stage_parameters_fitting 2.5)
)

(P TRANSITION_2_3_ERROR1
	=goal>
		ISA Stir
		state "all-complete"
		container saucepan
==>
	=pour-cold-mix>
		ISA  Pour-Cold-Mix
		state "ready-to-proceed"
		transition "TRANSITION_2_3"
	!push! =pour-cold-mix
	!output! ("~&**** Erroneous stage: Pour the mixture****")
)

(P TRANSITION_2_3_ERROR1_BIS
	=goal>
		ISA Stir
		state "all-complete"
		container measuring-cup
==>
	=pour-cold-mix>
		ISA  Pour-Cold-Mix
		state "ready-to-proceed"
		transition "TRANSITION_2_3_BIS"
	!push! =pour-cold-mix
	!output! ("~&**** Erroneous stage: Pour the mixture****")
)

(P TRANSITION23_ERROR_POUR_COLD_MIX	
	=goal>
		ISA Pour-Cold-Mix
		state "ready-to-proceed"
==>
	=goal>
		state "pouring"
	!output! ("The subject wants to pour the cold mixture into the dishes")
)

(P TRANSITION23_ERROR_POUR_COLD_MIX_VH	
	=goal>
		ISA Pour-Cold-Mix
		state "pouring"
		transition =name-transition
	!eval! (equal *help* "no-help")	
==>
	!eval! (Utility_verbal_help "sequencing" =name-transition)
	!output! ("Sequencing error--> VERBAL HELP")
	!pop!
)

(P TRANSITION23_ERROR_POUR_COLD_MIX_PH	
	=goal>
		ISA Pour-Cold-Mix
		state "pouring"
		transition =name-transition
	!eval! (equal *help* "verbal")	
==>
	!eval! (Utility_physical_help "sequencing" =name-transition)
	!output! ("Sequencing error--> PHYSICAL HELP")
	!pop!
)

(P TRANSITION23_ERROR_POUR_COLD_MIX_NC	
	=goal>
		ISA Pour-Cold-Mix
		state "pouring"
		transition "TRANSITION_2_3"
	!eval! (equal *help* "physical")	
==>
	!eval! (Not_capable_help "sequencing")
	!output! ("Sequencing error--> UNABLE")
	!output! ("The supervisor tells him to cook the mixture")
	!pop!
	=cook>
		ISA Cook
		ingredient milk+pudding-mix
		container saucepan
		ustensile wooden-spoon 
		state "ready-to-proceed"
		stove-state "off"
	!push! =cook
	!eval! (stage_parameters_fitting 3)
)

(P TRANSITION23_ERROR_POUR_COLD_MIX_NC_BIS	
	=goal>
		ISA Pour-Cold-Mix
		state "pouring"
		transition "TRANSITION_2_3_BIS"
	!eval! (equal *help* "physical")	
==>
	!eval! (Not_capable_help "sequencing")
	!output! ("Sequencing error--> UNABLE")
	!output! ("The supervisor tells him to cook the mixture")
	!pop!
	=transvase>
		ISA Transvase
		new-container saucepan
		state "ready-to-proceed"
	!push! =transvase
	!eval! (stage_parameters_fitting 2.5)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Intermediate Stage (before stage 3) : Transvase
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(P TRANSVASE_RETRIEVE_NEW_CONTAINER
	=goal>
		ISA Transvase
		state "ready-to-proceed"
		new-container =name-new-container
==>
	=goal>
		state "find-new-container"
	+retrieval>
		=name-new-container
	!output! ("~&**** Intermediate stage: Transfer the mixture****")
)

(P TRANSVASE
	=goal>
		ISA Transvase
		state "find-new-container"
		new-container =name-new-container
	=retrieval>
		ISA Ustensile
		name the-saucepan
==>
	=goal>
		state "complete"
	!eval! (Mod-Chunk milk+pudding-mix container saucepan)
	!output! ("The subject transfered the mixture into the saucepan")
)

(P TRANSVASE_RETRIEVE_NEW_CONTAINER_ERROR
=goal>
		ISA Transvase
		state "find-new-container"
	=retrieval>
		ISA Error
==>
	=goal>
		state "complete"
	!output! ("The subject did not transfer the  mixture into the saucepan")
)

(P TRANSVASE_END
	=goal>
		ISA Transvase
		state "complete"
==>
	=cook>
		ISA Cook
		ingredient milk+pudding-mix
		container saucepan
		ustensile wooden-spoon 
		state "ready-to-proceed"
		stove-state "off"
	!push! =cook
	!eval! (stage_parameters_fitting 3)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Stage 3 : Cook
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(P 3_INITIATE_COOK_STAGE
	=goal>
		ISA Cook
		state "ready-to-proceed"
==>
	!eval! (Reset_help)
	!eval! (set_var_time (pm-get-time))
	=goal>
		state "light-stove"
	!output! ("~&**** Stage 3 : Cook ****")
)

(P 3_LIGHT_STOVE
	=goal>
		ISA Cook
		state "light-stove"
		stove-state "off"	
==>
	=goal>
		stove-state "on"
	!output! ("The subject turned on the stove")
)

(P 3_WAITING_WITHOUT_LIGHTING_STOVE
	=goal>
		ISA Cook
		state "light-stove"
		stove-state "off"	
==>
	!output! ("..............")
)

(P 3_LIGHT_STOVE_VERBAL_HELP
	=goal>
		ISA Cook
		state "light-stove"
		stove-state "off"
	!eval! (equal *help* "no-help")
	!eval!  (> (pm-get-time) (+ 50 *time-var*))
==>
	!eval! (Utility_verbal_help "all-steps" "3_LIGHT_STOVE")
	!output! ("The subject does not turn on the stove: Performance of all steps problem --> VERBAL HELP")
)

(P 3_LIGHT_STOVE_PHYSICAL_HELP
	=goal>
		ISA Cook
		state "light-stove"
		stove-state "off"
	!eval! (equal *help* "verbal")
	!eval!  (> (pm-get-time) (+ 150 *time-var*))
==>
	!eval! (Utility_physical_help "all-steps" "3_LIGHT_STOVE")
	!output! ("The subject does not turn on the stove: Performance of all steps problem --> PHYSICAL HELP")

)

(P 3_LIGHT_STOVE_NOT_CAPABLE
	=goal>
		ISA Cook
		state "light-stove"
		stove-state "off"
	!eval! (equal *help* "physical")
	!eval!  (> (pm-get-time) (+ 250 *time-var*))
==>
	!eval! (Not_capable_help "all-steps")
	=goal>
		stove-state "on"
	!output! ("The subject does not turn on the stove: Performance of all steps problem --> UNABLE")
	!output! ("The supervisor turns the stove on")

)

(P 3_RETRIEVE_MIX
	=goal>
		ISA Cook
		state "light-stove"
		stove-state "on"
		ingredient =name-ingredient	
==>
	!eval! (Reset_help)
	=goal>
		state "find-mix"
	+retrieval>
		=name-ingredient
)

(P 3_RETRIEVE_MIX_ERROR_OMISSION_VERBAL_HELP
	=goal>
		ISA Cook
		state "find-mix"
		stove-state "on"
		ingredient =name-ingredient
	!eval! (equal *help* "no-help")
	=retrieval>
		ISA error
==>
	!eval! (Activation_verbal_help "organization")
	+retrieval>
		=name-ingredient
	!output! ("Mixture research: Omission--> VERBAL HELP")
)

(P 3_RETRIEVE_MIX_ERROR_OMISSION_PHYSICAL_HELP
	=goal>
		ISA Cook
		state "find-mix"
		stove-state "on"
		ingredient =name-ingredient
	!eval! (equal *help* "verbal")
	=retrieval>
		ISA error
==>
	!eval! (Activation_physical_help "organization" "milk+pudding-mix")	
	+retrieval>
		=name-ingredient
	!output! ("Mixture research: Omission--> PHYSICAL HELP")
)

(P 3_RETRIEVE_MIX_ERROR_OMISSION_NOT_CAPABLE
	=goal>
		ISA Cook
		state "find-mix"
		stove-state "on"
		ingredient =name-ingredient
		container (Chunk-Slot-Value milk+pudding-mix container)
	!eval! (equal *help* "physical")
	=retrieval>
		ISA error
==>
	!eval! (Not_capable_help "organization")
	=goal>
		state "put-on-stove"
	!output! ("Mixture research: Omission--> UNABLE")
	!output! ("The supervisor gives the mixture to him")
)

(P 3_RETRIEVE_MIX_ERROR_OMISSION_NOT_CAPABLE_BIS
	=goal>
		ISA Cook
		state "find-mix"
		stove-state "on"
		ingredient =name-ingredient
		- container (Chunk-Slot-Value milk+pudding-mix container)
	!eval! (equal *help* "physical")
	=retrieval>
		ISA error
==>
	!eval! (Not_capable_help "organization")
	=goal>
		state "help-container"
	!output! ("Mixture research: Omission--> UNABLE")
	!output! ("The supervisor gives the mixture to him")
)

(P 3_PUT_CONTAINER_ON_STOVE
	=goal>
		ISA Cook
		state "find-mix"
		stove-state "on"
	=retrieval>
		ISA Ingredient
		name the-mix
		container saucepan	
==>
	!eval! (Reset_help)
	=goal>
		state "put-on-stove"
)

(P 3_ACTIVE_HELP_FOR_CONTAINER
	=goal>
		ISA Cook
		state "find-mix"
		stove-state "on"
	=retrieval>
		ISA Ingredient
		name the-mix
		container measuring-cup	
==>
	!eval! (Reset_help)
	=goal>
		state "help-container"
)

(P 3_PUT_CONTAINER_ON_STOVE_VH
	=goal>
		ISA Cook
		state "help-container"
		container =name-container
	!eval! (equal *help* "no-help")
==>
	!eval! (Activation_verbal_help "organization")
	=goal>
		state "retrieve-from-help"
	+retrieval>
		=name-container
	!output! ("Organization error: The subject wants to cook the mixture in the measuring cup --> VERBAL HELP")
)

(P 3_RETRIEVE_SAUCEPAN_A
	=goal>
		ISA Cook
		state "retrieve-from-help"
	=retrieval>
		ISA Ustensile
		name the-saucepan
==>
	!eval! (Mod-Chunk milk+pudding-mix container saucepan)
	=goal>
		state "put-on-stove"
	!output! ("The subject transfered the mixture into the saucepan")
)

(P 3_RETRIEVE_SAUCEPAN_B
	=goal>
		ISA Cook
		state "retrieve-from-help"
	=retrieval>
		ISA Error
==>
	=goal>
		state "help-container"
	!output! ("The subject cannot transfer the mixture into the saucepan")
)

(P 3_PUT_CONTAINER_ON_STOVE_PH
	=goal>
		ISA Cook
		state "help-container"
		container =name-container
	!eval! (equal *help* "verbal")
==>
	!eval! (Activation_physical_help "organization" "saucepan")
	=goal>
		state "retrieve-from-help"
	+retrieval>
		=name-container
	!output! ("Organization error: The subject wants to cook the mixture in the measuring cup --> PHYSICAL HELP")
)

(P 3_PUT_CONTAINER_ON_STOVE_NC
	=goal>
		ISA Cook
		state "help-container"
		container =name-container
	!eval! (equal *help* "physical")
==>
	!eval! (Not_Capable_help "organization")
	!eval! (Mod-Chunk milk+pudding-mix container saucepan)
	=goal>
		state "put-on-stove"
	!output! ("Organization error: The subject wants to cook the mixture in the measuring cup --> UNABLE")
	!output! ("The supervisor transfered the mixture into the saucepan")
)

(P 3_CONTAINER_ON_STOVE
	=goal>
		ISA Cook
		state "put-on-stove"
==>	
	!eval! (Reset_help)
	!eval! (set_var_time (pm-get-time))
	=goal>
		state "wait-and-stir"
	!output! ("The subject puts the saucepan on the stove")
)

(P 3_WAIT_AND_STIR
	=goal>
		ISA Cook
		state "wait-and-stir"
==>	
	!output! ("The subject stirs the mixture and wait until it is hot")
)

(P 3_STOP_WAITING_AND_STIRING
	=goal>
		ISA Cook
		state "wait-and-stir"
	!eval!  (> (pm-get-time) (+ 50 *time-var*))
==>	
	!eval! (Reset_help)
	=goal>
		state "achieve-stage"
	!output! ("The subject considers the mixture ready")
)

(P 3_WAIT_AND_STIR_COMPLETION_VERBAL_HELP
	=goal>
		ISA Cook
		state "wait-and-stir"
	!eval! (equal *help* "no-help")
	!eval!  (> (pm-get-time) (+ 150 *time-var*))
==>
	!eval! (Utility_verbal_help "completion" "3_STOP_WAITING_AND_STIRING")
	!output! ("The subject keeps cooking the mixture: perseveration problem --> VERBAL HELP")
)

(P 3_WAIT_AND_STIR_COMPLETION_PHYSICAL_HELP
	=goal>
		ISA Cook
		state "wait-and-stir"
	!eval! (equal *help* "verbal")
	!eval!  (> (pm-get-time) (+ 250 *time-var*))
==>
	!eval! (Utility_physical_help "completion" "3_STOP_WAITING_AND_STIRING")
	!output! ("The subject keeps cooking the mixture: perseveration problem --> PHYSICAL HELP")

)

(P 3_WAIT_AND_STIR_COMPLETION_NOT_CAPABLE
	=goal>
		ISA Cook
		state "wait-and-stir"
	!eval! (equal *help* "physical")
	!eval!  (> (pm-get-time) (+ 350 *time-var*))
==>
	!eval! (Not_capable_help "completion")
	=goal>
		state "achieve-stage"
	!output! ("The subject keeps cooking the mixture: perseveration problem --> UNABLE")
	!output! ("The supervisor takes off the saucepan from the stove")
)

(P 3_TURN_OFF_STOVE
	=goal>
		ISA Cook
		state "achieve-stage"
==>
	=goal>
		state "complete"
		stove-state "off"
	!output! ("The subject turned off the stove")
)

(P 3_COMPLETE_COOK_STAGE
	=goal>
		ISA Cook
		state "achieve-stage"
==>
	=goal>
		state "complete"
)

(P 3_COMPLETE_COOK_STAGE_JUDGMENT_VERBAL_HELP
	=goal>
		ISA Cook
		state "complete"
		stove-state "on"
	!eval! (equal *help* "no-help")
==>
	!eval! (Utility_verbal_help "judgment-safety" "3_TURN_OFF_STOVE")
	=goal>
		state "achieve-stage"
	!output! ("The subject does not turn off the stove: Judgment and safety problem--> VERBAL HELP")
)

(P 3_COMPLETE_COOK_STAGE_JUDGMENT_PHYSICAL_HELP
	=goal>
		ISA Cook
		state "complete"
		stove-state "on"
	!eval! (equal *help* "verbal")
==>
	!eval! (Utility_physical_help "judgment-safety" "3_TURN_OFF_STOVE")
	=goal>
		state "achieve-stage"
	!output! ("The subject does not turn off the stove: Judgment and safety problem--> PHYSICAL HELP")

)

(P 3_COMPLETE_COOK_STAGE_JUDGMENT_NOT_CAPABLE
	=goal>
		ISA Cook
		state "complete"
		stove-state "on"
	!eval! (equal *help* "physical")
==>
	!eval! (Not_capable_help "judgment-safety")
	=goal>
		stove-state "off"
		state "complete"
	!output! ("The subject does not turn off the stove: Judgment and safety problem--> UNABLE")
	!output! ("The supervisor turns off the stove")
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Transition from stage 3 to stage 4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(P BEFORE_TRANSITION_3_4
	=goal>
		ISA Cook
		state "complete"
		stove-state "off"
==>
	!eval! (Reset_help)
	=goal>
		state "all-completed"
)

(P TRANSITION_3_4
	=goal>
		ISA Cook
		state "all-completed"
		stove-state "off"
==>
	=pour>
		ISA Pour
		state "ready-to-proceed"
		container saucepan
		first-dish dish1
		second-dish dish2
		third-dish dish3
		fourth-dish dish4
		ustensile rubber-scraper
		dishes-state 0
	!push! =pour
	!eval! (stage_parameters_fitting 4)
)

(P TRANSITION_3_4_ERROR1
	=goal>
		ISA Cook
		state "all-completed"
==>
	=clean-error>
		ISA Clean
		state "ready-to-proceed"
		previous-stage "Cook"
	!push! =clean-error
	!output! ("~&**** Erroneous stage: Clean up****")
)

(P TRANSITION34_ERROR_CLEAN	
	=goal>
		ISA Clean
		state "ready-to-proceed"
		previous-stage "Cook"
==>
	=goal>
		state "proceed"
	!output! ("The subject wants to clean up the utensils")
)

(P TRANSITION34_ERROR_CLEAN_VH	
	=goal>
		ISA Clean
		state "proceed"
		previous-stage "Cook"
	!eval! (equal *help* "no-help")	
==>
	!eval! (Utility_verbal_help "all-steps" "TRANSITION_3_4")
	!output! ("Performance of all steps problem--> VERBAL HELP")
	!pop!
)

(P TRANSITION34_ERROR_CLEAN_PH	
	=goal>
		ISA Clean
		state "proceed"
		previous-stage "Cook"
	!eval! (equal *help* "verbal")	
==>
	!eval! (Utility_Physical_help "all-steps" "TRANSITION_3_4")
	!output! ("Performance of all steps problem--> PHYSICAL HELP")
	!pop!
)

(P TRANSITION34_ERROR_CLEAN_NC	
	=goal>
		ISA Clean
		state "proceed"
		previous-stage "Cook"
	!eval! (equal *help* "physical")	
==>
	!eval! (Not_capable_help "all-steps")
	!output! ("Performance of all steps problem--> UNABLE")
	!output! ("The supervisor tells him to pour the mixture")
	!pop!
	=pour>
		ISA Pour
		state "ready-to-proceed"
		container saucepan
		first-dish dish1
		second-dish dish2
		third-dish dish3
		fourth-dish dish4
		ustensile rubber-scraper
		dishes-state 0
	!push! =pour
	!eval! (stage_parameters_fitting 4)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Stage 4 : Pour
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(P 4_READY_FOR_POUR_STAGE
	=goal>
		ISA Pour
		state "ready-to-proceed"
		container =name-container
==>
	!eval! (Reset_help)
	=goal>
		state "find-container"
	!output! ("~&**** Stage 4 : Pour ****")
	+retrieval>
		=name-container						
)

(P 4_RETRIEVE_CONTAINER
	=goal>
		ISA Pour
		state "find-container"
	=retrieval>
		ISA Ustensile
		name the-saucepan
==>
	!eval! (Reset_help)
	=goal>
		state "find-dish"	
	!output! ("The subject took the saucepan")				
)

(P 4_RETRIEVE_CONTAINER_OMISSION_ERROR_VH
	=goal>
		ISA Pour
		state "find-container"
		container =name-container
		!eval! (equal *help* "no-help")
	=retrieval>
		ISA error
==>
	!eval! (Activation_verbal_help "organization")
	+retrieval>
		=name-container
	!output! ("saucepan with mixture research: Omission--> VERBAL HELP")			
)

(P 4_RETRIEVE_CONTAINER_OMISSION_ERROR_PH
	=goal>
		ISA Pour
		state "find-container"
		container =name-container
		!eval! (equal *help* "verbal")
	=retrieval>
		ISA error
==>
	!eval! (Activation_physical_help "organization" "Saucepan")
	+retrieval>
		=name-container
	!output! ("saucepan with mixture research: Omission--> PHYSICAL HELP")			
)

(P 4_RETRIEVE_CONTAINER_OMISSION_ERROR_NC
	=goal>
		ISA Pour
		state "find-container"
		container =name-container
		!eval! (equal *help* "physical")
	=retrieval>
		ISA error
==>
	!eval! (Not_capable_help "organization")
	=goal>
		state "find-dish"	
	!output! ("saucepan with mixture research: Omission--> UNABLE")			
	!output! ("The supervisor takes the saucepan")
)

(P 4_FIND_DISH
	=goal>
		ISA Pour
		state "find-dish"
==>
	!eval! (Reset_help)
	=goal>
		state "retrieve-dish"
	+retrieval>
		ISA Ustensile
		function "dish"
		state "empty"	
)

(P 4_RETRIEVE_DISH
	=goal>
		ISA Pour
		state "retrieve-dish"
	=retrieval>
		ISA Ustensile
		function "dish"
		state "empty"
		other =number
==>
	!eval! (Reset_help)
	!eval! (set_var_time (pm-get-time))
	=goal>
		state "pour"	
		current-dish =number
	!output! ("The subject took an empty dish: ~s" =retrieval)				
)

(P 4_RETRIEVE_DISH_OMISSION_ERROR_VH
	=goal>
		ISA Pour
		state "retrieve-dish"
		- dishes-state 4
		!eval! (equal *help* "no-help")
	=retrieval>
		ISA error
==>
	!eval! (Activation_verbal_help "organization")
	+retrieval>
		ISA Ustensile
		function "dish"
		state "empty"	
	!output! ("Empty dish research: Omission--> VERBAL HELP")			
)

(P 4_RETRIEVE_DISH_OMISSION_ERROR_PH
	=goal>
		ISA Pour
		state "retrieve-dish"
		- dishes-state 4
		!eval! (equal *help* "verbal")
	=retrieval>
		ISA error
==>
	!eval! (Activation_physical_help "organization" "Dish")
	+retrieval>
		ISA Ustensile
		function "dish"
		state "empty"
	!output! ("Empty dish research: Omission--> PHYSICAL HELP")			
)

(P 4_RETRIEVE_DISH_OMISSION_ERROR_NC
	=goal>
		ISA Pour
		state "retrieve-dish"
		- dishes-state 4
		!eval! (equal *help* "physical")
	=retrieval>
		ISA error
==>
	!eval! (Not_capable_help "organization")
	!bind! =number-current-dish *current-dish*
	!eval! (set_var_time (pm-get-time))
	=goal>
		state "pour"	
		current-dish =number-current-dish
	!output! ("Empty dish research: Omission--> UNABLE")			
	!output! ("The supervisor takes an empty dish")
)

(P 4_POUR
	=goal>
		ISA Pour
		state "pour"
==>
	=goal>
		state "pour-into-dish"
	!output! ("The subject pours correctly the mixture into the dish")	
)

(P 4_BAD_POUR
	=goal>
		ISA Pour
		state "pour"
==>
	=goal>
		state "bad-pour"
	!output! ("The subject does not pour correctly the mixture and burns himself")	
)

(P 4_BAD_POUR_VERBAL_HELP
	=goal>
		ISA Pour
		state "bad-pour"
	!eval! (equal *help* "no-help")
==>
	!eval! (Utility_verbal_help "judgment-safety" "4_POUR")
	!eval! (set_var_time (pm-get-time))
	=goal>
		state "pour"
	!output! ("The subject burns himself while pourring the mixture: Safety problem --> VERBAL HELP")
)

(P 4_BAD_POUR_PHYSICAL_HELP
	=goal>
		ISA Pour
		state "bad-pour"
	!eval! (equal *help* "verbal")
==>
	!eval! (Utility_physical_help "judgment-safety" "4_POUR")
	!eval! (set_var_time (pm-get-time))
	=goal>
		state "pour"
	!output! ("The subject burns himself while pourring the mixture: Safety problem --> PHYSICAL HELP")
)

(P 4_BAD_POUR_NOT_CAPABLE
	=goal>
		ISA Pour
		state "bad-pour"
	!eval! (equal *help* "physical")
==>
	!eval! (Not_capable_help "judgment-safety")
	=goal>
		state "pour-into-dish"
	!output! ("The subject burns himself while pourring the mixture: Safety problem --> UNABLE")
	!output! ("The supervisor pours the mixture")
)

(P 4_WAITING_WITHOUT_POURING
	=goal>
		ISA Pour
		state "pour"	
==>
	!output! ("..............")
)

(P 4_WAITING_WITHOUT_POURING_VERBAL_HELP
	=goal>
		ISA Pour
		state "pour"
	!eval! (equal *second-help* "no-help")
	!eval!  (> (pm-get-time) (+ 50 *time-var*))
==>
	!eval! (Utility_verbal_help_second "all-steps" "4_POUR")
	!output! ("The subject does not pour the mixture: Performance of all steps problem --> VERBAL HELP")
)

(P 4_WAITING_WITHOUT_POURING_PHYSICAL_HELP
	=goal>
		ISA Pour
		state "pour"
	!eval! (equal *second-help* "verbal")
	!eval!  (> (pm-get-time) (+ 150 *time-var*))
==>
	!eval! (Utility_physical_help_second "all-steps" "4_POUR")
	!output! ("The subject does not pour the mixture: Performance of all steps problem --> PHYSICAL HELP")
)

(P 4_WAITING_WITHOUT_POURING_NOT_CAPABLE
	=goal>
		ISA Pour
		state "pour"
	!eval! (equal *second-help* "physical")
	!eval!  (> (pm-get-time) (+ 250 *time-var*))
==>
	!eval! (Not_capable_help "all-steps")
	=goal>
		state "pour-into-dish"
	!output! ("The subject does not pour the mixture: Performance of all steps problem --> UNABLE")
	!output! ("The supervisor pours the mixture")
)

(P 4_POUR_INTO_DISH
	=goal>
		ISA Pour
		state "pour-into-dish"
		dishes-state =dishes-state
		current-dish =number
==>
	!eval! (Reset_help)
	!bind! =new-dishes-state (+ 1 =dishes-state)
	!eval! (set_dish_state =number)
	=goal>
		state "find-dish"
		dishes-state =new-dishes-state	
)

(P 4_DISHES_FULL
	=goal>
		ISA Pour
		state "retrieve-dish"
		dishes-state 4
	=retrieval>
		ISA error
==>
	!eval! (Reset_help)
	=goal>
		state "find-rubber-scraper"
	+retrieval>
		ISA Ustensile
		name the-rubber-scraper		
	!output! ("The subject completed the first distribution")
)

(P 4_DISHES_FULL_BIS
	=goal>
		ISA Pour
		state "retrieve-dish"
		dishes-state 4
	=retrieval>
		ISA Ustensile
		function "dish"
		state "full"
		other =number
==>
	!eval! (Reset_help)
	=goal>
		state "find-rubber-scraper"
	+retrieval>
		ISA Ustensile
		name the-rubber-scraper		
	!output! ("The subject completed the first distribution")
)


(P 4_RETRIEVE_RUBBER_SCRAPER
	=goal>
		ISA Pour
		state "find-rubber-scraper"
	=retrieval>
		ISA Ustensile
		name the-rubber-scraper
==>
	!eval! (Reset_help)
	=goal>
		state "ready-scrap-saucepan"	
	!output! ("The subject took the rubber scraper")				
)

(P 4_RETRIEVE_RUBBER_SCRAPER_ERROR_OMISSION_VH
	=goal>
		ISA Pour
		state "find-rubber-scraper"
		ustensile =name-ustensile
	!eval! (equal *help* "no-help")
	=retrieval>
		ISA error
==>
	!eval! (Activation_verbal_help "organization")
	+retrieval>
		=name-ustensile
	!output! ("Rubber scraper research : Omission--> VERBAL HELP")
)

(P 4_RETRIEVE_RUBBER_SCRAPER_ERROR_OMISSION_PH
	=goal>
		ISA Pour
		state "find-rubber-scraper"
		ustensile =name-ustensile
	!eval! (equal *help* "verbal")
	=retrieval>
		ISA error
==>
	!eval! (Activation_physical_help "organization" "rubber-scraper")	
	+retrieval>
		=name-ustensile
	!output! ("Rubber scraper research : Omission--> PHYSICAL HELP")
)

(P 4_RETRIEVE_RUBBER_SCRAPER_ERROR_OMISSION_NC
	=goal>
		ISA Pour
		state "find-rubber-scraper"
		ustensile =name-ustensile
	!eval! (equal *help* "physical")
	=retrieval>
		ISA error
==>
	!eval! (Not_capable_help "organization")
	=goal>
		state "ready-scrap-saucepan"
	!output! ("Rubber scraper research : Omission--> UNABLE")
	!output! ("The supervisor gives the Rubber scraper to him")
)

(P 4_RETRIEVE_RUBBER_SCRAPER_ERROR_COMMISSION_VH
	=goal>
		ISA Pour
		state "find-rubber-scraper"
	!eval! (equal *help* "no-help")
	=retrieval>
		ISA Ustensile
		- name the-rubber-scraper
==>
	!eval! (Activation_verbal_help "organization")
	+retrieval>
		ISA Ustensile
		name the-rubber-scraper
	!output! ("Rubber scraper research : Confusion with(~s) --> VERBAL HELP" =retrieval)
)

(P 4_RETRIEVE_RUBBER_SCRAPER_ERROR_COMMISSION_PH
	=goal>
		ISA Pour
		state "find-rubber-scraper"
	!eval! (equal *help* "verbal")
	=retrieval>
		ISA Ustensile
		- name the-rubber-scraper
==>
	!eval! (Activation_physical_help "organization" "rubber-scraper")
	+retrieval>
		ISA Ustensile
		name the-rubber-scraper
	!output! ("Rubber scraper research : Confusion with(~s) --> PHYSICAL HELP" =retrieval)
)

(P 4_RETRIEVE_RUBBER_SCRAPER_ERROR_COMMISSION_NC
	=goal>
		ISA Pour
		state "find-rubber-scraper"
	!eval! (equal *help* "physical")
	=retrieval>
		ISA Ustensile
		- name the-rubber-scraper
==>
	!eval! (Not_capable_help "organization")
	=goal>
		state "ready-scrap-saucepan"
	!output! ("Rubber scraper research : Confusion with(~s) --> UNABLE" =retrieval)
	!output! ("The supervisor gives the rubber scraper to him")
)

(P 4_READY_TO_SCRAP_SAUCEPAN
	=goal>
		ISA Pour
		state "ready-scrap-saucepan"
==>
	!eval! (set_var_time (pm-get-time))
	!eval! (Reset_help)
	=goal>
		state "scrap-saucepan"					
)

(P 4_SCRAP_SAUCEPAN
	=goal>
		ISA Pour
		state "scrap-saucepan"
==>
	!output! ("The subject scraps the saucepan")				
)

(P 4_STOP_SCRAPPING_SAUCEPAN
	=goal>
		ISA Pour
		state "scrap-saucepan"
	!eval!  (> (pm-get-time) (+ 50 *time-var*))
==>
	!eval! (Reset_help)
	=goal>
		state "saucepan-empty"
	!output! ("The subject considers the saucepan empty")				
)

(P 4_SCRAP_SAUCEPAN_COMPLETION_VERBAL_HELP
	=goal>
		ISA Pour
		state "scrap-saucepan"
	!eval! (equal *help* "no-help")
	!eval!  (> (pm-get-time) (+ 150 *time-var*))
==>
	!eval! (Utility_verbal_help "completion" "4_STOP_SCRAPPING_SAUCEPAN")
	!output! ("The subject keeps scraping the saucepan: Perseveration problem --> VERBAL HELP")
)

(P 4_SCRAP_SAUCEPAN_COMPLETION_PHYSICAL_HELP
	=goal>
		ISA Pour
		state "scrap-saucepan"
	!eval! (equal *help* "verbal")
	!eval!  (> (pm-get-time) (+ 250 *time-var*))
==>
	!eval! (Utility_physical_help "completion" "4_STOP_SCRAPPING_SAUCEPAN")
	!output! ("The subject keeps scraping the saucepan: Perseveration problem --> PHYSICAL HELP")

)

(P 4_SCRAP_SAUCEPAN_COMPLETION_NOT_CAPABLE
	=goal>
		ISA Pour
		state "scrap-saucepan"
	!eval! (equal *help* "physical")
	!eval!  (> (pm-get-time) (+ 350 *time-var*))
==>
	!eval! (Not_capable_help "completion")
	=goal>
		state "saucepan-empty"
	!output! ("The subject keeps scraping the saucepan: Perseveration problem --> UNABLE")
	!output! ("The supervisor takes off the saucepan")
)


(P 4_OVER
	=goal>
		ISA Pour
		state  "saucepan-empty"
==>
	!eval! (Reset_help)
	=goal>
		state "complete"
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Transition from stage 4 to stage 5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(P BEFORE_TRANSITION_4_5
	=goal>
		ISA Pour
		state "complete"
==>
	!eval! (Reset_help)
	=goal>
		state "all-completed"
)

(P TRANSITION_4_5
	=goal>
		ISA Pour
		state "all-completed"
==>
	=clean>
		ISA Clean
		state "ready-to-proceed"
		previous-stage "Pour"
	!push! =clean
	!eval! (stage_parameters_fitting 5)
)

(P TRANSITION_4_5_ERROR1
	=goal>
		ISA Pour
		state "all-completed"
==>
	=task-completed>
		ISA Task-Completed
		state "ready-to-proceed"
		previous-stage "Pour"
	!push! =task-completed
	!output! ("~&**** Erroneous stage: The subject considers the task completed****")
)

(P TRANSITION45_ERROR_TASK_COMPLETED_VH	
	=goal>
		ISA Task-Completed
		state "ready-to-proceed"
		previous-stage "Pour"
	!eval! (equal *help* "no-help")	
==>
	!eval! (Utility_verbal_help "all-steps" "TRANSITION_4_5")
	!output! ("Performance of all steps problem--> VERBAL HELP")
	!pop!
)

(P TRANSITION45_ERROR_TASK_COMPLETED_PH	
	=goal>
		ISA Task-Completed
		state "ready-to-proceed"
		previous-stage "Pour"
	!eval! (equal *help* "verbal")	
==>
	!eval! (Utility_Physical_help "all-steps" "TRANSITION_4_5")
	!output! ("Performance of all steps problem--> PHYSICAL HELP")
	!pop!
)

(P TRANSITION45_ERROR_TASK_COMPLETED_NC	
	=goal>
		ISA Task-Completed
		state "ready-to-proceed"
		previous-stage "Pour"
	!eval! (equal *help* "physical")	
==>
	!eval! (Not_capable_help "all-steps")
	!output! ("Performance of all steps problem--> UNABLE")
	!output! ("The supervisor tells him to clean up the utensils")
	!pop!
	=clean>
		ISA Clean
		state "ready-to-proceed"
		previous-stage "Pour"
	!push! =clean
	!eval! (stage_parameters_fitting 5)
)



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Stage 5 : Clean the ustensiles
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(P 5_CLEAN
	=goal>
		ISA Clean
		state "ready-to-proceed"
		previous-stage "Pour"
==>
	!eval! (Reset_help)
	=goal>
		state "complete"
	!output! ("~&**** Etape 5 : Clean up ****")				
)
;taces

(goal-focus initiate)

; Similarities between chunks
(Set-Similarities
  (the-measuring-cup the-saucepan  0.2)
  (the-wooden-spoon the-rubber-scraper 0.2))

