Skip to content

Commit

Permalink
rename Branching to MinhThi Trick
Browse files Browse the repository at this point in the history
  • Loading branch information
GiggleLiu committed Jun 24, 2024
1 parent 63033ca commit c9b2c3d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 20 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
6 changes: 3 additions & 3 deletions notebooks/tutorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down
4 changes: 2 additions & 2 deletions notebooks/unweighted.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion src/UnitDiskMapping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
16 changes: 8 additions & 8 deletions src/mapping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
23 changes: 19 additions & 4 deletions src/pathdecomposition/pathdecomposition.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module PathDecomposition
using Graphs

export pathwidth, PathDecompositionMethod, Branching, Greedy
export pathwidth, PathDecompositionMethod, MinhThiTrick, Greedy

struct Layout{T}
vertices::Vector{T}
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/pathdecomposition/pathdecomposition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit c9b2c3d

Please sign in to comment.