Escolar Documentos
Profissional Documentos
Cultura Documentos
Experiment No.1
;;; DEPTHFS.CL
;;; Depth-First Search.
(test)
Output:
Experiment No.2
;;; BESTFS.CL
;;; Best-First Search (Forward-Looking version).
;;; It uses an evaluation function based on the ordering of cities
;;; with respect to longitude. The method does not take into
;;; consideration the length of each partial path found so far.
;;; Thus it considers only the "remaining distance" to the goal
;;; in deciding how to order nodes on OPEN. Hence it is
;;; "forward-looking".
Output:
Experiment No.3
;;; ASTAR.CL
;;; A* Search for a shortest path.
;;; Here is the representation of the adjacency distance data,
;;; plus functions for getting at it and at solution path info.
;;; This code is identical to that in UNIFCOST.CL
(let ((distance-info (make-hash-table :size 20))
(path-predecessor-info (make-hash-table :size 20)) )
(defun set-distances (x y)
(setf (gethash x distance-info) y) )
(defun get-distances (x)
(gethash x distance-info) )
(defun set-predecessor (x y)
(setf (gethash x path-predecessor-info) y) )
(defun get-predecessor (x)
(gethash x path-predecessor-info) )
)
;;; Here are actual inter-city distances from the Michelin map:
(set-distances 'brest '((rennes . 244)))
(set-distances 'rennes '((caen . 176)(paris . 348)
(limoges . 313)))
(set-distances 'bordeaux '((limoges . 220)(toulouse . 253)
(nantes . 329)))
(set-distances 'limoges '((lyon . 389)(toulouse . 313)
(rennes . 107)))
(set-distances 'paris '((calais . 297)(nancy . 372)(dijon . 313)
Output:
Experiment No.4
AIM: Write A Lisp Program to solve Water Jug problem using Heuristic function.
Experiment No.5
#|--------------------------------------------------------------------
--------
TIC-TAC-TOE GAME
"tictactoe.lisp"
----------------------------------------------------------------------
------|#
#|--------------------------------------------------------------------
---------
----------------------------------------------------------------------------|#
(defun null-board ()
(list nil nil nil nil nil nil nil nil nil))
;; Function MOVEGEN takes a position and a player and generates all legal
;; successor positions, i.e., all possible moves a player could make.
Output:
Experiment No.6
;; Pop the top disk of the I'th tower in the HANOI configuration
(defun hanoi-tower-pop (hanoi i)
(hanoi-tower-update hanoi i (tower-pop (hanoi-tower hanoi i))))
Output:
Experiment No.7
;;; Our problem uses a graph whose nodes present cities and
;;; whose arcs carry distances, much as for the UNIFORM-COST
;;; search and A* programs.
(set-distances 'seattle
'((portland . 150)(spokane . 350)
(wenatchee . 100)(bellingham . 90) ) )
(set-distances 'portland
'((seattle . 150)(spokane . 400)
(wenatchee . 200)(bellingham . 235) ) )
(set-distances 'spokane
'((portland . 400)(seattle . 350)
(wenatchee . 275)(bellingham . 385) ) )
(set-distances 'wenatchee
'((portland . 200)(spokane . 275)
(seattle . 100)(bellingham . 130) ) )
(set-distances 'bellingham
'((portland . 235)(seattle . 90)
(spokane . 385)(wenatchee . 130) ) )
(defparameter *initial-population*
'( ((seattle seattle seattle seattle seattle) . 0) ) )
(defvar *population*)
(defvar *current-min-strength*)
(defvar *current-pop-size*)
(defun distance (a b)
"Returns the distance between cities A and B."
(if (eql a b) 0
(rest (assoc b (get-distances a))) ) )
;;; In CROSSOVER we assume that PATH1 and PATH2 are of the same length.
(defun crossover (individual1 individual2)
"Returns a new path resulting from
genetic crossover of PATH1 and PATH2."
(let* ((path1 (get-path individual1))
(path2 (get-path individual2))
(where (random (length path1))) )
(cons (append (left-part path1 where)
(right-part path2 where) )
0) ) )
(defun random-individual ()
"Returns a randomly selected member of the population."
(nth (random (length *population*)) *population*) )
(defun update-min-strength ()
"Computes and saves the minimum of all strengths of
current members of the population."
(setf *current-min-strength*
(apply #'min (mapcar #'get-strength *population*)) ) )
(defun test ()
"Does a trial run of EVOLVE."
(setf *population* *initial-population*)
(setf *current-min-strength* 0)
(setf *current-pop-size* 1)
(evolve 10 10 10) ; these values often lead to convergence at strength 4.78.
)
(test)
Output:
Experiment No.8
(defun up (8-puzzle)
(let* ((board (first 8-puzzle))
(path (second 8-puzzle))
(x (x-position 0 board))
(y (y-position 0 board))
(new-state (copy-board board)))
(unless (= y 2)
(setf (nth x (nth y new-state)) (nth x (nth (+ y 1) new-state)))
(setf (nth x (nth (+ y 1) new-state)) 0)
(list new-state (cons 'up path)))))
Output:
3