Question: write using prolog starter code below Write predicate path(Start, End, Graph, Path, Budget) that is true if and only if Path is a list of

write using prolog write using prolog starter code below Write predicate path(Start, End, Graph, Path,
Budget) that is true if and only if Path is a list
starter code below

Write predicate path(Start, End, Graph, Path, Budget) that is true if and only if Path is a list of vertices comprising a path from vertex Start to vertex End in the given weighted directed Graph such that the sum of the costs of the edges in the path does not exceed the given Budget. Let's break that down! First, here's an example of a directed weighted graph. Notice that the graph is represented as a list of triples where a triple (x, y, w] indicates that there is an edge from vertex x to vertex y with weight w. (Note: member (X, Y) is built-in to Prolog. It is true if and only if item X is a member of list Y.) 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,2,5] ] ). The weights will always be positive integers. The graph can have cycles as in this example (e.g., an edge from a to b and an edge from b to a). Moreover, the path from start to end need not be "simple"; that is, it may visit some vertices multiple times. Here are a few examples: 7 graph(c). patha, 2, G. P. 5). false. There is no path free ato of cost 5 or less G 7 graph(a), patha, 2, GP. 6). l a. 1). Db, c, 2). le, , 1). b, a, 5). le, d, 2). D. , 23. v, zl...). Exl...). [......]). P .b. 2) I The path a, b, coats 6, so it's within budget. Any sore? false 7 graph (G). patha,2, GP. 8). G. , D, 1). DD. c. 2). c. b. 1). b. a. 5). Is. d. 2). D. v. 2). w. x...). x...). [......]). - Lab, W, X, I any more? - [la, , 1). t. c. 2). le., 1, a, ). I, d. 2). t. w. 2). [w, al...). Ex...).......]]. a, b, a wysore? P G graph ), patha, P. 10). l a ), 1). D. c. 2). Ie, , :). , . 5). le, d. 2). . . 2). [w, ul...). Exl...). ......)). P . , C. , 2) : I my more? G- , , :). t. c. 2). .. 1). th., 5). Is. d. 23. , , 2). Iw, ...). Ex...). [......]]. P. , W, X, Iany more! c. [ .). Do, C, 2). I, 1, 1). . . 5). Ic. c. 21. D. , 23. v. xl...). xl...). C......)). a., 2) Iany more %% BASE CASE - STARTER CODE path(X, X, [X], K) :- K >= 0. %%%%%%%%%%%%% %% YOUR TURN! path(X, Y, Graph, [X | Rest], Budget) :- fail. % = 0. %%%%%%%%%%%%% %% YOUR TURN! path(X, Y, Graph, [X | Rest], Budget) :- fail. %

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!