% graph nodes node(N) :- jet(N). node(N) :- junction(N). node(N) :- tank(N). % useable links are those without stuck valves useablelink(N1,N2,V) :- link(N1,N2,V), not stuck(V). % lengths of useable paths (ie w/o stuck valves) to goal, bounded by % the number of valves dist(J,0) :- goal(J). dist(N,DN) :- dist(K,DK), useablelink(N,K,Fv1), DN=DK+1, numValves(NV), DN <= NV. % minimum distance of a node to the goal node nodemindist(N,DN) :- node(N), dist(N,DN), not existDnLessThan(N,DN). existDnLessThan(N,DN) :- dist(N,DN), dist(N,DN1), DN1 N2. smallestnodeforvalve(N1,D1) :- smallestvalve(V,D1), reached(N,D), D1=D-1, useablelink(N,N1,V), not nsmallestnodeforvalve(N1,D1). reached(N,D) :- smallestnodeforvalve(N,D).