Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 6(25 pts) Graphs in Prolog The Purpose of this question is to write a Prolog Program which describes a directed graph (G), with the

image text in transcribedimage text in transcribed

Question 6(25 pts) Graphs in Prolog The Purpose of this question is to write a Prolog Program which describes a directed graph (G), with the following structure and allows us to ask some questions about this graph. 2) Complete the definition for all these rules parent(X,Y) :-% There is a directed edge from X to Y child(X,Y) :. % Y is parent of X. path(X,Y)-% find a directed path from node X to node Y path(X,Y,Z):-% find a directed path from node X to Y and store in Z. length-of-path(X,Y, Z):-% Z is Length of a path (directed) from X to Y connected(X,Y):-% There is a directed path from X to Y, or from Y to X undirected edge(X,Y):-/*There is an edge (ignoring the directions) from X to Y or from Y to X* undirected path(X,Y)find a path (ignoring the directions) from node X to node Y. * Important Note: There are circles in this graph including nodes some nodes such as: e, f, g. You should find a way to avoid infinite recursion by making sure that you visit each node along your paths once 3) Create a knowledge base (KB) composed of all the facts and rules that you have written in parts (1), and (2), and save it in a prolog program file called "my grapghG.pl", and show a print of your program here. 4) Run this Prolog program, and write 4 queries about each of those rules that you have created in part (2) in order to test those rules, and show your queries and their results, and test the correctness of your results. (Note: you should write and test two ground quires (one with positive and one with negative answer) and two non-ground quires for each of the rules that you have created in Part B.) 5) Add the following rule to your program, and test it and describe its function. tpath(Nodel.Node2):-edge(Node1, SomeNode), edge(SomeNode,Node2)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions