Providing Services to
World Wide

Mail Us
khizarshahal3@gmail.com

Contact Us
+92 3472506073

Blog Post Details

Home / Free Services / Blog Posts / Blog Post Details

CS607P Assignment # 02 Spring 2026

June 25, 2026

Copy Paste this code into Notepad file .txt then submit on LMS only .txt file

Code Examples

clips
(deftemplate traffic
   (slot road)
   (slot level))

(deftemplate emergency
   (slot status))

(deftemplate system-control
   (slot status))

(deftemplate user-choice
   (slot value))

(deffacts start-system
   (system-control (status menu)))

(deffunction print-line ()
   (printout t "--------------------------------------------------" crlf))

(deffunction show-output (?title ?action)
   (printout t crlf)
   (print-line)
   (printout t ?title crlf)
   (printout t "Action: " ?action crlf)
   (print-line)
   (printout t crlf))

(deffunction show-menu ()
   (printout t crlf)
   (printout t "========= TRAFFIC SIGNAL CONTROL SYSTEM =========" crlf)
   (printout t "1. Emergency vehicle approaching" crlf)
   (printout t "2. Traffic heavy on East-West Road" crlf)
   (printout t "3. Traffic heavy on North-South Road" crlf)
   (printout t "4. Normal traffic processing" crlf)
   (printout t "5. Exit" crlf)
   (printout t "Enter your choice: "))

(deffunction show-developer-info ()
   (printout t crlf)
   (printout t "Thanks for using Traffic Signal Control System." crlf)
   (printout t "Developed By KST Learning (BC123456789)" crlf))

(defrule show-main-menu
   ?s <- (system-control (status menu))
   =>
   (retract ?s)
   (show-menu)
   (bind ?choice (read))
   (assert (user-choice (value ?choice))))

(defrule select-emergency-vehicle
   ?c <- (user-choice (value 1))
   =>
   (retract ?c)
   (assert (emergency (status approaching))))

(defrule select-heavy-east-west
   ?c <- (user-choice (value 2))
   =>
   (retract ?c)
   (assert (traffic (road east-west) (level heavy))))

(defrule select-heavy-north-south
   ?c <- (user-choice (value 3))
   =>
   (retract ?c)
   (assert (traffic (road north-south) (level heavy))))

(defrule select-normal-traffic
   ?c <- (user-choice (value 4))
   =>
   (retract ?c)
   (assert (traffic (road east-west) (level moderate)))
   (assert (traffic (road north-south) (level moderate))))

(defrule exit-program
   ?c <- (user-choice (value 5))
   =>
   (retract ?c)
   (show-developer-info))

(defrule invalid-choice
   ?c <- (user-choice (value ?v&~1&~2&~3&~4&~5))
   =>
   (retract ?c)
   (show-output "INVALID CHOICE" "Please select a valid option from 1 to 5.")
   (assert (system-control (status menu))))

(defrule emergency-vehicle-approaching
   ?e <- (emergency (status approaching))
   =>
   (show-output "EMERGENCY VEHICLE APPROACHING" "Turn ALL signals RED. Allow emergency vehicle to pass.")
   (retract ?e)
   (assert (system-control (status menu))))

(defrule heavy-traffic-east-west
   ?t <- (traffic (road east-west) (level heavy))
   =>
   (show-output "Traffic heavy on East-West Road" "Give priority to EAST-WEST signal.")
   (retract ?t)
   (assert (system-control (status menu))))

(defrule heavy-traffic-north-south
   ?t <- (traffic (road north-south) (level heavy))
   =>
   (show-output "Traffic heavy on North-South Road" "Give priority to NORTH-SOUTH signal.")
   (retract ?t)
   (assert (system-control (status menu))))

(defrule moderate-traffic-both-roads
   ?t1 <- (traffic (road east-west) (level moderate))
   ?t2 <- (traffic (road north-south) (level moderate))
   =>
   (show-output "Moderate traffic on both Roads" "Alternate signals every 30 seconds.")
   (retract ?t1 ?t2)
   (assert (system-control (status menu))))