Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Complete this PROLOG program to find a path on the map in Figure 3.2 between any pair of cities. Be sure the path you find
Complete this PROLOG program to find a path on the map in Figure 3.2 between any pair of cities. Be sure the path you find is acyclic, i.e., has no loops like [a,s,r,p,c,s,r,b]. adjacent(a,t). adjacent(a,s). adjacent(a,z). adjacent(s,o). adjacent(s,f). adjacent(s,r). adjacent(o,a). adjacent(f,b). adjacent(r,p). adjacent(p,b). %path(P,Start,Goal) means P is a path from Start to Goal path([X,Y],X,Y):-adjacent(X,Y). path([X,Y],X,Y):-adjacent(Y,X). path([Goal],Goal,Goal). path([Start|[Head|Tail]],Start,Goal):-adjacent(Start,Head),path([Head|Tail],Head,Goal). Name your program PATH.pl. Hint: PROLOG checks predicates in order, so choose the order carefully.
Oradea Neamt 87 Zerind 151 75 Iasi Arad 140 92 Sibiu Fagaras 118 Vaslui 80 Rimnicu Vilcea Timisoara 142 211 Pitesti Lugoj 97 70 98 Hirsova Mehadia 146 101 85 Urziceni 86 75 138 Bucharest Drobeta 120 90 Craiova Eforie Giurgiu Figure 3.2 A simplified road map of part of Romania Oradea Neamt 87 Zerind 151 75 Iasi Arad 140 92 Sibiu Fagaras 118 Vaslui 80 Rimnicu Vilcea Timisoara 142 211 Pitesti Lugoj 97 70 98 Hirsova Mehadia 146 101 85 Urziceni 86 75 138 Bucharest Drobeta 120 90 Craiova Eforie Giurgiu Figure 3.2 A simplified road map of part of Romania
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