;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; generation.lisp ;;; Written by: Shaul Markovitch ;;; Last time modified: 10/1/2000 ;;; ;;; ;;; This file contains procedures for generating training (and ;;; tetsing) problems. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; The basic technique for generating problems. It assumes that ;;; the domain includes a function for generating random goal states. ;;; It aslo assumes that the ;;; domain definition includes a definition of reverse operators. It ;;; applies a random sequence of such operators on the random goal ;;; and gets an initial state. This method guarentees that the problem ;;; is solveable. The technique includes one parameter - the maximal ;;; length of the random sequence. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defparameter *random-problem-sequence-length* 10000) (defclass problem-generation ()()) (defclass random-generation (problem-generation) ((sequence-length :initform *random-problem-sequence-length* :initarg :sequence-length :accessor random-generation-sequence-length))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; generate-problem ;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defmethod generate-problem ((domain domain)(method random-generation)) (let* ((goal (funcall (domain-gen-goal-fn domain) domain)) (state (funcall (domain-state-copy-fn domain) goal)) (n (random-generation-sequence-length method)) (rev-ops (domain-reverse-operators domain))) (loop repeat n do (loop for op in (shuffle rev-ops) for new-state = (funcall (domain-apply-rev-op-fn domain) op state domain t) until new-state finally (setf state new-state))) (make-problem :init-state state :goal-state goal)))