;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Path (C) 1997 David Wallace Croft ;; 1997-11-30 ;; Language: Java Expert System Shell (JESS) CLIPS variant ;; ;; Finds a path along a one-dimensional line with the ends joined. ;; Does not necessarily find the minimum path. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ( watch all ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( defrule take_path_rule ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ?goal_fact <- ( goal ?goal ) ?state_fact <- ( state ?state ) ( path ?state ?goal ) ( not ( stop ?state ) ) ( not ( closed ?goal ) ) => ( retract ?state_fact ?goal_fact ) ( assert ( state ?goal ) ( closed ?goal ) ( closed ?state ) ) ( printout t "Transitioning from " ?state " to " ?goal crlf ) ) ( defrule find_path_rule ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( state ?state ) ?goal_fact <- ( goal ?goal&~?state ) ( not ( path ?state ?goal ) ) ( path ?newgoal ?goal ) ( not ( goal ?newgoal ) ) ( not ( stop ?state ) ) ( not ( closed ?newgoal ) ) => ( assert ( goal ?newgoal ) ) ( printout t "Creating subgoal of " ?newgoal " to get to " ?goal crlf ) ) ( defrule make_goal_rule ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( start ?start ) ( stop ?stop ) ( not ( goal ?goal ) ) ( not ( state ?state ) ) => ( assert ( state ?start ) ( goal ?stop ) ) ( printout t "Starting state: " ?start " Goal: " ?stop crlf ) ) ( defrule goal_stop_rule ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( stop ?stop ) ( state ?stop ) ( start ?start ) => ( printout t "Final goal of " ?stop " has been reached from " ?start crlf ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( deffacts goalinit ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( start 3 ) ( stop 6 ) ( path 10 0 ) ( path 0 1 ) ( path 1 2 ) ( path 2 3 ) ( path 3 4 ) ( path 4 5 ) ( path 5 6 ) ( path 6 7 ) ( path 7 8 ) ( path 8 9 ) ( path 9 10 ) ( path 0 10 ) ( path 10 9 ) ( path 9 8 ) ( path 8 7 ) ( path 7 6 ) ( path 6 5 ) ( path 5 4 ) ( path 4 3 ) ( path 3 2 ) ( path 2 1 ) ( path 1 0 ) ( path 0 1 ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( reset ) ( run ) ; ( facts )