;; -*- Mode: Lisp; -*- ;;;; Utilities for debugging TGizmo ;;;; modified: Thursday, February 14, 2008 at 15:32:19 by forbus ;;; Copyright (c) 1991, Kenneth D. Forbus, Northwestern University ;;; and Johan de Kleer, the Xerox Corporation. ;;; All Rights Reserved. ;;; See the file legal.txt for a paragraph stating scope of permission ;;; and disclaimer of warranty. The above copyright notice and that ;;; paragraph must be included in any separate copy of this file. ;;;; File name: debug.lsp (in-package :cl-user) (defparameter *ex1* "ex1") (defparameter *ex2* "ex2") (defparameter *ex3* "ex3") (defvar *default-debugging* '(:psvs-dds :ir-dds)) (defun new (&optional (debugging t) (scenario-file *ex1*) (title "Test Gizmo")) (in-tgizmo (create-tgizmo title :debugging debugging)) (in-ltre (tgizmo-ltre *tgizmo*)) (bps-load-file *ltre-path* *set-rule-file*) (with-ltre *ltre* (bps-load-file *tgizmo-path* *tgizmo-laws-file*)) (with-ltre *ltre* (bps-load-file *tgizmo-path* *tgizmo-domain-file*)) (load-scenario scenario-file) *tgizmo*) (defun test-ex1 () (new nil *ex1*) (tg-run-rules) (find-states)) (defun test-ex1-2 () (new nil *ex1*) (assume! '(> (a ((amount-of water liquid) f)) zero) :ex1-test) (assume! '(> (a ((amount-of water liquid) g)) zero) :ex1-test) (assume! '(aligned p1) :ex1-test) (assume! '(> (a (pressure f)) (a (pressure g))) :ex1-test)) (defun test-ex2 () (new nil *ex2*) (tg-run-rules)(find-states)) (defun test-ex3 () ;; Check out ambiguous influences (new nil *ex3*) (assume! '(> (a ((amount-of water liquid) f)) zero) :ex3-test) (assume! '(> (a ((amount-of water liquid) g)) zero) :ex3-test) (assume! '(> (a ((amount-of water liquid) h)) zero) :ex3-test) (assume! '(aligned p1) :ex3-test) (assume! '(aligned p2) :ex3-test) (assume! '(> (a (pressure f)) (a (pressure g))) :ex3-test) (assume! '(> (a (pressure g)) (a (pressure h))) :ex3-test) (tg-run-rules)) (defun test-ex3-2 () ;; Check out ambiguous influences (new nil *ex3*) (assume! '(> (a ((amount-of water liquid) f)) zero) :ex3-test) (assume! '(> (a ((amount-of water liquid) g)) zero) :ex3-test) (assume! '(> (a ((amount-of water liquid) h)) zero) :ex3-test) (tg-run-rules)) ;;;; Measurement Interpretation examples (defvar *ex2-measurements* '((> (d ((amount-of water gas) can)) zero))) (defvar *ex3-measurements* '((> (a ((amount-of water liquid) f)) zero) (> (a ((amount-of water liquid) g)) zero) (> (a ((amount-of water liquid) h)) zero) (< (d ((amount-of water liquid) g)) zero))) (defvar *ex3-extra-measurements* '((> (a ((amount-of water liquid) f)) zero) (> (a ((amount-of water liquid) g)) zero) (> (a ((amount-of water liquid) h)) zero) (< (d ((amount-of water liquid) g)) zero) (< (d ((amount-of water liquid) f)) zero))) (defun tgizmo-shakedown (&aux result) (test-ex1) (unless (= 8 (setq result (length (tgizmo-states *tgizmo*)))) (warn "Example 1 failed. Should be 8 states, found ~D." result)) (format t "~% Passed Example 1.") (test-ex2) (unless (= 13 (setq result (length (tgizmo-states *tgizmo*)))) (warn "Example 1 failed. Should be 13 states, found ~D." result)) (format t "~% Passed Example 2.") (mi *ex3* *ex3-measurements* :debugging nil :title "Ex3, basic data") (unless (= 9 (setq result (length (tgizmo-states *tgizmo*)))) (warn "Example 3, basic measurements, failed. Should be 9, was ~D." result)) (format t "~% Passed Example 3 basic.") (mi *ex3* *ex3-extra-measurements* :debugging nil :title "Ex3 test -- More data") (unless (= 3 (setq result (length (tgizmo-states *tgizmo*)))) (warn "Example 3, extra measurements, failed. Should be 3, was ~D." result)) (format t "~% Passed Example 3 extra.") (format t "~% TGizmo seems okay.") t)