# Encoding checkdepots.dlv

Name checkdepots.dlv [Root]    Unclassified (114)    Fastfood (5) Martin Gebser Wolfgang Faber This program checks whether a depot allocation has minimal supply costs among all depot allocations of the same cardinality. Input predicates: restaurant(Name,Km), depot(Name,Km) Output predicates: altdepot(Name,Km) Author: Wolfgang Faber <> License: GNU Public License, http://www.gnu.org/licenses/gpl.html 2009-03-30 13:03 2009-03-12 22:47 Decision Version of Fastfood depot/2restaurant/2 altdepot/2 No % This program checks whether a depot allocation has minimal supply % costs among all depot allocations of the same cardinality. % % Input predicates: % restaurant(Name,Km), depot(Name,Km) % Output predicates: % altdepot(Name,Km) % % Author: Wolfgang Faber % License: GNU Public License, http://www.gnu.org/licenses/gpl.html % Maximum distance from a depot to a restaurant. #maxint=910. % Auxiliary predicate: All distances between restaurant locations. distance(X,L,Y):- restaurant(_,X), restaurant(_,L), X>L, X=L+Y. distance(X,L,Y):- restaurant(_,X), restaurant(_,L), X<=L, L=X+Y. % The supply distance for each restaurant for the candidate solution % in the input. serves(Rname,Dist) :- restaurant(Rname,RK), depot(Dname,DK), distance(RK,DK,Dist), Dist = #min {Y : depot(Dname1,DK1), distance(DK1,RK,Y) }. % Each restaurant may be an alternative depot or not. altdepot(R,K) v naltdepot(R,K) :- restaurant(R,K). % The number of alternative depots must be equal to the number of depots in % the input. :- #count{D,K: depot(D,K)} = N, #count{D,K: altdepot(D,K)} > N. :- #count{D,K: depot(D,K)} = N, #count{D,K: altdepot(D,K)} < N. % The supply distance for each restaurant for the alternative solution. altserves(Rname,Dist) :- restaurant(Rname,RK), altdepot(Dname,DK), distance(RK,DK,Dist), Dist = #min {Y : altdepot(Dname1,DK1), distance(DK1,RK,Y) }. % Accept an alternative solution only if its supply costs are less % than the supply costs for the input candidate. :- #sum{Dist,R : serves(R,Dist)} = Cost, #sum{Dist,R : altserves(R,Dist)} >= Cost.