Академический Документы
Профессиональный Документы
Культура Документы
(CEST, Lucknow)
Submitted By : Name :
(defvar *visited* nil) (defvar *heur-mult* 2) (defun best (state limit) (let ((nodes 0) (expanded 0) (branches 0) (limit limit) (open (list (list (heur-value state) state)))) (setf *visited* nil) (loop (cond ((null open) (print (list 'nodes nodes expanded branches)) (return (list 'no 'solution 'found)))) (incf nodes) (cond ((goalp (state-of (car open))) (print (list 'nodes nodes expanded branches)) (print (list 'length 'of 'soln (depth-of (car open)))) (return (path-of (car open))))) (cond ((> nodes limit) (print (list 'nodes nodes expanded branches)) (return (list 'closest 'was (car open))))) (let ((children (new-states (state-of (car open))))) (incf expanded) (setf branches (+ (length children) branches)) (setf open (combine-queue children (car open) (cdr open)))))))
(defun combine-queue (new-states node queue) (push (state-of node) *visited*) (dolist (state new-states) (if (not (member state *visited* :test #'equal)) (push (cons (- (* *heur-mult* (heur-value state)) (depth-of node)) (cons state (cdr node))) queue))) (sort queue #'> :key #'car))
(cond((null x) nil) ((null (car x)) (remove-null (cdr x))) ((cons (car x) (remove-null (cdr x)))))) (defun fill-first (state) (cond ((< (first-jug state) 4) (mk-state 4 (second-jug state)))))) (defun fill-second (state) (cond ((< (second-jug state) 3) (mk-state (first-jug state) 3)))) (defun pour-first-second (state) (let ( (f (first-jug state)) (s (second-jug state))) (cond ((zerop f) nil) ((= s 3) nil) ((<= (+ f s) 3) (mk-state 0 (+ f s))) (t (mk-state (- (+ f s) 3) 3))))) (defun pour-second-first (state) (let ( (f (first-jug state)) (s (second-jug state))) (cond ((zerop s) nil) ((= f 4) nil) ((<= (+ f s) 4) (mk-state (+ f s) 0)) (t(mk-state 4 (- (+ f s) 4)))))) ; Fill first from second ; Cant pour nothing ; First full ; Empty second into first ; Fill second from first ; Cant pour nothing ; Second full ; Empty first into second
(defun empty-second (state) (cond((> (second-jug state) 0) (mk-state (first-jug state) 0))))
not(member_queue(Test, Open)), not(member_set(Test, Closed)), state_record(Next, State, Child_record). printsolution(State_record, _):state_record(State,nil, State_record), write(State), nl. printsolution(State_record, Closed) :state_record(State, Parent, State_record), state_record(Parent, _, Parent_record), member(Parent_record, Closed), printsolution(Parent_record, Closed), write(State), nl. add_list_to_queue([], Queue, Queue). add_list_to_queue([H|T], Queue, New_queue) :add_to_queue(H, Queue, Temp_queue), add_list_to_queue(T, Temp_queue, New_queue).