|
1 | | -# const PRS = PartialRejectionSampling, Plots, GraphPlot, Colors, LS = LazySets, LG = LightGraphs |
2 | | -includet("docs/plots/pedagogy_graph.jl") |
| 1 | +include(joinpath(@__DIR__, "pedagogy_graph.jl")) |
3 | 2 | using Random |
4 | 3 |
|
5 | 4 | dims = [5, 5] |
6 | 5 | g = LG.grid(dims) |
7 | 6 | β = 0.5 |
8 | 7 |
|
9 | 8 | pp = PRS.HardCoreGraph(g, β) |
10 | | - |
11 | 9 | rng = Random.MersenneTwister(123) |
12 | 10 |
|
13 | | -path(i) = joinpath("docs/plots/output/hard_core_graph", join([lpad(i, 3, "0"), ".pdf"])) |
14 | | - |
15 | | -c_node_normal = Colors.colorant"turquoise"; |
16 | | - |
17 | | -c_node_unccupied = Colors.colorant"white"; |
18 | | -c_node_occupied = Colors.colorant"gray"; |
19 | | - |
20 | | -c_node_update = Colors.colorant"orange"; |
21 | | -c_node_bad = Colors.colorant"red"; |
22 | | - |
23 | | -i = 0 |
24 | | -c_nodes = fill(c_node_normal, LG.nv(pp.graph)) |
25 | | -plot(pp.graph, dims, path(i); nodefillc=c_nodes) |
26 | | - |
27 | | -proba = pp.β / (one(pp.β) + pp.β) |
28 | | - |
29 | | -adj = LG.adjacency_matrix(pp.graph) |
30 | | -occupied = Random.randsubseq(rng, LG.vertices(pp.graph), proba) |
31 | | - |
32 | | -while true |
33 | | - |
34 | | - i += 1 |
35 | | - c_nodes = fill(c_node_unccupied, LG.nv(pp.graph)) |
36 | | - c_nodes[occupied] .= c_node_occupied |
37 | | - plot(pp.graph, dims, path(i); nodefillc=c_nodes) |
38 | | - |
39 | | - # Check if occupied vertices form an independent set |
40 | | - sub_graph = LG.SimpleGraph(adj[occupied, occupied]) |
41 | | - LG.ne(sub_graph) == 0 && break |
42 | | - |
43 | | - bad = [] |
44 | | - independent, resample = [], Set() |
45 | | - for cc in LG.connected_components(sub_graph) |
46 | | - if length(cc) == 1 # Identify current independent vertices |
47 | | - append!(independent, occupied[cc]) |
48 | | - else # Construct the resampling set of vertices |
49 | | - union!(resample, occupied[cc]) |
50 | | - union!(bad, occupied[cc]) |
51 | | - for v in cc |
52 | | - union!(resample, LG.neighbors(pp.graph, occupied[v])) |
53 | | - end |
54 | | - end |
55 | | - end |
56 | | - |
57 | | - i += 1 |
58 | | - c_nodes[bad] .= c_node_bad |
59 | | - plot(pp.graph, dims, path(i); nodefillc=c_nodes) |
60 | | - |
61 | | - Random.randsubseq!(rng, occupied, collect(resample), proba) |
62 | | - append!(occupied, independent) |
63 | | - |
64 | | - i += 1 |
65 | | - c_nodes[collect(resample)] .= c_node_update; |
66 | | - plot(pp.graph, dims, path(i); nodefillc=c_nodes) |
67 | | -end |
| 11 | +hard_core_graph_pedagogy(pp, dims, rng) |
0 commit comments