# Encoding hydraulic-leaking_decision.gringo

Name hydraulic-leaking_decision.gringo [Root]    Unclassified (114)    Hydraulic System (8)    Hydraulic Leaking (3) Martin Gebser Martin Gebser and Roland Kaminski A Gringo encoding of Hydraulic Leaking. (No search needed) 2009-03-22 16:17 2009-06-03 21:00 Hydraulic Leaking full/1goal/1jet/1junction/1leaking/1link/3numValves/1tank/1valve/1 switchon/2 No ASP Contest 09 (Martin Gebser)No Search (Martin Gebser) leak(0..L) :- L = { leaking(V) : leaking(V) }. relay(I) :- link(J,I,V1), link(I,K,V2), J != K. step(0..S+1) :- S = { relay(I) : relay(I) : not goal(I) }. leaky(0..N) :- N = min [ step(S) : step(S) : not step(S+1) = S, leak(L) : leak(L) : not leak(L+1) = L ]. reach(I,0,0) :- goal(I). reach(I,N,M) :- link(I,J,V), reach(J,N, M-1), leaky(N), step(M), not leaking(V). reach(I,N,M) :- link(I,J,V), reach(J,N-1,M-1), leaky(N), step(M), leaking(V). done(L) :- L = min [ reach(I,N,M) : reach(I,N,M) : full(I) = N ]. done(L,S) :- S = min [ reach(I,L,M) : reach(I,L,M) : full(I) = M ], done(L). % :- not done(L) : leaky(L). done :- reach(I,N,M), full(I). :- not done. forth(I,0, 0) :- done(L,S), reach(I,L,S), full(I), not reach(J,L,S) : full(J) : J < I. forth(J,NI, S-M) :- done(L,S), reach(J,NJ,M), forth(I,NI,S-(M+1)), NI = L-NJ, link(I,J,V), not leaking(V). forth(J,NI+1,S-M) :- done(L,S), reach(J,NJ,M), forth(I,NI,S-(M+1)), NI = L-(NJ+1), link(I,J,V), leaking(V). switchon(V,0) :- forth(I,0, 0), forth(J,0, 1), link(I,J,V), not leaking(V), not link(I,JJ,VV) : forth(JJ,0,1) : not leaking(VV) : VV < V : link(I,JJ,VV). switchon(V,0) :- forth(I,0, 0), forth(J,1, 1), link(I,J,V), leaking(V), not link(I,JJ,VV) : forth(JJ,1,1) : leaking(VV) : VV < V, not link(I,KK,WW) : forth(KK,0,1) : not leaking(WW) : link(I,KK,WW). switchon(V,M) :- forth(I,NI,M), forth(J,NI, M+1), link(I,J,V), not leaking(V), switchon(W,M-1), link(K,I,W), not link(I,JJ,VV) : forth(JJ,NI, M+1) : not leaking(VV) : VV < V : link(I,JJ,VV). switchon(V,M) :- forth(I,NI,M), forth(J,NI+1,M+1), link(I,J,V), leaking(V), switchon(W,M-1), link(K,I,W), not link(I,JJ,VV) : forth(JJ,NI+1,M+1) : leaking(VV) : VV < V, not link(I,KK,WW) : forth(KK,NI, M+1) : not leaking(WW) : link(I,KK,WW). #hide. #show switchon(V,N).