Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a Prolog Program which describes a directed graph (G) (shown below) A) write all possible node and edge facts that describes the structure of

write a Prolog Program which describes a directed graph (G) (shown below)

image text in transcribed

A) write all possible node and edge facts that describes the structure of this graph G such as below:

node( a ). % a is a node of this graph.

edge( a, b ). % There is an edge (directed) from node a to b.

B) complete the definition all these rules.

node(X) :- % X is a node in graph G

edge( X, Y) :- % There is an directed edge from X to Y.

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.

length_of_path( X, Y):- % 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. */

This is what I have

node(a). node(b). node(c). node(d). node(e). node(f). node(g). node(h).

edge(a,b). edge(b,c). edge(c,a). edge(c,e). edge(c,d). edge(d,e). edge(d,h). edge(e,f). edge(e,g). edge(f,g). edge(g,e).

node(X):- node(X).

edge(X,Y):- node(X),node(Y),edge(X,Y).

parent(X,Y):- node(X),node(Y), edge(X,Y).

child(X,Y):- node(X), node(Y), edge(Y,X).

Not sure if what I wrote is correct and not sure how to continue the other rules.

e a C

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

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

=+What benefits are there in direct mail?

Answered: 1 week ago