Skip to content

Commit

Permalink
Tweak docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gdalle committed Feb 22, 2023
1 parent a6318d6 commit f1175c1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
6 changes: 4 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ TUTORIAL_DIR_JL = joinpath(dirname(@__DIR__), "test", "tutorial")
TUTORIAL_DIR_MD = joinpath(@__DIR__, "src", "tutorial")

for file in readdir(TUTORIAL_DIR_MD)
rm(joinpath(TUTORIAL_DIR_MD, file))
if endswith(file, ".md")
rm(joinpath(TUTORIAL_DIR_MD, file))
end
end

for file in readdir(TUTORIAL_DIR_JL)
Expand Down Expand Up @@ -38,7 +40,7 @@ pages = [
"Home" => "index.md",
"Tutorial" => [
markdown_title(joinpath(TUTORIAL_DIR_MD, file)) => joinpath("tutorial", file)
for file in sort(readdir(TUTORIAL_DIR_MD))
for file in sort(readdir(TUTORIAL_DIR_MD)) if endswith(file, ".md")
],
"API reference" => "api.md",
]
Expand Down
23 changes: 11 additions & 12 deletions test/tutorial/1_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,22 @@ weighttype(weighted_default)

# You can use the `weight_function` keyword to specify a function which will transform edge metadata into a weight. This weight must always be the same type as the `default_weight`.

weighted = MetaGraph(Graph(); EdgeData=Float64, weight_function=identity);
weighted[:red] = nothing;
weighted[:blue] = nothing;
weighted[:yellow] = nothing;
weighted[:red, :blue] = 1.0;
weighted[:blue, :yellow] = 2.0;
weighted = MetaGraph(Graph(); EdgeData=Float64, weight_function=ed -> ed^2);

weighted[:alice] = nothing;
weighted[:bob] = nothing;
weighted[:alice, :bob] = 2.0;
#-
weight_matrix = Graphs.weights(weighted)
#-
size(weight_matrix)
@test size(weight_matrix) == (3, 3) #src
@test size(weight_matrix) == (2, 2) #src
#-
weight_matrix[1, 3]
@test weight_matrix[1, 3] 1.0 #src
weight_matrix[1, 2]
@test weight_matrix[1, 2] 4.0 #src
#-
wf = get_weight_function(weighted) # identity
wf(5.2)
@test wf(5.2) 5.2 #src
wf = get_weight_function(weighted)
wf(3)
@test wf(3) == 9 #src

# You can then use all functions from Graphs.jl that require weighted graphs (see the rest of the tutorial).
9 changes: 7 additions & 2 deletions test/tutorial/2_graphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ using Test #src
# We can make `MetaGraph`s based on (undirected) `Graph`s.

cities = MetaGraph(
Graph(); VertexData=String, EdgeData=Int, weight_function=identity, default_weight=0
Graph();
Label=Symbol,
VertexData=String,
EdgeData=Int,
weight_function=identity,
default_weight=0,
);

# Let us add some cities and the distance between them:
Expand Down Expand Up @@ -88,7 +93,7 @@ zero(cities)
diameter(cities)
@test diameter(cities) == 344 + 878 #src
#-
ds = dijkstra_shortest_paths(cities, 2);
ds = dijkstra_shortest_paths(cities, 2)
@test Tuple(ds.dists) == (344, 0, 344 + 878) #src

# Finally, let us remove some edges and vertices
Expand Down

0 comments on commit f1175c1

Please sign in to comment.