I have the following dataset:
vertex ( v1 ). vertex ( v2 ). vertex ( v3 ).
vertex ( v4 ). vertex ( v5 ). vertex ( v6 ).
vertex ( v7 ). vertex ( v8 ). vertex ( v9 ).
weight ( v1 , v2 ,3). weight ( v1 , v3 ,3).
weight ( v2 , v4 ,1). weight ( v2 , v5 ,5).
weight ( v3 , v4 ,3). weight ( v3 , v6 ,4).
weight ( v4 , v5 ,4). weight ( v4 , v7 ,1).
weight ( v5 , v7 ,7). weight ( v6 , v7 ,2).
weight ( v6 , v8 ,2). weight ( v7 , v9 ,3).
weight ( v8 , v9 ,2).
target (4).
threshold (4).
I want to meet the constraints:
choose N-1 vertex(target(N))
and the sum
of their weight
should be less than M(threshold(M))
. Output all satisfiable conditions. I coeded the following codes:
%rule
(A-1) {pick(X, Y) : weight(X, Y, W)} (B-1) :- target(A), target(B).
total(N) :- N = #sum {W : pick(X,Y),weight(X,Y,W)}
% limit total weight
:- total(N),threshold(M), N > M.
#show pick/2.
but the result is only one, in fact, it should have several answers.
I do not know the reason.