1+ # # Solving independent set for a weighted unit disk graph
2+ using GraphTensorNetworks, Graphs
3+
4+ # This example shows how to check the MIS degeneracy (another way of saying counting) of a weight unit disk graph.
5+ # Let us construct a unit disk graph by specifying the locations of nodes, the unit disk radius is 1.5,
6+ # which means two vertices within distance 1.5 are connected.
7+ # For each vertex, we assign a weight to it.
8+ locations = [(6 ,- 3 ),(1 , - 1 ), (0 ,0 ), (6 ,- 2 ), (1 ,1 ), (2 ,0 ),
9+ (2 ,2 ), (2 ,- 2 ), (3 ,1 ), (3 ,- 2 ), (4 ,1 ), (4 ,- 1 ),
10+ (5 , 1 ), (5 , - 1 ), (6 ,0 ), (6 ,- 1 ), (7 ,- 1 ), (7 , - 4 ),
11+ (8 , - 2 ), (8 , - 4 ), (9 ,- 3 )]
12+
13+
14+ weights = [0.7439015222121296 , 0.722970984162338 ,
15+ 0.9502792990276312 , 0.6617352332568173 ,
16+ 0.8592866066961992 , 1.0 , 1.0 , 1.0 , 1.0 ,
17+ 1.0 , 1.0 , 1.0 , 1.0 , 1.0 , 1.0 , 1.0 ,
18+ 1.0 , 1.0 , 1.0 , 1.0 , 1.0 ]
19+
20+ graph = unit_disk_graph (locations, 1.5 )
21+
22+ show_graph (graph; locs= locations)
23+
24+ # ## Find the best configurations
25+ # We can easily check the MIS degeneracy by computing the [`CountingMax`](@ref) property.
26+ counting_mapped = solve (IndependentSet (graph; weights= weights), CountingMax ())[]
27+
28+ # The MIS degeneracy is the second field, which is 3.
29+ # We can compute the [`ConfigsMax`](@ref) to enumerate all configurations with maximum independent set size.
30+
31+ configs_mapped = solve (IndependentSet (graph; weights= weights), ConfigsMax ())[]
32+
33+ # * Solution 1
34+ show_graph (graph; locs= locations, vertex_colors=
35+ [iszero (configs_mapped. c[1 ][i]) ? " white" : " red" for i= 1 : nv (graph)])
36+
37+ # * Solution 2
38+ show_graph (graph; locs= locations, vertex_colors=
39+ [iszero (configs_mapped. c[2 ][i]) ? " white" : " red" for i= 1 : nv (graph)])
40+
41+ # * Solution 3
42+ show_graph (graph; locs= locations, vertex_colors=
43+ [iszero (configs_mapped. c[3 ][i]) ? " white" : " red" for i= 1 : nv (graph)])
0 commit comments