diff --git a/Project.toml b/Project.toml index b81edb6..acfe5d7 100644 --- a/Project.toml +++ b/Project.toml @@ -14,8 +14,9 @@ julia = "1" [extras] GenericTensorNetworks = "3521c873-ad32-4bb4-b63d-f4f178f42b49" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "Random", "GenericTensorNetworks"] +test = ["Test", "Random", "GenericTensorNetworks", "LinearAlgebra"] diff --git a/notebooks/tutorial.jl b/notebooks/tutorial.jl index cdb9d73..f54ed28 100644 --- a/notebooks/tutorial.jl +++ b/notebooks/tutorial.jl @@ -70,10 +70,10 @@ LuxorGraphPlot.show_graph(graph) md"We can use the `map_graph` function to map the unweighted MIS problem on the Petersen graph to one on a defected King's graph." # ╔═╡ c7315578-8bb0-40a0-a2a3-685a80674c9c -unweighted_res = map_graph(graph; vertex_order=Branching()); +unweighted_res = map_graph(graph; vertex_order=MinhThiTrick()); # ╔═╡ 3f605eac-f587-40b2-8fac-8223777d3fad -md"Here, the keyword argument `vertex_order` can be a vector of vertices in a specified order, or the method to compute the path decomposition that generates an order. The `Branching()` method is an exact path decomposition solver, which is suited for small graphs (where number of vertices <= 50). The `Greedy()` method finds the vertex order much faster and works in all cases, but may not be optimal. +md"Here, the keyword argument `vertex_order` can be a vector of vertices in a specified order, or the method to compute the path decomposition that generates an order. The `MinhThiTrick()` method is an exact path decomposition solver, which is suited for small graphs (where number of vertices <= 50). The `Greedy()` method finds the vertex order much faster and works in all cases, but may not be optimal. A good vertex order can reduce the depth of the mapped graph." # ╔═╡ e5382b61-6387-49b5-bae8-0389fbc92153 @@ -150,7 +150,7 @@ md"## Generic Weighted Mapping" md"A Maximum Weight Independent Set (MWIS) problem on a general graph can be mapped to one on the defected King's graph. The first step is to do the same mapping as above but adding a new positional argument `Weighted()` as the first argument of `map_graph`. Let us still use the Petersen graph as an example." # ╔═╡ 2fa704ee-d5c1-4205-9a6a-34ba0195fecf -weighted_res = map_graph(Weighted(), graph; vertex_order=Branching()); +weighted_res = map_graph(Weighted(), graph; vertex_order=MinhThiTrick()); # ╔═╡ 27acc8be-2db8-4322-85b4-230fdddac043 md"The return value is similar to that for the unweighted mapping generated above, except each node in the mapped graph can have a weight 1, 2 or 3. Note here, we haven't added the weights in the original graph." diff --git a/notebooks/unweighted.jl b/notebooks/unweighted.jl index f117753..6fc1613 100644 --- a/notebooks/unweighted.jl +++ b/notebooks/unweighted.jl @@ -82,11 +82,11 @@ show_graph(g5) # ╔═╡ 625bdcf4-e37e-4bb8-bd1a-907cdcc5fe24 md""" #### Step 2: Map the source graph to an unweighted King's subgraph (KSG) -The vertex order is optimized with the Branching path decomposition algorithm +The vertex order is optimized with the Branching path decomposition algorithm (MinhThi's Trick) """ # ╔═╡ f9e57a6b-1186-407e-a8b1-cb8f31a17bd2 -g5res = UnitDiskMapping.map_graph(g5; vertex_order=Branching()) +g5res = UnitDiskMapping.map_graph(g5; vertex_order=MinhThiTrick()) # ╔═╡ e64e7ca4-b297-4c74-8699-bec4b4fbb843 md"Visualize the mapped KSG graph in terminal" diff --git a/src/UnitDiskMapping.jl b/src/UnitDiskMapping.jl index 247bdbd..628f921 100644 --- a/src/UnitDiskMapping.jl +++ b/src/UnitDiskMapping.jl @@ -37,7 +37,9 @@ export @gg export is_independent_set, unitdisk_graph # path decomposition -export pathwidth, PathDecompositionMethod, Branching, Greedy +export pathwidth, PathDecompositionMethod, MinhThiTrick, Greedy + +@deprecate Branching MinhThiTrick include("utils.jl") include("Core.jl") diff --git a/src/mapping.jl b/src/mapping.jl index 4a1c4e1..1297393 100644 --- a/src/mapping.jl +++ b/src/mapping.jl @@ -318,16 +318,16 @@ function crossat(ug::MappingGrid, v, w) end """ - embed_graph([mode,] g::SimpleGraph; vertex_order=Branching()) + embed_graph([mode,] g::SimpleGraph; vertex_order=MinhThiTrick()) Embed graph `g` into a unit disk grid, where the optional argument `mode` can be `Weighted()` or `UnWeighted`. The `vertex_order` can be a vector or one of the following inputs * `Greedy()` fast but non-optimal. - * `Branching()` slow but optimal. + * `MinhThiTrick()` slow but optimal. """ -embed_graph(g::SimpleGraph; vertex_order=Branching()) = embed_graph(UnWeighted(), g; vertex_order) -function embed_graph(mode, g::SimpleGraph; vertex_order=Branching()) +embed_graph(g::SimpleGraph; vertex_order=MinhThiTrick()) = embed_graph(UnWeighted(), g; vertex_order) +function embed_graph(mode, g::SimpleGraph; vertex_order=MinhThiTrick()) if vertex_order isa AbstractVector L = PathDecomposition.Layout(g, collect(vertex_order[end:-1:1])) else @@ -368,7 +368,7 @@ struct MappingResult{NT} end """ - map_graph([mode=UnWeighted(),] g::SimpleGraph; vertex_order=Branching(), ruleset=[...]) + map_graph([mode=UnWeighted(),] g::SimpleGraph; vertex_order=MinhThiTrick(), ruleset=[...]) Map a graph to a unit disk grid graph that being "equivalent" to the original graph, and return a `MappingResult` instance. Here "equivalent" means a maximum independent set in the grid graph can be mapped back to @@ -385,13 +385,13 @@ Keyword Arguments Different vertex orders have different path width, i.e. different depth of mapped grid graph. It can be a vector or one of the following inputs * `Greedy()` fast but not optimal. - * `Branching()` slow but optimal. + * `MinhThiTrick()` slow but optimal. * `ruleset` specifies and extra set of optimization patterns (not the crossing patterns). """ -function map_graph(g::SimpleGraph; vertex_order=Branching(), ruleset=default_simplifier_ruleset(UnWeighted())) +function map_graph(g::SimpleGraph; vertex_order=MinhThiTrick(), ruleset=default_simplifier_ruleset(UnWeighted())) map_graph(UnWeighted(), g; ruleset=ruleset, vertex_order=vertex_order) end -function map_graph(mode, g::SimpleGraph; vertex_order=Branching(), ruleset=default_simplifier_ruleset(mode)) +function map_graph(mode, g::SimpleGraph; vertex_order=MinhThiTrick(), ruleset=default_simplifier_ruleset(mode)) ug = embed_graph(mode, g; vertex_order=vertex_order) mis_overhead0 = mis_overhead_copylines(ug) ug, tape = apply_crossing_gadgets!(mode, ug) diff --git a/src/pathdecomposition/pathdecomposition.jl b/src/pathdecomposition/pathdecomposition.jl index 8960d09..cc93781 100644 --- a/src/pathdecomposition/pathdecomposition.jl +++ b/src/pathdecomposition/pathdecomposition.jl @@ -1,7 +1,7 @@ module PathDecomposition using Graphs -export pathwidth, PathDecompositionMethod, Branching, Greedy +export pathwidth, PathDecompositionMethod, MinhThiTrick, Greedy struct Layout{T} vertices::Vector{T} @@ -78,7 +78,22 @@ Graphs.vertices(layout::Layout) = layout.vertices ##### Interfaces ##### abstract type PathDecompositionMethod end -struct Branching <: PathDecompositionMethod end +""" + MinhThiTrick <: PathDecompositionMethod + +A path decomposition method based on the Branching method. + +In memory of Minh-Thi Nguyen, one of the main developers of this method. +She left us in a truck accident at her 24 years old. +- https://www.cbsnews.com/boston/news/cyclist-killed-minh-thi-nguyen-cambridge-bike-safety/ +""" +struct MinhThiTrick <: PathDecompositionMethod end + +""" + Greedy <: PathDecompositionMethod + +A path decomposition method based on the Greedy method. +""" Base.@kwdef struct Greedy <: PathDecompositionMethod nrepeat::Int = 10 end @@ -90,9 +105,9 @@ Compute the optimal path decomposition of graph `g`, returns a `Layout` instance `method` can be * Greedy(; nrepeat=10) - * Branching + * MinhThiTrick """ -function pathwidth(g::AbstractGraph, ::Branching) +function pathwidth(g::AbstractGraph, ::MinhThiTrick) return branch_and_bound(g) end diff --git a/test/pathdecomposition/pathdecomposition.jl b/test/pathdecomposition/pathdecomposition.jl index f710f51..2be885d 100644 --- a/test/pathdecomposition/pathdecomposition.jl +++ b/test/pathdecomposition/pathdecomposition.jl @@ -16,7 +16,7 @@ using Graphs @test sum(length, arem) == nv(g) end g = smallgraph(:tutte) - res = pathwidth(g, Branching()) + res = pathwidth(g, MinhThiTrick()) @test vsep(res) == 6 g = smallgraph(:tutte) res = pathwidth(g, Greedy(nrepeat=50))