diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 7886926b0..c8a562e65 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,7 +1,3 @@ Please make sure to leave this PR editable by maintainers of this repo. Please make sure you have consulted [CONTRIBUTING](https://github.com/JuliaGraphs/Graphs.jl/blob/master/CONTRIBUTING.md) - -The linter bot might add new commits to your PR (e.g. to take care of formatting issues). Feel free to overwrite these commits. - -If the linter bot is the last one to put in a commit, **THE TESTS WILL NOT RUN**. Either lint/format your contributions yourself as described in CONTRIBUTING.md or close&reopen the PR to reset the test runner. \ No newline at end of file diff --git a/.github/workflows/prprecommit.yml b/.github/workflows/prprecommit.yml deleted file mode 100644 index fdd3c7380..000000000 --- a/.github/workflows/prprecommit.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: PR Pre-Commit Bot -env: - JULIA_NUM_THREADS: 2 -concurrency: - # group by workflow and ref; the last slightly strange component ensures that for pull - # requests, we limit to 1 concurrent job, but for the master branch we don't - group: ${{ github.workflow }}-${{ github.ref }}-${{ (github.ref != 'refs/heads/master' && github.ref != 'refs/heads/main') || github.run_number }} - # Cancel intermediate builds, but only if it is a pull request build. - cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} -#on: -# pull_request: -# branches: ["master", "main"] -jobs: - pre-commit: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v5 - with: - ref: ${{ github.head_ref }} - - name: Setup Julia - uses: julia-actions/setup-julia@v2 - with: - version: '1' - - uses: julia-actions/cache@v2 - - name: Setup JuliaFormatter - run: | - julia -e ' - using Pkg - Pkg.add(name="JuliaFormatter", version="1.0.62")' - - name: Setup Python - uses: actions/setup-python@v5 - - name: Run pre-commit - uses: pre-commit/action@v3.0.1 - continue-on-error: true - - name: Potentially commit changes - uses: stefanzweifel/git-auto-commit-action@v6 - with: - commit_message: linter bot commit -- feel free to overwrite \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 592195822..000000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,5 +0,0 @@ -repos: -- repo: "https://github.com/domluna/JuliaFormatter.jl" - rev: "v1.0.62" - hooks: - - id: "julia-formatter" \ No newline at end of file diff --git a/Project.toml b/Project.toml index e10d64ac1..6d7e273b5 100644 --- a/Project.toml +++ b/Project.toml @@ -21,12 +21,12 @@ GraphsSharedArraysExt = "SharedArrays" [compat] ArnoldiMethod = "0.4" +DataStructures = "0.19" Distributed = "1" -DataStructures = "0.18, 0.19" Inflate = "0.1.3" LinearAlgebra = "1" Random = "1" -SharedArrays = "1" +SharedArrays = "1" SimpleTraits = "0.9.1" SparseArrays = "1" Statistics = "1" diff --git a/src/Experimental/ShortestPaths/ShortestPaths.jl b/src/Experimental/ShortestPaths/ShortestPaths.jl index ec7d8e139..ece5232ff 100644 --- a/src/Experimental/ShortestPaths/ShortestPaths.jl +++ b/src/Experimental/ShortestPaths/ShortestPaths.jl @@ -4,7 +4,7 @@ using Graphs using Graphs.Experimental.Traversals using Graphs: AbstractGraph, AbstractEdge using Graphs.SimpleGraphs: AbstractSimpleGraph -using DataStructures: PriorityQueue, enqueue!, dequeue! +using DataStructures: PriorityQueue import Graphs.Experimental.Traversals: initfn!, previsitfn!, newvisitfn!, visitfn!, postvisitfn!, postlevelfn! diff --git a/src/Experimental/ShortestPaths/astar.jl b/src/Experimental/ShortestPaths/astar.jl index f12ad5a34..fab0a8048 100644 --- a/src/Experimental/ShortestPaths/astar.jl +++ b/src/Experimental/ShortestPaths/astar.jl @@ -56,7 +56,7 @@ function a_star_impl!( total_path = Vector{T}() @inbounds while !isempty(open_set) - current = dequeue!(open_set) + current = popfirst!(open_set).first if current == goal reconstruct_path!(total_path, came_from, current, g) @@ -104,7 +104,7 @@ function shortest_paths( checkbounds(distmx, Base.OneTo(nv(g)), Base.OneTo(nv(g))) open_set = PriorityQueue{Integer,T}() - enqueue!(open_set, s, 0) + push!(open_set, s => 0) closed_set = zeros(Bool, nv(g)) diff --git a/src/Experimental/ShortestPaths/dijkstra.jl b/src/Experimental/ShortestPaths/dijkstra.jl index 9d9baea98..5fd70f4dd 100644 --- a/src/Experimental/ShortestPaths/dijkstra.jl +++ b/src/Experimental/ShortestPaths/dijkstra.jl @@ -66,7 +66,7 @@ function shortest_paths( sizehint!(closest_vertices, nvg) while !isempty(H) - u = dequeue!(H) + u = popfirst!(H).first if alg.track_vertices push!(closest_vertices, u) diff --git a/src/Experimental/Traversals/bfs.jl b/src/Experimental/Traversals/bfs.jl index 40b663fc9..8ce058c18 100644 --- a/src/Experimental/Traversals/bfs.jl +++ b/src/Experimental/Traversals/bfs.jl @@ -1,4 +1,3 @@ -import Base.Sort, Base.Sort.Algorithm import Base: sort! struct NOOPSortAlg <: Base.Sort.Algorithm end diff --git a/src/Experimental/vf2.jl b/src/Experimental/vf2.jl index d4286fe4b..0c3b44929 100644 --- a/src/Experimental/vf2.jl +++ b/src/Experimental/vf2.jl @@ -489,7 +489,7 @@ function has_induced_subgraphisomorph( edge_relation::Union{Nothing,Function}=nothing, )::Bool result = false - callback(vmap) = (result = true; return false) + callback(vmap) = (result=true; return false) vf2( callback, g1, @@ -509,7 +509,7 @@ function has_subgraphisomorph( edge_relation::Union{Nothing,Function}=nothing, )::Bool result = false - callback(vmap) = (result = true; return false) + callback(vmap) = (result=true; return false) vf2( callback, g1, @@ -531,7 +531,7 @@ function has_isomorph( !could_have_isomorph(g1, g2) && return false result = false - callback(vmap) = (result = true; return false) + callback(vmap) = (result=true; return false) vf2( callback, g1, @@ -648,8 +648,6 @@ function all_subgraphisomorph( end #! format: off -# Turns off formatting from this point onwards - function all_isomorph( g1::AbstractGraph, g2::AbstractGraph, @@ -672,6 +670,4 @@ function all_isomorph( end return ch end - #! format: on -# Turns on formatting from this point onwards diff --git a/src/Graphs.jl b/src/Graphs.jl index a40a78168..031f678dd 100644 --- a/src/Graphs.jl +++ b/src/Graphs.jl @@ -8,15 +8,11 @@ using Statistics: mean using Inflate: InflateGzipStream using DataStructures: - IntDisjointSets, + IntDisjointSet, PriorityQueue, - dequeue!, - dequeue_pair!, - enqueue!, heappop!, heappush!, in_same_set, - peek, union!, find_root!, BinaryMaxHeap, diff --git a/src/SimpleGraphs/generators/randgraphs.jl b/src/SimpleGraphs/generators/randgraphs.jl index 750e22b5a..0f2a04468 100644 --- a/src/SimpleGraphs/generators/randgraphs.jl +++ b/src/SimpleGraphs/generators/randgraphs.jl @@ -1164,7 +1164,7 @@ function stochastic_block_model( for b in a:K ((a == b) && !(c[a, b] <= n[b] - 1)) || ((a != b) && !(c[a, b] <= n[b])) && error( - "Mean degree cannot be greater than available neighbors in the block.", + "Mean degree cannot be greater than available neighbors in the block." ) # TODO 0.7: turn into some other error? m = a == b ? div(n[a] * (n[a] - 1), 2) : n[a] * n[b] diff --git a/src/SimpleGraphs/generators/smallgraphs.jl b/src/SimpleGraphs/generators/smallgraphs.jl index 0706d5d81..60a846711 100644 --- a/src/SimpleGraphs/generators/smallgraphs.jl +++ b/src/SimpleGraphs/generators/smallgraphs.jl @@ -81,179 +81,173 @@ diamond_graph() = SimpleGraph(SimpleEdge.([(1, 2), (1, 3), (2, 3), (2, 4), (3, 4 bull_graph() = SimpleGraph(SimpleEdge.([(1, 2), (1, 3), (2, 3), (2, 4), (3, 5)])) function chvatal_graph() - e = - SimpleEdge.([ - (1, 2), - (1, 5), - (1, 7), - (1, 10), - (2, 3), - (2, 6), - (2, 8), - (3, 4), - (3, 7), - (3, 9), - (4, 5), - (4, 8), - (4, 10), - (5, 6), - (5, 9), - (6, 11), - (6, 12), - (7, 11), - (7, 12), - (8, 9), - (8, 12), - (9, 11), - (10, 11), - (10, 12), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 5), + (1, 7), + (1, 10), + (2, 3), + (2, 6), + (2, 8), + (3, 4), + (3, 7), + (3, 9), + (4, 5), + (4, 8), + (4, 10), + (5, 6), + (5, 9), + (6, 11), + (6, 12), + (7, 11), + (7, 12), + (8, 9), + (8, 12), + (9, 11), + (10, 11), + (10, 12), + ]) return SimpleGraph(e) end function cubical_graph() - e = - SimpleEdge.([ - (1, 2), - (1, 4), - (1, 5), - (2, 3), - (2, 8), - (3, 4), - (3, 7), - (4, 6), - (5, 6), - (5, 8), - (6, 7), - (7, 8), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 4), + (1, 5), + (2, 3), + (2, 8), + (3, 4), + (3, 7), + (4, 6), + (5, 6), + (5, 8), + (6, 7), + (7, 8), + ]) return SimpleGraph(e) end function desargues_graph() - e = - SimpleEdge.([ - (1, 2), - (1, 6), - (1, 20), - (2, 3), - (2, 17), - (3, 4), - (3, 12), - (4, 5), - (4, 15), - (5, 6), - (5, 10), - (6, 7), - (7, 8), - (7, 16), - (8, 9), - (8, 19), - (9, 10), - (9, 14), - (10, 11), - (11, 12), - (11, 20), - (12, 13), - (13, 14), - (13, 18), - (14, 15), - (15, 16), - (16, 17), - (17, 18), - (18, 19), - (19, 20), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 6), + (1, 20), + (2, 3), + (2, 17), + (3, 4), + (3, 12), + (4, 5), + (4, 15), + (5, 6), + (5, 10), + (6, 7), + (7, 8), + (7, 16), + (8, 9), + (8, 19), + (9, 10), + (9, 14), + (10, 11), + (11, 12), + (11, 20), + (12, 13), + (13, 14), + (13, 18), + (14, 15), + (15, 16), + (16, 17), + (17, 18), + (18, 19), + (19, 20), + ]) return SimpleGraph(e) end function dodecahedral_graph() - e = - SimpleEdge.([ - (1, 2), - (1, 11), - (1, 20), - (2, 3), - (2, 9), - (3, 4), - (3, 7), - (4, 5), - (4, 20), - (5, 6), - (5, 18), - (6, 7), - (6, 16), - (7, 8), - (8, 9), - (8, 15), - (9, 10), - (10, 11), - (10, 14), - (11, 12), - (12, 13), - (12, 19), - (13, 14), - (13, 17), - (14, 15), - (15, 16), - (16, 17), - (17, 18), - (18, 19), - (19, 20), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 11), + (1, 20), + (2, 3), + (2, 9), + (3, 4), + (3, 7), + (4, 5), + (4, 20), + (5, 6), + (5, 18), + (6, 7), + (6, 16), + (7, 8), + (8, 9), + (8, 15), + (9, 10), + (10, 11), + (10, 14), + (11, 12), + (12, 13), + (12, 19), + (13, 14), + (13, 17), + (14, 15), + (15, 16), + (16, 17), + (17, 18), + (18, 19), + (19, 20), + ]) return SimpleGraph(e) end function frucht_graph() - e = - SimpleEdge.([ - (1, 2), - (1, 7), - (1, 8), - (2, 3), - (2, 8), - (3, 4), - (3, 9), - (4, 5), - (4, 10), - (5, 6), - (5, 10), - (6, 7), - (6, 11), - (7, 11), - (8, 12), - (9, 10), - (9, 12), - (11, 12), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 7), + (1, 8), + (2, 3), + (2, 8), + (3, 4), + (3, 9), + (4, 5), + (4, 10), + (5, 6), + (5, 10), + (6, 7), + (6, 11), + (7, 11), + (8, 12), + (9, 10), + (9, 12), + (11, 12), + ]) return SimpleGraph(e) end function heawood_graph() - e = - SimpleEdge.([ - (1, 2), - (1, 6), - (1, 14), - (2, 3), - (2, 11), - (3, 4), - (3, 8), - (4, 5), - (4, 13), - (5, 6), - (5, 10), - (6, 7), - (7, 8), - (7, 12), - (8, 9), - (9, 10), - (9, 14), - (10, 11), - (11, 12), - (12, 13), - (13, 14), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 6), + (1, 14), + (2, 3), + (2, 11), + (3, 4), + (3, 8), + (4, 5), + (4, 13), + (5, 6), + (5, 10), + (6, 7), + (7, 8), + (7, 12), + (8, 9), + (9, 10), + (9, 14), + (10, 11), + (11, 12), + (12, 13), + (13, 14), + ]) return SimpleGraph(e) end @@ -270,263 +264,255 @@ function house_x_graph() end function icosahedral_graph() - e = - SimpleEdge.([ - (1, 2), - (1, 6), - (1, 8), - (1, 9), - (1, 12), - (2, 3), - (2, 6), - (2, 7), - (2, 9), - (3, 4), - (3, 7), - (3, 9), - (3, 10), - (4, 5), - (4, 7), - (4, 10), - (4, 11), - (5, 6), - (5, 7), - (5, 11), - (5, 12), - (6, 7), - (6, 12), - (8, 9), - (8, 10), - (8, 11), - (8, 12), - (9, 10), - (10, 11), - (11, 12), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 6), + (1, 8), + (1, 9), + (1, 12), + (2, 3), + (2, 6), + (2, 7), + (2, 9), + (3, 4), + (3, 7), + (3, 9), + (3, 10), + (4, 5), + (4, 7), + (4, 10), + (4, 11), + (5, 6), + (5, 7), + (5, 11), + (5, 12), + (6, 7), + (6, 12), + (8, 9), + (8, 10), + (8, 11), + (8, 12), + (9, 10), + (10, 11), + (11, 12), + ]) return SimpleGraph(e) end function karate_graph() - e = - SimpleEdge.([ - (1, 2), - (1, 3), - (1, 4), - (1, 5), - (1, 6), - (1, 7), - (1, 8), - (1, 9), - (1, 11), - (1, 12), - (1, 13), - (1, 14), - (1, 18), - (1, 20), - (1, 22), - (1, 32), - (2, 3), - (2, 4), - (2, 8), - (2, 14), - (2, 18), - (2, 20), - (2, 22), - (2, 31), - (3, 4), - (3, 8), - (3, 9), - (3, 10), - (3, 14), - (3, 28), - (3, 29), - (3, 33), - (4, 8), - (4, 13), - (4, 14), - (5, 7), - (5, 11), - (6, 7), - (6, 11), - (6, 17), - (7, 17), - (9, 31), - (9, 33), - (9, 34), - (10, 34), - (14, 34), - (15, 33), - (15, 34), - (16, 33), - (16, 34), - (19, 33), - (19, 34), - (20, 34), - (21, 33), - (21, 34), - (23, 33), - (23, 34), - (24, 26), - (24, 28), - (24, 30), - (24, 33), - (24, 34), - (25, 26), - (25, 28), - (25, 32), - (26, 32), - (27, 30), - (27, 34), - (28, 34), - (29, 32), - (29, 34), - (30, 33), - (30, 34), - (31, 33), - (31, 34), - (32, 33), - (32, 34), - (33, 34), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 3), + (1, 4), + (1, 5), + (1, 6), + (1, 7), + (1, 8), + (1, 9), + (1, 11), + (1, 12), + (1, 13), + (1, 14), + (1, 18), + (1, 20), + (1, 22), + (1, 32), + (2, 3), + (2, 4), + (2, 8), + (2, 14), + (2, 18), + (2, 20), + (2, 22), + (2, 31), + (3, 4), + (3, 8), + (3, 9), + (3, 10), + (3, 14), + (3, 28), + (3, 29), + (3, 33), + (4, 8), + (4, 13), + (4, 14), + (5, 7), + (5, 11), + (6, 7), + (6, 11), + (6, 17), + (7, 17), + (9, 31), + (9, 33), + (9, 34), + (10, 34), + (14, 34), + (15, 33), + (15, 34), + (16, 33), + (16, 34), + (19, 33), + (19, 34), + (20, 34), + (21, 33), + (21, 34), + (23, 33), + (23, 34), + (24, 26), + (24, 28), + (24, 30), + (24, 33), + (24, 34), + (25, 26), + (25, 28), + (25, 32), + (26, 32), + (27, 30), + (27, 34), + (28, 34), + (29, 32), + (29, 34), + (30, 33), + (30, 34), + (31, 33), + (31, 34), + (32, 33), + (32, 34), + (33, 34), + ]) return SimpleGraph(e) end function krackhardt_kite_graph() - e = - SimpleEdge.([ - (1, 2), - (1, 3), - (1, 4), - (1, 6), - (2, 4), - (2, 5), - (2, 7), - (3, 4), - (3, 6), - (4, 5), - (4, 6), - (4, 7), - (5, 7), - (6, 7), - (6, 8), - (7, 8), - (8, 9), - (9, 10), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 3), + (1, 4), + (1, 6), + (2, 4), + (2, 5), + (2, 7), + (3, 4), + (3, 6), + (4, 5), + (4, 6), + (4, 7), + (5, 7), + (6, 7), + (6, 8), + (7, 8), + (8, 9), + (9, 10), + ]) return SimpleGraph(e) end function moebius_kantor_graph() - e = - SimpleEdge.([ - (1, 2), - (1, 6), - (1, 16), - (2, 3), - (2, 13), - (3, 4), - (3, 8), - (4, 5), - (4, 15), - (5, 6), - (5, 10), - (6, 7), - (7, 8), - (7, 12), - (8, 9), - (9, 10), - (9, 14), - (10, 11), - (11, 12), - (11, 16), - (12, 13), - (13, 14), - (14, 15), - (15, 16), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 6), + (1, 16), + (2, 3), + (2, 13), + (3, 4), + (3, 8), + (4, 5), + (4, 15), + (5, 6), + (5, 10), + (6, 7), + (7, 8), + (7, 12), + (8, 9), + (9, 10), + (9, 14), + (10, 11), + (11, 12), + (11, 16), + (12, 13), + (13, 14), + (14, 15), + (15, 16), + ]) return SimpleGraph(e) end function octahedral_graph() - e = - SimpleEdge.([ - (1, 2), - (1, 3), - (1, 4), - (1, 5), - (2, 3), - (2, 4), - (2, 6), - (3, 5), - (3, 6), - (4, 5), - (4, 6), - (5, 6), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 3), + (1, 4), + (1, 5), + (2, 3), + (2, 4), + (2, 6), + (3, 5), + (3, 6), + (4, 5), + (4, 6), + (5, 6), + ]) return SimpleGraph(e) end function pappus_graph() - e = - SimpleEdge.([ - (1, 2), - (1, 6), - (1, 18), - (2, 3), - (2, 9), - (3, 4), - (3, 14), - (4, 5), - (4, 11), - (5, 6), - (5, 16), - (6, 7), - (7, 8), - (7, 12), - (8, 9), - (8, 15), - (9, 10), - (10, 11), - (10, 17), - (11, 12), - (12, 13), - (13, 14), - (13, 18), - (14, 15), - (15, 16), - (16, 17), - (17, 18), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 6), + (1, 18), + (2, 3), + (2, 9), + (3, 4), + (3, 14), + (4, 5), + (4, 11), + (5, 6), + (5, 16), + (6, 7), + (7, 8), + (7, 12), + (8, 9), + (8, 15), + (9, 10), + (10, 11), + (10, 17), + (11, 12), + (12, 13), + (13, 14), + (13, 18), + (14, 15), + (15, 16), + (16, 17), + (17, 18), + ]) return SimpleGraph(e) end function petersen_graph() - e = - SimpleEdge.([ - (1, 2), - (1, 5), - (1, 6), - (2, 3), - (2, 7), - (3, 4), - (3, 8), - (4, 5), - (4, 9), - (5, 10), - (6, 8), - (6, 9), - (7, 9), - (7, 10), - (8, 10), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 5), + (1, 6), + (2, 3), + (2, 7), + (3, 4), + (3, 8), + (4, 5), + (4, 9), + (5, 10), + (6, 8), + (6, 9), + (7, 9), + (7, 10), + (8, 10), + ]) return SimpleGraph(e) end function sedgewick_maze_graph() - e = - SimpleEdge.([ - (1, 3), (1, 6), (1, 8), (2, 8), (3, 7), (4, 5), (4, 6), (5, 6), (5, 7), (5, 8) - ]) + e = SimpleEdge.([ + (1, 3), (1, 6), (1, 8), (2, 8), (3, 7), (4, 5), (4, 6), (5, 6), (5, 7), (5, 8) + ]) return SimpleGraph(e) end @@ -535,170 +521,166 @@ function tetrahedral_graph() end function truncated_cube_graph() - e = - SimpleEdge.([ - (1, 2), - (1, 3), - (1, 5), - (2, 12), - (2, 15), - (3, 4), - (3, 5), - (4, 7), - (4, 9), - (5, 6), - (6, 17), - (6, 19), - (7, 8), - (7, 9), - (8, 11), - (8, 13), - (9, 10), - (10, 18), - (10, 21), - (11, 12), - (11, 13), - (12, 15), - (13, 14), - (14, 22), - (14, 23), - (15, 16), - (16, 20), - (16, 24), - (17, 18), - (17, 19), - (18, 21), - (19, 20), - (20, 24), - (21, 22), - (22, 23), - (23, 24), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 3), + (1, 5), + (2, 12), + (2, 15), + (3, 4), + (3, 5), + (4, 7), + (4, 9), + (5, 6), + (6, 17), + (6, 19), + (7, 8), + (7, 9), + (8, 11), + (8, 13), + (9, 10), + (10, 18), + (10, 21), + (11, 12), + (11, 13), + (12, 15), + (13, 14), + (14, 22), + (14, 23), + (15, 16), + (16, 20), + (16, 24), + (17, 18), + (17, 19), + (18, 21), + (19, 20), + (20, 24), + (21, 22), + (22, 23), + (23, 24), + ]) return SimpleGraph(e) end function truncated_tetrahedron_graph() - e = - SimpleEdge.([ - (1, 2), - (1, 3), - (1, 10), - (2, 3), - (2, 7), - (3, 4), - (4, 5), - (4, 12), - (5, 6), - (5, 12), - (6, 7), - (6, 8), - (7, 8), - (8, 9), - (9, 10), - (9, 11), - (10, 11), - (11, 12), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 3), + (1, 10), + (2, 3), + (2, 7), + (3, 4), + (4, 5), + (4, 12), + (5, 6), + (5, 12), + (6, 7), + (6, 8), + (7, 8), + (8, 9), + (9, 10), + (9, 11), + (10, 11), + (11, 12), + ]) return SimpleGraph(e) end function truncated_tetrahedron_digraph() - e = - SimpleEdge.([ - (1, 2), - (1, 3), - (1, 10), - (2, 3), - (2, 7), - (3, 4), - (4, 5), - (4, 12), - (5, 6), - (5, 12), - (6, 7), - (6, 8), - (7, 8), - (8, 9), - (9, 10), - (9, 11), - (10, 11), - (11, 12), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 3), + (1, 10), + (2, 3), + (2, 7), + (3, 4), + (4, 5), + (4, 12), + (5, 6), + (5, 12), + (6, 7), + (6, 8), + (7, 8), + (8, 9), + (9, 10), + (9, 11), + (10, 11), + (11, 12), + ]) return SimpleDiGraph(e) end function tutte_graph() - e = - SimpleEdge.([ - (1, 2), - (1, 3), - (1, 4), - (2, 5), - (2, 27), - (3, 11), - (3, 12), - (4, 19), - (4, 20), - (5, 6), - (5, 34), - (6, 7), - (6, 30), - (7, 8), - (7, 28), - (8, 9), - (8, 15), - (9, 10), - (9, 39), - (10, 11), - (10, 38), - (11, 40), - (12, 13), - (12, 40), - (13, 14), - (13, 36), - (14, 15), - (14, 16), - (15, 35), - (16, 17), - (16, 23), - (17, 18), - (17, 45), - (18, 19), - (18, 44), - (19, 46), - (20, 21), - (20, 46), - (21, 22), - (21, 42), - (22, 23), - (22, 24), - (23, 41), - (24, 25), - (24, 28), - (25, 26), - (25, 33), - (26, 27), - (26, 32), - (27, 34), - (28, 29), - (29, 30), - (29, 33), - (30, 31), - (31, 32), - (31, 34), - (32, 33), - (35, 36), - (35, 39), - (36, 37), - (37, 38), - (37, 40), - (38, 39), - (41, 42), - (41, 45), - (42, 43), - (43, 44), - (43, 46), - (44, 45), - ]) + e = SimpleEdge.([ + (1, 2), + (1, 3), + (1, 4), + (2, 5), + (2, 27), + (3, 11), + (3, 12), + (4, 19), + (4, 20), + (5, 6), + (5, 34), + (6, 7), + (6, 30), + (7, 8), + (7, 28), + (8, 9), + (8, 15), + (9, 10), + (9, 39), + (10, 11), + (10, 38), + (11, 40), + (12, 13), + (12, 40), + (13, 14), + (13, 36), + (14, 15), + (14, 16), + (15, 35), + (16, 17), + (16, 23), + (17, 18), + (17, 45), + (18, 19), + (18, 44), + (19, 46), + (20, 21), + (20, 46), + (21, 22), + (21, 42), + (22, 23), + (22, 24), + (23, 41), + (24, 25), + (24, 28), + (25, 26), + (25, 33), + (26, 27), + (26, 32), + (27, 34), + (28, 29), + (29, 30), + (29, 33), + (30, 31), + (31, 32), + (31, 34), + (32, 33), + (35, 36), + (35, 39), + (36, 37), + (37, 38), + (37, 40), + (38, 39), + (41, 42), + (41, 45), + (42, 43), + (43, 44), + (43, 46), + (44, 45), + ]) return SimpleGraph(e) end diff --git a/src/SimpleGraphs/generators/staticgraphs.jl b/src/SimpleGraphs/generators/staticgraphs.jl index 65fbb0bdb..9f37cb689 100644 --- a/src/SimpleGraphs/generators/staticgraphs.jl +++ b/src/SimpleGraphs/generators/staticgraphs.jl @@ -530,12 +530,12 @@ function binary_tree(k::T) where {T<:Integer} fadjlist = Vector{Vector{T}}(undef, n) @inbounds fadjlist[1] = T[2, 3] @inbounds for i in 1:(k - 2) - @simd for j in (2^i):(2^(i + 1) - 1) + @simd for j in (2 ^ i):(2 ^ (i + 1) - 1) fadjlist[j] = T[j ÷ 2, 2j, 2j + 1] end end i = k - 1 - @inbounds @simd for j in (2^i):(2^(i + 1) - 1) + @inbounds @simd for j in (2 ^ i):(2 ^ (i + 1) - 1) fadjlist[j] = T[j ÷ 2] end return SimpleGraph(ne, fadjlist) diff --git a/src/SimpleGraphs/simpleedgeiter.jl b/src/SimpleGraphs/simpleedgeiter.jl index 3c33fc95f..509319c68 100644 --- a/src/SimpleGraphs/simpleedgeiter.jl +++ b/src/SimpleGraphs/simpleedgeiter.jl @@ -30,7 +30,7 @@ eltype(::Type{SimpleEdgeIter{SimpleDiGraph{T}}}) where {T} = SimpleDiGraphEdge{T @traitfn @inline function iterate( eit::SimpleEdgeIter{G}, state=(one(eltype(eit.g)), 1) -) where {G <: AbstractSimpleGraph; !IsDirected{G}} +) where {G<:AbstractSimpleGraph;!IsDirected{G}} g = eit.g T = eltype(g) n = T(nv(g)) @@ -57,7 +57,7 @@ end @traitfn @inline function iterate( eit::SimpleEdgeIter{G}, state=(one(eltype(eit.g)), 1) -) where {G <: AbstractSimpleGraph; IsDirected{G}} +) where {G<:AbstractSimpleGraph;IsDirected{G}} g = eit.g T = eltype(g) n = T(nv(g)) diff --git a/src/dominatingset/degree_dom_set.jl b/src/dominatingset/degree_dom_set.jl index 3e3da690b..183355775 100644 --- a/src/dominatingset/degree_dom_set.jl +++ b/src/dominatingset/degree_dom_set.jl @@ -52,8 +52,8 @@ function dominating_set(g::AbstractGraph{T}, alg::DegreeDominatingSet) where {T< degree_queue = PriorityQueue(Base.Order.Reverse, enumerate(degree(g) .+ 1)) length_ds = 0 - while !isempty(degree_queue) && peek(degree_queue)[2] > 0 - v = dequeue!(degree_queue) + while !isempty(degree_queue) && first(degree_queue)[2] > 0 + v = popfirst!(degree_queue).first in_dom_set[v] = true length_ds += 1 diff --git a/src/editdist.jl b/src/editdist.jl index 895ff7a3e..33eaccda8 100644 --- a/src/editdist.jl +++ b/src/editdist.jl @@ -149,16 +149,16 @@ function _edit_distance( # initialize open set OPEN = PriorityQueue{Vector{Tuple},Float64}() for v in vertices(G₂) - enqueue!(OPEN, [(T(1), v)], vertex_subst_cost(1, v) + h([(T(1), v)])) + push!(OPEN, [(T(1), v)] => vertex_subst_cost(1, v) + h([(T(1), v)])) end - enqueue!(OPEN, [(T(1), U(0))], vertex_delete_cost(1) + h([(T(1), U(0))])) + push!(OPEN, [(T(1), U(0))] => vertex_delete_cost(1) + h([(T(1), U(0))])) c = 0 while true # minimum (partial) edit path - λ, cost = peek(OPEN) + λ, cost = first(OPEN) c += 1 - dequeue!(OPEN) + popfirst!(OPEN) if is_complete_path(λ, G₁, G₂) return cost, λ @@ -177,7 +177,7 @@ function _edit_distance( end new_cost += association_cost(u1, u1, v1, v1) # handle self-loops - enqueue!(OPEN, λ⁺, new_cost) + push!(OPEN, λ⁺ => new_cost) end # we try deleting v1 λ⁺ = [λ; (u1, U(0))] @@ -194,7 +194,7 @@ function _edit_distance( new_cost += edge_delete_cost(Edge(u2, u1)) end end - enqueue!(OPEN, λ⁺, new_cost) + push!(OPEN, λ⁺ => new_cost) else # add remaining vertices of G₂ to the path by deleting them λ⁺ = [λ; [(T(0), v) for v in vs]] @@ -212,7 +212,7 @@ function _edit_distance( end end end - enqueue!(OPEN, λ⁺, new_cost + h(λ⁺) - h(λ)) + push!(OPEN, λ⁺ => new_cost + h(λ⁺) - h(λ)) end end end diff --git a/src/graphcut/karger_min_cut.jl b/src/graphcut/karger_min_cut.jl index 1fbd5af7d..1d412c771 100644 --- a/src/graphcut/karger_min_cut.jl +++ b/src/graphcut/karger_min_cut.jl @@ -23,7 +23,7 @@ function karger_min_cut(g::AbstractGraph{T}) where {T<:Integer} nvg < 2 && return zeros(Int, nvg) nvg == 2 && return [1, 2] - connected_vs = IntDisjointSets(nvg) + connected_vs = IntDisjointSet(nvg) num_components = nvg for e in shuffle(collect(edges(g))) diff --git a/src/independentset/degree_ind_set.jl b/src/independentset/degree_ind_set.jl index 7ca403cf0..df30c3425 100644 --- a/src/independentset/degree_ind_set.jl +++ b/src/independentset/degree_ind_set.jl @@ -26,7 +26,7 @@ function independent_set(g::AbstractGraph{T}, alg::DegreeIndependentSet) where { degree_queue = PriorityQueue(enumerate(degree(g))) while !isempty(degree_queue) - v = dequeue!(degree_queue) + v = popfirst!(degree_queue).first (deleted[v] || has_edge(g, v, v)) && continue deleted[v] = true push!(ind_set, v) diff --git a/src/linalg/nonbacktracking.jl b/src/linalg/nonbacktracking.jl index ddbae17dd..208e92bf5 100644 --- a/src/linalg/nonbacktracking.jl +++ b/src/linalg/nonbacktracking.jl @@ -118,16 +118,15 @@ function mul!(C, nbt::Nonbacktracking, B) end function coo_sparse(nbt::Nonbacktracking) - m = nbt.m - #= I,J = zeros(Int, m), zeros(Int, m) =# + m = nbt.m#= I,J = zeros(Int, m), zeros(Int, m) =# + I, J = zeros(Int, 0), zeros(Int, 0) for (e, u) in nbt.edgeidmap i, j = src(e), dst(e) for k in inneighbors(nbt.g, i) k == j && continue - v = nbt.edgeidmap[Edge(k, i)] - #= J[u] = v =# - #= I[u] = u =# + v = nbt.edgeidmap[Edge(k, i)]#= J[u] = v =##= I[u] = u =# + push!(I, v) push!(J, u) end diff --git a/src/linalg/spectral.jl b/src/linalg/spectral.jl index 756a37dde..f80e2afbe 100644 --- a/src/linalg/spectral.jl +++ b/src/linalg/spectral.jl @@ -180,7 +180,7 @@ function spectral_distance end # can't use Traitor syntax here (https://github.com/mauro3/SimpleTraits.jl/issues/36) @traitfn function spectral_distance( G₁::G, G₂::G, k::Integer -) where {G <: AbstractGraph; !IsDirected{G}} +) where {G<:AbstractGraph;!IsDirected{G}} A₁ = adjacency_matrix(G₁) A₂ = adjacency_matrix(G₂) @@ -199,7 +199,7 @@ function spectral_distance end end # can't use Traitor syntax here (https://github.com/mauro3/SimpleTraits.jl/issues/36) -@traitfn function spectral_distance(G₁::G, G₂::G) where {G <: AbstractGraph; !IsDirected{G}} +@traitfn function spectral_distance(G₁::G, G₂::G) where {G<:AbstractGraph;!IsDirected{G}} nv(G₁) == nv(G₂) || throw(ArgumentError("Spectral distance not defined for |G₁| != |G₂|")) return spectral_distance(G₁, G₂, nv(G₁)) diff --git a/src/operators.jl b/src/operators.jl index d8aeb2172..d1e5a9f55 100644 --- a/src/operators.jl +++ b/src/operators.jl @@ -504,11 +504,11 @@ sparse(g::AbstractGraph) = adjacency_matrix(g) length(g::AbstractGraph) = widen(nv(g)) * widen(nv(g)) ndims(g::AbstractGraph) = 2 -@traitfn function issymmetric(g::AG) where {AG <: AbstractGraph; !IsDirected{AG}} +@traitfn function issymmetric(g::AG) where {AG<:AbstractGraph;!IsDirected{AG}} return true end -@traitfn function issymmetric(g::AG) where {AG <: AbstractGraph; IsDirected{AG}} +@traitfn function issymmetric(g::AG) where {AG<:AbstractGraph;IsDirected{AG}} for e in edges(g) if !has_edge(g, reverse(e)) return false diff --git a/src/shortestpaths/astar.jl b/src/shortestpaths/astar.jl index d42bd442c..aa7b553e1 100644 --- a/src/shortestpaths/astar.jl +++ b/src/shortestpaths/astar.jl @@ -31,7 +31,7 @@ function a_star_impl!( total_path = Vector{edgetype_to_return}() @inbounds while !isempty(open_set) - current = dequeue!(open_set) + current = popfirst!(open_set).first if current == goal reconstruct_path!(total_path, came_from, current, g, edgetype_to_return) @@ -86,7 +86,7 @@ function a_star( checkbounds(distmx, Base.OneTo(nv(g)), Base.OneTo(nv(g))) open_set = PriorityQueue{U,T}() - enqueue!(open_set, s, 0) + push!(open_set, s => 0) closed_set = zeros(Bool, nv(g)) diff --git a/src/shortestpaths/dijkstra.jl b/src/shortestpaths/dijkstra.jl index 9a8e8911c..cc810b276 100644 --- a/src/shortestpaths/dijkstra.jl +++ b/src/shortestpaths/dijkstra.jl @@ -95,7 +95,7 @@ function dijkstra_shortest_paths( sizehint!(closest_vertices, nvg) while !isempty(H) - u = dequeue!(H) + u = popfirst!(H).first if trackvertices push!(closest_vertices, u) diff --git a/src/shortestpaths/yen.jl b/src/shortestpaths/yen.jl index 50625044b..fbc168763 100644 --- a/src/shortestpaths/yen.jl +++ b/src/shortestpaths/yen.jl @@ -88,7 +88,7 @@ function yen_k_shortest_paths( distpath = distrootpath + djspur.dists[target] # Add the potential k-shortest path to the heap if !haskey(B, pathtotal) - enqueue!(B, pathtotal, distpath) + push!(B, pathtotal => distpath) end end @@ -99,11 +99,11 @@ function yen_k_shortest_paths( # No more paths in B isempty(B) && break - mindistB = peek(B)[2] + mindistB = first(B)[2] # The path with minimum distance in B is higher than maxdist mindistB > maxdist && break - push!(dists, peek(B)[2]) - push!(A, dequeue!(B)) + push!(dists, first(B)[2]) + push!(A, popfirst!(B).first) end return YenState{T,U}(dists, A) diff --git a/src/spanningtrees/boruvka.jl b/src/spanningtrees/boruvka.jl index 02b038a5c..26c7261c6 100644 --- a/src/spanningtrees/boruvka.jl +++ b/src/spanningtrees/boruvka.jl @@ -15,7 +15,7 @@ function boruvka_mst end @traitfn function boruvka_mst( g::AG::(!IsDirected), distmx::AbstractMatrix{T}=weights(g); minimize=true ) where {T<:Number,U,AG<:AbstractGraph{U}} - djset = IntDisjointSets(nv(g)) + djset = IntDisjointSet(nv(g)) # maximizing Z is the same as minimizing -Z # mode will indicate the need for the -1 multiplication mode = minimize ? 1 : -1 diff --git a/src/spanningtrees/kruskal.jl b/src/spanningtrees/kruskal.jl index b9efba367..e29dbcd60 100644 --- a/src/spanningtrees/kruskal.jl +++ b/src/spanningtrees/kruskal.jl @@ -12,7 +12,7 @@ function kruskal_mst end @traitfn function kruskal_mst( g::AG::(!IsDirected), distmx::AbstractMatrix{T}=weights(g); minimize=true ) where {T<:Number,U,AG<:AbstractGraph{U}} - connected_vs = IntDisjointSets(nv(g)) + connected_vs = IntDisjointSet(nv(g)) mst = Vector{edgetype(g)}() nv(g) <= 1 && return mst @@ -25,7 +25,7 @@ function kruskal_mst end push!(weights, distmx[src(e), dst(e)]) end - for e in edge_list[sortperm(weights; rev=!minimize)] + for e in edge_list[sortperm(weights; rev=(!minimize))] if !in_same_set(connected_vs, src(e), dst(e)) union!(connected_vs, src(e), dst(e)) push!(mst, e) diff --git a/src/spanningtrees/prim.jl b/src/spanningtrees/prim.jl index baf963b1c..efde13fe8 100644 --- a/src/spanningtrees/prim.jl +++ b/src/spanningtrees/prim.jl @@ -20,7 +20,7 @@ function prim_mst end wt[1] = typemin(T) while !isempty(pq) - v = dequeue!(pq) + v = popfirst!(pq).first finished[v] = true for u in neighbors(g, v) diff --git a/src/traversals/maxadjvisit.jl b/src/traversals/maxadjvisit.jl index ab8bd6b52..94827a1bc 100644 --- a/src/traversals/maxadjvisit.jl +++ b/src/traversals/maxadjvisit.jl @@ -30,7 +30,7 @@ assumed to be 1. # still appearing in fadjlist. When iterating neighbors, is_merged makes sure we # don't consider them is_merged = falses(nvg) - merged_vertices = IntDisjointSets(U(nvg)) + merged_vertices = IntDisjointSet(U(nvg)) graph_size = nvg # We need to mutate the weight matrix, # and we need it clean (0 for non edges) @@ -73,7 +73,7 @@ assumed to be 1. local cutweight while true last_vertex = u - u, cutweight = dequeue_pair!(pq) + u, cutweight = popfirst!(pq) isempty(pq) && break for v in fadjlist[u] (is_processed[v] || is_merged[v] || u == v) && continue @@ -158,7 +158,7 @@ function maximum_adjacency_visit( # start traversing the graph while !isempty(pq) - u = dequeue!(pq) + u = popfirst!(pq).first has_key[u] = false push!(vertices_order, u) log && println(io, "discover vertex: $u") diff --git a/src/vertexcover/degree_vertex_cover.jl b/src/vertexcover/degree_vertex_cover.jl index 1d9f33f34..bf850f5cc 100644 --- a/src/vertexcover/degree_vertex_cover.jl +++ b/src/vertexcover/degree_vertex_cover.jl @@ -36,8 +36,8 @@ function vertex_cover(g::AbstractGraph{T}, alg::DegreeVertexCover) where {T<:Int length_cover = 0 degree_queue = PriorityQueue(Base.Order.Reverse, enumerate(degree(g))) - while !isempty(degree_queue) && peek(degree_queue)[2] > 0 - v = dequeue!(degree_queue) + while !isempty(degree_queue) && first(degree_queue)[2] > 0 + v = popfirst!(degree_queue).first in_cover[v] = true length_cover += 1 diff --git a/test/Project.toml b/test/Project.toml index d15e5d8dd..e6b66c9cc 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -21,4 +21,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [compat] -JuliaFormatter = "1" \ No newline at end of file +JuliaFormatter = "2.2.0" diff --git a/test/biconnectivity/articulation.jl b/test/biconnectivity/articulation.jl index 0ebaff9bd..d9481c03f 100644 --- a/test/biconnectivity/articulation.jl +++ b/test/biconnectivity/articulation.jl @@ -27,7 +27,7 @@ btree = Graphs.binary_tree(level) for tree in test_generic_graphs(btree; eltypes=[Int, UInt8, Int16]) artpts = @inferred(articulation(tree)) - @test artpts == collect(1:(2^(level - 1) - 1)) + @test artpts == collect(1:(2 ^ (level - 1) - 1)) end end diff --git a/test/centrality/eigenvector.jl b/test/centrality/eigenvector.jl index af13508b7..5fb69d9b3 100644 --- a/test/centrality/eigenvector.jl +++ b/test/centrality/eigenvector.jl @@ -4,8 +4,7 @@ for g in test_generic_graphs(g1) y = @inferred(eigenvector_centrality(g)) - @test round.(y, digits=3) == - round.( + @test round.(y, digits=3) == round.( [ 0.3577513877490464, 0.3577513877490464, diff --git a/test/simplegraphs/runtests.jl b/test/simplegraphs/runtests.jl index 576110f14..7ae54ae5c 100644 --- a/test/simplegraphs/runtests.jl +++ b/test/simplegraphs/runtests.jl @@ -1,13 +1,13 @@ using Graphs.SimpleGraphs import Graphs.SimpleGraphs: fadj, badj, adj -import Graphs.edgetype, Graphs.has_edge +import Graphs: edgetype, has_edge using Statistics: mean struct DummySimpleGraph <: AbstractSimpleGraph{Int} end struct DummySimpleEdge <: AbstractSimpleEdge{Int} end DummySimpleEdge(x...) = DummySimpleEdge() -Graphs.edgetype(g::DummySimpleGraph) = DummySimpleEdge +edgetype(g::DummySimpleGraph) = DummySimpleEdge has_edge(::DummySimpleGraph, ::DummySimpleEdge) = true # function to check if the invariants for SimpleGraph and SimpleDiGraph holds diff --git a/test/simplegraphs/simplegraphs.jl b/test/simplegraphs/simplegraphs.jl index 78b5145ef..cbc372117 100644 --- a/test/simplegraphs/simplegraphs.jl +++ b/test/simplegraphs/simplegraphs.jl @@ -322,8 +322,9 @@ using Graphs.Test SimpleGraph(0) ) E = edgetype(g) - edge_list = - E.([(4, 4), (1, 2), (4, 4), (1, 2), (4, 4), (2, 1), (0, 1), (1, 0), (0, 0)]) + edge_list = E.([ + (4, 4), (1, 2), (4, 4), (1, 2), (4, 4), (2, 1), (0, 1), (1, 0), (0, 0) + ]) edge_iter = (e for e in edge_list) edge_set = Set(edge_list) edge_set_any = Set{Any}(edge_list) @@ -352,8 +353,9 @@ using Graphs.Test SimpleDiGraph(0) ) E = edgetype(g) - edge_list = - E.([(4, 4), (1, 2), (4, 4), (1, 2), (4, 4), (2, 1), (0, 1), (1, 0), (0, 0)]) + edge_list = E.([ + (4, 4), (1, 2), (4, 4), (1, 2), (4, 4), (2, 1), (0, 1), (1, 0), (0, 0) + ]) edge_iter = (e for e in edge_list) edge_set = Set(edge_list) edge_set_any = Set{Any}(edge_list)