initial
This commit is contained in:
@@ -1,2 +1,4 @@
|
|||||||
# knapsack
|
# knapsack
|
||||||
A solver for the knapsack problem in Prolog (Eclipse CSP)
|
|
||||||
|
A solver for the knapsack problem in Eclipse CSP-flavoured Prolog.
|
||||||
|
Nothing too fancy. Have fun!
|
||||||
|
20
knapsack.ecl
Normal file
20
knapsack.ecl
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
:-lib(fd).
|
||||||
|
:-lib(fd_global).
|
||||||
|
:-lib(branch_and_bound).
|
||||||
|
|
||||||
|
knapsack(P, W, C, T, V) :-
|
||||||
|
length(P, N),
|
||||||
|
length(V, N),
|
||||||
|
minlist(W, Min),
|
||||||
|
D is C // Min,
|
||||||
|
V::0..D,
|
||||||
|
C #>= W*V,
|
||||||
|
T #= P*V,
|
||||||
|
sumlist(V, S),
|
||||||
|
O #= (-1)*T,
|
||||||
|
Negs #= (-1)*T,
|
||||||
|
bb_min(labeling(V), O, V, _, _, _),
|
||||||
|
bb_min(labeling(V), Negs, _).
|
||||||
|
|
||||||
|
test(P, V):-
|
||||||
|
knapsack([60, 100, 120], [15, 20, 30], 325, P, V).
|
Reference in New Issue
Block a user