Skip to content

Commit 4638cf1

Browse files
authored
Upgrade LuxorGraphPlot (#82)
* update * fix graph display * fix doc * update visualize * fix docstring
1 parent 33b2300 commit 4638cf1

File tree

13 files changed

+62
-25
lines changed

13 files changed

+62
-25
lines changed

docs/src/ref.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,11 @@ MergeGreedy
134134
#### Graph
135135
```@docs
136136
show_graph
137-
show_gallery
137+
show_configs
138138
show_einsum
139+
GraphDisplayConfig
140+
Layout
141+
render_locs
139142
140143
diagonal_coupled_graph
141144
square_lattice_graph

examples/Coloring.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ is_vertex_coloring(graph, single_solution.c.data)
5555

5656
vertex_color_map = Dict(0=>"red", 1=>"green", 2=>"blue")
5757

58-
show_graph(graph; locs=locations, format=:svg, vertex_colors=[vertex_color_map[Int(c)]
58+
show_graph(graph, locations; format=:svg, vertex_colors=[vertex_color_map[Int(c)]
5959
for c in single_solution.c.data])
6060

6161
# Let us try to solve the same issue on its line graph, a graph that generated by mapping an edge to a vertex and two edges sharing a common vertex will be connected.
6262
linegraph = line_graph(graph)
6363

64-
show_graph(linegraph; locs=[0.5 .* (locations[e.src] .+ locations[e.dst])
65-
for e in edges(graph)], format=:svg)
64+
show_graph(linegraph, [0.5 .* (locations[e.src] .+ locations[e.dst])
65+
for e in edges(graph)]; format=:svg)
6666

6767
# Let us construct the tensor network and see if there are solutions.
6868
lineproblem = Coloring{3}(linegraph);

examples/DominatingSet.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ all(c->is_dominating_set(graph, c), min_configs)
7474

7575
#
7676

77-
show_gallery(graph, (2, 5); locs=locations, vertex_configs=min_configs, format=:svg)
77+
show_configs(graph, locations, reshape(collect(min_configs), 2, 5); padding_left=20)
7878

7979
# Similarly, if one is only interested in computing one of the minimum dominating sets,
8080
# one can use the graph property [`SingleConfigMin`](@ref).

examples/IndependentSet.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ all_max_configs = solve(problem, ConfigsMax(; bounded=true))[]
132132

133133
all_max_configs.c.data
134134

135-
# These solutions can be visualized with the [`show_gallery`](@ref) function.
136-
show_gallery(graph, (1, length(all_max_configs.c)); locs=locations, vertex_configs=all_max_configs.c, format=:svg)
135+
# These solutions can be visualized with the [`show_configs`](@ref) function.
136+
show_configs(graph, locations, reshape(collect(all_max_configs.c), 1, length(all_max_configs.c)); padding_left=20)
137137

138138
# We can use [`ConfigsAll`](@ref) to enumerate all sets satisfying the independence constraint.
139139
all_independent_sets = solve(problem, ConfigsAll())[]

examples/Matching.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ matching_poly = solve(problem, GraphPolynomial())[]
6666
match_config = solve(problem, SingleConfigMax())[]
6767

6868
# Let us show the result by coloring the matched edges to red
69-
show_graph(graph; locs=locations, format=:svg, edge_colors=
69+
show_graph(graph, locations; format=:svg, edge_colors=
7070
[isone(match_config.c.data[i]) ? "red" : "black" for i=1:ne(graph)])
7171

7272
# where we use edges with red color to related pairs of matched vertices.

examples/MaxCut.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ max_cut_size_verify = cut_size(graph, max_vertex_config)
7676

7777
# You should see a consistent result as above `max_cut_size`.
7878

79-
show_graph(graph; locs=locations, vertex_colors=[
79+
show_graph(graph, locations; vertex_colors=[
8080
iszero(max_vertex_config[i]) ? "white" : "red" for i=1:nv(graph)], format=:svg)
8181

8282
# where red vertices and white vertices are separated by the cut.

examples/MaximalIS.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ all(c->is_maximal_independent_set(graph, c), maximal_configs)
7272

7373
#
7474

75-
show_gallery(graph, (3, 5); locs=locations, vertex_configs=maximal_configs, format=:svg)
75+
show_configs(graph, locations, reshape(collect(maximal_configs), 3, 5); padding_left=20)
7676

7777
# This result should be consistent with that given by the [Bron Kerbosch algorithm](https://en.wikipedia.org/wiki/Bron%E2%80%93Kerbosch_algorithm) on the complement of Petersen graph.
7878
cliques = maximal_cliques(complement(graph))
@@ -83,7 +83,7 @@ cliques = maximal_cliques(complement(graph))
8383
# It is the [`ConfigsMin`](@ref) property in the program.
8484
minimum_maximal_configs = solve(problem, ConfigsMin())[].c
8585

86-
show_gallery(graph, (2, 5); locs=locations, vertex_configs=minimum_maximal_configs, format=:svg)
86+
show_configs(graph, locations, reshape(collect(minimum_maximal_configs), 2, 5); padding_left=20)
8787

8888
# Similarly, if one is only interested in computing one of the minimum sets,
8989
# one can use the graph property [`SingleConfigMin`](@ref).

examples/PaintShop.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ best_configs = solve(problem, ConfigsMin())[]
9090

9191
painting1 = paint_shop_coloring_from_config(pshop, best_configs.c.data[1])
9292

93-
show_graph(graph; locs=locations, format=:svg, texts=string.(sequence),
93+
show_graph(graph, locations; format=:svg, texts=string.(sequence),
9494
edge_colors=[sequence[e.src] == sequence[e.dst] ? "blue" : "black" for e in edges(graph)],
95-
vertex_colors=[isone(c) ? "red" : "black" for c in painting1], vertex_text_color="white")
95+
vertex_colors=[isone(c) ? "red" : "black" for c in painting1], config=GraphDisplayConfig(;vertex_text_color="white"))
9696

9797
# Since we have different choices of initial color, the number of best solution is 2.
9898

examples/weighted.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,4 @@ max5_configs = solve(problem, SingleConfigMax(5))[]
4141
max5_configs.orders
4242

4343
# Let us visually check these configurations
44-
show_gallery(graph, (1, 5); locs=locations, format=:svg, vertex_configs=[max5_configs.orders[k].c.data for k=1:5])
45-
44+
show_configs(graph, locations, [max5_configs.orders[j].c.data for i=1:1, j=1:5]; padding_left=20)

src/GenericTensorNetworks.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using OMEinsum: contraction_complexity, timespace_complexity, timespacereadwrite
77
using Graphs, Random
88
using DelimitedFiles, Serialization, Printf
99
using LuxorGraphPlot
10+
using LuxorGraphPlot.Luxor.Colors: @colorant_str
1011
import Polynomials
1112
using Polynomials: Polynomial, LaurentPolynomial, printpoly, fit
1213
using FFTW
@@ -59,7 +60,7 @@ export solve, SizeMax, SizeMin, PartitionFunction, CountingAll, CountingMax, Cou
5960
export save_configs, load_configs, hamming_distribution, save_sumproduct, load_sumproduct
6061

6162
# Visualization
62-
export show_graph, spring_layout!, show_gallery, show_einsum
63+
export show_graph, spring_layout!, show_configs, show_einsum, GraphDisplayConfig, Layout, render_locs
6364

6465
project_relative_path(xs...) = normpath(joinpath(dirname(dirname(pathof(@__MODULE__))), xs...))
6566

0 commit comments

Comments
 (0)