% Knapsack benchmark; adopted from: % % A. Dovier, A. Formisano, and E. Pontelli: % "A Comparison of CLP(FD) and ASP Solutions to NP-complete Problems" % in Convegno Italiano di Logica Computazionale, June 2005. #option -dnone item(1..10). #weight size(1,X1)=2*X1. #weight size(2,X2)=4*X2. #weight size(3,X3)=8*X3. #weight size(4,X4)=16*X4. #weight size(5,X5)=32*X5. #weight size(6,X6)=64*X6. #weight size(7,X7)=128*X7. #weight size(8,X8)=256*X8. #weight size(9,X9)=512*X9. #weight size(10,X10)=1024*X10. #weight cost(1,X1)=2*X1. #weight cost(2,X2)=5*X2. #weight cost(3,X3)=11*X3. #weight cost(4,X4)=23*X4. #weight cost(5,X5)=47*X5. #weight cost(6,X6)=95*X6. #weight cost(7,X7)=191*X7. #weight cost(8,X8)=383*X8. #weight cost(9,X9)=767*X9. #weight cost(10,X10)=1535*X10. occs(0..max_size). 1 { in_sack(I,XI):occs(XI) } 1 :- item(I). size(I,XI) :- item(I), occs(XI), in_sack(I,XI). cost(I,XI) :- item(I), occs(XI), in_sack(I,XI). cond_cost :- min_profit [ cost(I,XI):item(I):occs(XI) ]. :- not cond_cost. cond_weight :- [ size(I,XI):item(I):occs(XI) ] max_size. :- not cond_weight. #hide cond_weight, cond_cost. #hide item(I). #hide occs(X). #hide size(I,S). #hide cost(I,C).