Prolog A Production System Example.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 2
Algorithmic Problem Solving Lecture 3 River Crossing Problems.
Min terms and logic expression
Problem Solving Well-formed predicate calculus expressions provide a means of describing objects and relations in a problem domain and inference rule.
1 SE-561 Formal Methods in Software Petri Nets - I.
1 CS 385 Fall 2006 Chapter 15 Introduction to PROLOG.
Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search.
CSC 423 ARTIFICIAL INTELLIGENCE
SEARCH ALGORITHMS David Kauchak CS30 – Spring 2015.
FATIH UNIVERSITY Department of Computer Engineering Input and Output Notes for Ch.6 of Bratko For CENG 421 Fall03.
Module 1- Getting Started Tell me what to do Using sets of instructions…
Chapter Two: Finite Automata
Graphs and Trees This handout: Total degree of a graph Applications of Graphs.
Module 1- Getting Started Tell me what to do Using sets of instructions…
Building Control Algorithms For State Space Search
Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.
WHAT IS ARTIFICIAL INTELLIGENCE?
Lecture 24 Farmer, Goat, Cabbage and Wolf Problem Continued 1 The “Russian Farmer” Problem Continued.
State Spaces Introduction to Artificial Intelligence Dr. Robin Burke.
Boolean Algebra Lecture 7: Supporting Material Dr Kathryn Merrick Tuesday 24 th March, 2009.
Listening: Riddle Goal, Wolf & Cabbage. Riddle – River Crossing GOAT, WOLF & CABBAGE A farmer is going home from the market. He bought a goat, a cabbage.
Control Algorithms 2 Chapter 6 Control Algorithms 2 Chapter 6 Production Systems.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Blind State-Space Search Notes for Ch.11 of Bratko For CSCE 580 Sp03 Marco.
State-Space Searches. State spaces A state space consists of –A (possibly infinite) set of states The start state represents the initial problem Each.
Toy Problem: Missionaries and Cannibals
Problem solving by Searching Problem Formulation.
Artificial Intelligence Problem solving by searching CSC 361 Prof. Mohamed Batouche Computer Science Department CCIS – King Saud University Riyadh, Saudi.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
CSC411Artificial Intelligence1 Chapter 15 An Introduction to PROLOG Syntax for Predicate Calculus Abstract Data Types (ADTs) in PROLOG A Production System.
Dr Eleni Mangina – COURSE: LOGIC PROGRAMMING (during a joint degree with Fudan University in Software Engineering) DEPT. OF COMPUTER SCIENCE UCD Problem.
Artificial Intelligence Problem solving by searching CSC 361
Problem solving in state spaces State representation and the problem solving agent algorithm.
Graphs and Trees This handout: Terminology of Graphs Applications of Graphs.
Artificial Intelligence Problem solving by searching CSC 361 Prof. Mohamed Batouche Computer Science Department CCIS – King Saud University Riyadh, Saudi.
State-Space Searches.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title: Overview of Data Structure.
Chapter 18 - basic definitions - binary trees - tree traversals Intro. to Trees 1CSCI 3333 Data Structures.
1 State Space of a Problem Lecture 03 ITS033 – Programming & Algorithms Asst. Prof.
Lists – More Examples  ‘Translate’ a list to another list  Counting  Split a given list into two  Merge two lists into one  Output a list (some I/O.
Module 1- Getting Started Tell me what to do Using sets of instructions…
Knowledge and search, page 1 CSI 4106, Winter 2005 Knowledge and search Points Properties of knowledge  Completeness  Objectivity  Certainty  Formalizability.
Revision at the Beginning of the 2 nd Semester (repeated slides) Small Coursework (40%) – Please complete it asap Go to:
Please snarf the code for today’s class. Then think about the famous 8-Queen’s Puzzle. The question is: is there a way to arrange 8 queens on a (8x8) chessboard.
ALGEBRA II ARITHMETIC & GEOMETRIC MEANS.
Control Algorithms 2 Chapter 6 Control Algorithms 2 Chapter 6 Production Systems.
Prolog Cut to Control Search Abstract Data Types Practical Examples Summary.
Chapter 12 Abstract Data Type. Understand the concept of an abstract data type (ADT). Understand the concept of a linear list as well as its operations.
KU NLP Artificial Intelligence1 Ch 14. An Introduction to Prolog q an Implementation of logic as a programming language(PROgramming in LOGig) q many interesting.
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
Stack. ADS2 Lecture 1010 The Stack ADT (GoTa §5.1) The Stack ADT stores arbitrary objects Insertions and deletions follow the last-in.
Prolog Overview Syntax Mechanism Summary. Overview PROLOG : Programming with Logic Uses predicate (first-order) calculus History: Roots: J.A. Robinson.
A Historical Example One of the most famous problems in graph theory is the bridges of Konigsberg Can you cross every bridge exactly once and come back.
ARTIFICIAL INTELLIGENCE
Friend Function.
The Decision-making Process
Breadth First and Depth First
Problem solving by Searching
Some problems Cse-402 K3r20,k3r23.
Introducing A Challenge Box
Chapter Two: Finite Automata
Iterative Deepening Search
The Wolf, the Goat, and the Cabbage
Artificial Intelligence Problem solving by searching CSC 361
4. Computational Problem Solving
Some problems Cse-402 K3r20,k3r23.
Problem Solving by Searching Search Methods :
Overview Analysis Notation Specific ADTs
ARTIFICIAL INTELLIGENCE
Problem Solving by Searching Search Methods :
Presentation transcript:

Prolog A Production System Example

The Farmer-Wolf-Goat-Cabbage Problem Elements: farmer,wolf,goat and the cabbage. They have to cross a river and there are some restrictions. The boat can carry two things only The wolf cannot be left alone with the goat The goat cannot be left alone with the cabbage Devise a sequence of moves to transport all elements to the other side of the river.

Figure 14.1

Figure 14.2

Code Start /* * This is the code for the Farmer, Wolf, Goat and Cabbage Problem * using the ADT Stack. * * go(state(w,w,w,w), state(e,e,e,e)). */ :- [adts]. /* consults (reconsults) file containing the various ADTs (Stack, Queue, etc.) */ go(Start,Goal) :- empty_stack(Empty_been_stack), stack(Start,Empty_been_stack,Been_stack), path(Start,Goal,Been_stack).

Code Path /* * Path predicates */ path(Goal,Goal,Been_stack) :- write('Solution Path Is:' ), nl, reverse_print_stack(Been_stack). path(State,Goal,Been_stack) :- move(State,Next_state), not(member_stack(Next_state,Been_stack)), stack(Next_state,Been_stack,New_been_stack), path(Next_state,Goal,New_been_stack),!.

Code Move /* * Move predicates */ move(state(X,X,G,C), state(Y,Y,G,C)) :- opp(X,Y), not(unsafe(state(Y,Y,G,C))), writelist(['try farmer takes wolf',Y,Y,G,C]). move(state(X,W,X,C), state(Y,W,Y,C)) :- opp(X,Y), not(unsafe(state(Y,W,Y,C))), writelist(['try farmer takes goat',Y,W,Y,C]). move(state(X,W,G,X), state(Y,W,G,Y)) :- opp(X,Y), not(unsafe(state(Y,W,G,Y))), writelist(['try farmer takes cabbage',Y,W,G,Y]).

Code Move move(state(X,W,G,C), state(Y,W,G,C)) :- opp(X,Y), not(unsafe(state(Y,W,G,C))), writelist(['try farmer takes self',Y,W,G,C]). move(state(F,W,G,C), state(F,W,G,C)) :- writelist([' BACKTRACK from:',F,W,G,C]), fail.

Code Unsafe /* * Unsafe predicates */ unsafe(state(X,Y,Y,C)) :- opp(X,Y). unsafe(state(X,W,Y,Y)) :- opp(X,Y).

Code writelist and opp /* * Definitions of writelist, and opp. */ writelist([]) :- nl. writelist([H|T]):- print(H), tab(1), /* "tab(n)" skips n spaces. */ writelist(T). opp(e,w). opp(w,e). reverse_print_stack(S) :- empty_stack(S). stack(E, Rest, S), reverse_print_stack(Rest), write(E), nl.

Results Try farmer takes goat e w e w Solution Try farmer takes self w w e w Try farmer takes wolf e e e w Try farmer takes goat w e w w Try farmer takes cabbage e e w e Try farmer takes wolf w w w e Try farmer takes goat e w e e BACKTRACK from e w e e BACKTRACK from w w w e Try farmer takes self w e w e Try farmer takes goat e e e e Solution state(w,w,w,w) state(e,w,e,w) state( w w e w state(e,e,e,w) state(w,e,w,w) state(e,e,w,e) state(w,e,w,e) state(e,e,e,e)