AI Lab Programs
AI Lab Programs
(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- ueue children (car open) (cdr open)))))))
(defun combine- ueue (new-states node ueue) (push (state-of node) *visited*) (dolist (state new-states) (if (not (member state *visited* !test "'e ual)) (push (cons (- (* *heur-mult* (heur-value state)) (depth-of node)) (cons state (cdr node))) ueue))) (sort ueue "'> !#e$ "'car))
(cond((null x) nil) ((null (car x)) (remo8e-null (cdr x))) ((cons (car x) (remo8e-null (cdr x)))))) (defun fill-first (state) (cond ((@ (first-jug state) 1) (mk-state 1 (second-jug state)))))) (defun fill-second (state) (cond ((@ (second-jug state) /) (mk-state (first-jug state) /)))) (defun pour-first-second (state) (let ( (f (first-jug state)) (s (second-jug state))) (cond ((zerop f) nil) ((; s /) nil) ((@; (> f s) /) (mk-state 0 (> f s))) (t (mk-state (- (> f s) /) /))))) (defun pour-second-first (state) (let ( (f (first-jug state)) (s (second-jug state))) (cond ((zerop s) nil) ((; f 1) nil) ((@; (> f s) 1) (mk-state (> f s) 0)) (t(mk-state 1 (- (> f s) 1)))))) , =ill first from second , <ant pour nothing , =irst full , (mpty second into first , =ill second from first , <ant pour nothing , !econd full , (mpty first into second
(defun empty-second (state) (cond((A (second-jug state) 0) (mk-state (first-jug state) 0))))
not(member50ueue("estB &pen))B not(member5set("estB <losed))B state5record(%extB !tateB <hild5record)+ printsolution(!tate5recordB 5):state5record(!tateBnilB !tate5record)B 4rite(!tate)B nl+ printsolution(!tate5recordB <losed) :state5record(!tateB arentB !tate5record)B state5record( arentB 5B arent5record)B member( arent5recordB <losed)B printsolution( arent5recordB <losed)B 4rite(!tate)B nl+ add5list5to50ueue(EFB GueueB Gueue)+ add5list5to50ueue(EHI"FB GueueB %e450ueue) :add5to50ueue(HB GueueB "emp50ueue)B add5list5to50ueue("B "emp50ueueB %e450ueue)+