|
1 | 1 | ### A Pluto.jl notebook ### |
2 | | -# v0.19.42 |
| 2 | +# v0.20.3 |
3 | 3 |
|
4 | 4 | using Markdown |
5 | 5 | using InteractiveUtils |
@@ -46,6 +46,9 @@ using UnitDiskMapping, Graphs # for mapping graphs to a King's subgraph (KSG) |
46 | 46 | # ╔═╡ 31250cb9-6f3a-429a-975d-752cb7c07883 |
47 | 47 | using GenericTensorNetworks # for solving the maximum independent sets |
48 | 48 |
|
| 49 | +# ╔═╡ e9a94e5a-274f-4740-ac05-bd3bb613df4d |
| 50 | +using GenericTensorNetworks.ProblemReductions |
| 51 | + |
49 | 52 | # ╔═╡ 9017a42c-9791-4933-84a4-9ff509967323 |
50 | 53 | md""" |
51 | 54 | # Unweighted KSG reduction of the independent set problem |
@@ -213,6 +216,48 @@ count(isone, mis_petersen) |
213 | 216 | # ╔═╡ 8c1d46e8-dc36-41bd-9d9b-5a72c380ef26 |
214 | 217 | md"The number printed should be consistent with the MIS size of the petersen graph." |
215 | 218 |
|
| 219 | +# ╔═╡ fba5edd7-e5b7-4631-94cc-0c49240917ff |
| 220 | +md""" |
| 221 | +## Extension: ProblemReductions |
| 222 | +Unit-disk mapping implements the unified interface for reduction in package [ProblemReductions.jl](https://github.com/GiggleLiu/ProblemReductions.jl) as an extension. |
| 223 | +""" |
| 224 | + |
| 225 | +# ╔═╡ 0f12b761-fb74-455b-9123-6d1b720aaf52 |
| 226 | +md""" |
| 227 | +Step 1: perform the problem reduction. |
| 228 | +""" |
| 229 | + |
| 230 | +# ╔═╡ 1113d5b9-8ebe-46fd-b24e-03e5fbc79435 |
| 231 | +source_problem = IndependentSet(smallgraph(:petersen)) |
| 232 | + |
| 233 | +# ╔═╡ 333a8123-1683-491e-8891-83987bad16eb |
| 234 | +# the Independent set problem with 2D GridGraph topology, unweighted. |
| 235 | +target_problem_type = IndependentSet{ProblemReductions.GridGraph{2}, Int, UnitWeight} |
| 236 | + |
| 237 | +# ╔═╡ 339fd327-a594-4460-9e00-8b3304aa0a78 |
| 238 | +# the result not only contains the target problem, but also the intermediate information |
| 239 | +reduction_result = reduceto(target_problem_type, source_problem) |
| 240 | + |
| 241 | +# ╔═╡ 0e2f9caa-d84e-411f-ad5d-64c10cdaa028 |
| 242 | +target_problem(reduction_result) |
| 243 | + |
| 244 | +# ╔═╡ 077045b9-3b88-4c41-a88c-354b8b30c31f |
| 245 | +md"Step 2: solve the target problem." |
| 246 | + |
| 247 | +# ╔═╡ d7562423-06cd-4949-a1fd-92d8e5c31280 |
| 248 | +# get single maximum independent set of the mapped problem |
| 249 | +config = solve(GenericTensorNetwork(target_problem(reduction_result)), SingleConfigMax())[].c.data |
| 250 | + |
| 251 | +# ╔═╡ 51a9d53b-b92f-41c4-a60e-d8ceedd3fead |
| 252 | +md"Step 3. Extract the solution back" |
| 253 | + |
| 254 | +# ╔═╡ 6ad557b1-04d3-4c7e-a350-20408c09b960 |
| 255 | +extracted_config = extract_solution(reduction_result, config) |
| 256 | + |
| 257 | +# ╔═╡ f685ed77-151f-4778-8342-112903255932 |
| 258 | +# finally, we check the validity of the solution. |
| 259 | +UnitDiskMapping.is_independent_set(source_problem.graph, extracted_config) |
| 260 | + |
216 | 261 | # ╔═╡ Cell order: |
217 | 262 | # ╟─f55dbf80-8425-11ee-2e7d-4d1ad4f693af |
218 | 263 | # ╟─9017a42c-9791-4933-84a4-9ff509967323 |
@@ -265,3 +310,15 @@ md"The number printed should be consistent with the MIS size of the petersen gra |
265 | 310 | # ╠═0297893c-c978-4818-aae8-26e60d8c9e9e |
266 | 311 | # ╠═5ffe0e4f-bd2c-4d3e-98ca-61673a7e5230 |
267 | 312 | # ╟─8c1d46e8-dc36-41bd-9d9b-5a72c380ef26 |
| 313 | +# ╟─fba5edd7-e5b7-4631-94cc-0c49240917ff |
| 314 | +# ╠═e9a94e5a-274f-4740-ac05-bd3bb613df4d |
| 315 | +# ╟─0f12b761-fb74-455b-9123-6d1b720aaf52 |
| 316 | +# ╠═1113d5b9-8ebe-46fd-b24e-03e5fbc79435 |
| 317 | +# ╠═333a8123-1683-491e-8891-83987bad16eb |
| 318 | +# ╠═339fd327-a594-4460-9e00-8b3304aa0a78 |
| 319 | +# ╠═0e2f9caa-d84e-411f-ad5d-64c10cdaa028 |
| 320 | +# ╟─077045b9-3b88-4c41-a88c-354b8b30c31f |
| 321 | +# ╠═d7562423-06cd-4949-a1fd-92d8e5c31280 |
| 322 | +# ╟─51a9d53b-b92f-41c4-a60e-d8ceedd3fead |
| 323 | +# ╠═6ad557b1-04d3-4c7e-a350-20408c09b960 |
| 324 | +# ╠═f685ed77-151f-4778-8342-112903255932 |
0 commit comments