-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathindependent.pl
31 lines (24 loc) · 974 Bytes
/
independent.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
:- use_module(library(clpb)).
:- use_module(library(lists)).
:- use_module(library(assoc)).
:- use_module(library(pairs)).
:- use_module(library(time)).
:- use_module(library(format)).
:- use_module(edges).
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Independent set:
IND(X) = not OR_(u->v){ x_u /\ x_v } = AND_(u->v){not x_u \/ not x_v}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
%?- independent_set(Sat), time(sat_count(Sat, Count)).
%@ % CPU time: 3.809s
%@ Sat = *(...), Count = 211954906.
independent_set(*(NBs)) :-
findall(U-V, edge(U, V), Edges),
findall(U, (member(U-V, Edges);member(V-U, Edges)), Nodes0),
sort(Nodes0, Nodes),
pairs_keys_values(Pairs, Nodes, _),
list_to_assoc(Pairs, Assoc),
maplist(not_both(Assoc), Edges, NBs).
not_both(Assoc, U-V, ~BU + ~BV) :-
get_assoc(U, Assoc, BU),
get_assoc(V, Assoc, BV).