-1

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.

DuDa
  • 3,718
  • 4
  • 16
  • 36

1 Answers1

0
total(N) :- N = #sum {W,X,Y : pick(X,Y), weight(X,Y,W); W,X,Z : pick(X,Z), weight(X,Z,W) }.
  • 1
    X,Y mean two vertex and W means their weight. I want to choose k-1 vertex and the sum of these vertex(N) is less than M. The output of above instance should have 3 answers, but I could only have one. – Mitchell Chen Nov 10 '20 at 01:37