Question
Prolog: Write predicate path(A, B, Graph, Path, TotalWeight) in Prolog that is true if and only if Path is a list of vertices comprising a
Prolog: Write predicate path(A, B, Graph, Path, TotalWeight) in Prolog that is true if and only if Path is a list of vertices comprising a path from vertex A to vertex B in the given weighted directed Graph such that the sum of the weight of the edges in the path does not exceed the given TotalWeight. An example of a directed weighted graph is graph([[a,b,1], [b,c,2], [c,b,1], [b,a,5], [c,d,2], [b,w,2], [w,x,3], [x,z,2] , [b,z,5]]). Notice that the graph is represented as a list of sub-lists, where [x, y, w] indicates that there is an edge from vertex x to vertex y with weight w. Make sure to use the built-in function member(X, Y).
The base case is path(A, A, _, [A], Z) :- Z >= 0.
The next and only line should start with path(A, B, Graph, [X | Rest], TotalWeight) :-
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started