diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml new file mode 100644 index 0000000..c743950 --- /dev/null +++ b/.JuliaFormatter.toml @@ -0,0 +1 @@ +style = "blue" \ No newline at end of file diff --git a/.codecov.yml b/.codecov.yml deleted file mode 100644 index 69cb760..0000000 --- a/.codecov.yml +++ /dev/null @@ -1 +0,0 @@ -comment: false diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c7988e1..a3e0259 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -1,14 +1,15 @@ name: CI -env: - JULIA_NUM_THREADS: 2 on: - pull_request: - branches: - - master push: branches: - master - tags: '*' + tags: ['*'] + pull_request: +concurrency: + # Skip intermediate builds: always. + # Cancel intermediate builds: only if it is a pull request build. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} jobs: test: name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} @@ -17,13 +18,11 @@ jobs: fail-fast: false matrix: version: - - 'nightly' - - '1' - '1.6' + - '1' + - 'nightly' os: - ubuntu-latest - - macos-latest - - windows-latest arch: - x64 steps: @@ -32,19 +31,31 @@ jobs: with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} - - uses: actions/cache@v1 - env: - cache-name: cache-artifacts - with: - path: ~/.julia/artifacts - key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} - restore-keys: | - ${{ runner.os }}-test-${{ env.cache-name }}- - ${{ runner.os }}-test- - ${{ runner.os }}- + - uses: julia-actions/cache@v1 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v1 + - uses: codecov/codecov-action@v2 + with: + files: lcov.info + docs: + name: Documentation + runs-on: ubuntu-latest + permissions: + contents: write + statuses: write + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 with: - file: lcov.info + version: '1' + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-docdeploy@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - run: | + julia --project=docs -e ' + using Documenter: DocMeta, doctest + using SimpleWeightedGraphs + DocMeta.setdocmeta!(SimpleWeightedGraphs, :DocTestSetup, :(using SimpleWeightedGraphs); recursive=true) + doctest(SimpleWeightedGraphs)' diff --git a/.gitignore b/.gitignore index 3f02ca7..96cfdc5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.jl.cov *.jl.*.cov *.jl.mem -Manifest.toml +/Manifest.toml +docs/build/ diff --git a/CITATION.bib b/CITATION.bib new file mode 100644 index 0000000..57c2ad4 --- /dev/null +++ b/CITATION.bib @@ -0,0 +1,8 @@ +@misc{SimpleWeightedGraphs.jl, + author = {JuliaGraphs contributors}, + title = {SimpleWeightedGraphs.jl}, + url = {https://github.com/JuliaGraphs/SimpleWeightedGraphs.jl}, + version = {v1.3.0}, + year = {2023}, + month = {2} +} diff --git a/Project.toml b/Project.toml index a949e96..0ad8e2b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,5 +1,6 @@ name = "SimpleWeightedGraphs" uuid = "47aef6b3-ad0c-573a-a1e2-d07658019622" +authors = ["JuliaGraphs contributors"] version = "1.3.0" [deps] @@ -7,8 +8,18 @@ Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] Graphs = "1.7" julia = "1" + +[extras] +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" +JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Aqua", "Documenter", "Graphs", "JuliaFormatter", "LinearAlgebra", "Test"] diff --git a/README.md b/README.md index 8c45ce4..494d5f7 100644 --- a/README.md +++ b/README.md @@ -1,59 +1,11 @@ # SimpleWeightedGraphs +[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaGraphs.github.io/SimpleWeightedGraphs.jl/stable/) +[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaGraphs.github.io/SimpleWeightedGraphs.jl/dev/) [![Build Status](https://github.com/JuliaGraphs/SimpleWeightedGraphs.jl/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/JuliaGraphs/SimpleWeightedGraphs.jl/actions/workflows/CI.yml?query=branch%3Amaster) -[![codecov.io](http://codecov.io/github/JuliaGraphs/SimpleWeightedGraphs.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaGraphs/SimpleWeightedGraphs.jl?branch=master) +[![Coverage](https://codecov.io/gh/JuliaGraphs/SimpleWeightedGraphs.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaGraphs/SimpleWeightedGraphs.jl) +[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) -Edge-Weighted Graphs for [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl). +Edge-weighted graphs compatible with [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl). -Usage: -```julia -using Graphs, SimpleWeightedGraphs - -g = SimpleWeightedGraph(3) # or use `SimpleWeightedDiGraph` for directed graphs -add_edge!(g, 1, 2, 0.5) -add_edge!(g, 2, 3, 0.8) -add_edge!(g, 1, 3, 2.0) - -# get weight of edge from vertex 1 to vertex 2 -get_weight(g, 1, 2) - -# find the shortest path from vertex 1 to vertex 3 taking weights into account. -enumerate_paths(dijkstra_shortest_paths(g, 1), 3) -3-element Array{Int64,1}: - 1 - 2 - 3 - -# reweight the edge from 1 to 2 -add_edge!(g, 1, 2, 1.6) - -# rerun the shortest path calculation from 1 to 3 -enumerate_paths(dijkstra_shortest_paths(g, 1), 3) -2-element Array{Int64,1}: - 1 - 3 - -# it's possible to build the graph from arrays of sources, destinations and weights -sources = [1,2,1] -destinations = [2,3,3] -weights = [0.5, 0.8, 2.0] -g = SimpleWeightedGraph(sources, destinations, weights) - -# the combine keyword handles repeated pairs (sum by default) -g = SimpleWeightedGraph([1,2,1], [2,1,2], [1,1,1]; combine = +) -g.weights[2,1] == g.weights[1,2] == 3 # true - -# WARNING: unexpected results might occur with non-associative combine functions - -# notice that weights are indexed by [destination, source] -s = SimpleWeightedDiGraph([1,2,1], [2,1,2], [1,1,1]; combine = +) -s.weights[1,2] == 1 # true -s.weights[2,1] == 2 # true -``` - -Please pay attention to the fact that zero-weight edges are discarded by `add_edge!`. -This is due to the way the graph is stored (a sparse matrix). [A possible workaround -is to set a very small weight instead](https://stackoverflow.com/questions/48977068/how-to-add-free-edge-to-graph-in-lightgraphs-julia/48994712#48994712). - -Note that adding or removing vertices or edges from these graph types is not particularly performant; -see [MetaGraphs.jl](https://github.com/JuliaGraphs/MetaGraphs.jl) for possible alternatives. +See the [documentation](https://JuliaGraphs.github.io/SimpleWeightedGraphs.jl/dev/) for a tutorial. \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index d129912..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,47 +0,0 @@ -environment: - matrix: - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe" - - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" - - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" - -## uncomment the following lines to allow failures on nightly julia -## (tests will run but not make your overall status red) -#matrix: -# allow_failures: -# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" -# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" - -branches: - only: - - master - - /release-.*/ - -notifications: - - provider: Email - on_build_success: false - on_build_failure: false - on_build_status_changed: false - -install: - - ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12" -# If there's a newer build queued for the same PR, cancel this one - - ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod ` - https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | ` - Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { ` - throw "There are newer queued builds for this pull request, failing early." } -# Download most recent Julia Windows binary - - ps: (new-object net.webclient).DownloadFile( - $env:JULIA_URL, - "C:\projects\julia-binary.exe") -# Run installer silently, output to C:\projects\julia - - C:\projects\julia-binary.exe /S /D=C:\projects\julia - -build_script: -# Need to convert from shallow to complete for Pkg.clone to work - - IF EXIST .git\shallow (git fetch --unshallow) - - C:\projects\julia\bin\julia -e "versioninfo(); - Pkg.clone(pwd(), \"SimpleWeightedGraphs\"); Pkg.build(\"SimpleWeightedGraphs\")" - -test_script: - - C:\projects\julia\bin\julia -e "Pkg.test(\"SimpleWeightedGraphs\")" diff --git a/docs/Manifest.toml b/docs/Manifest.toml new file mode 100644 index 0000000..028e4da --- /dev/null +++ b/docs/Manifest.toml @@ -0,0 +1,223 @@ +# This file is machine-generated - editing it directly is not advised + +julia_version = "1.8.5" +manifest_format = "2.0" +project_hash = "bdbda428ff9bda3e6edacec7c2836953b8b12fea" + +[[deps.ANSIColoredPrinters]] +git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c" +uuid = "a4c015fc-c6ff-483c-b24f-f7ea428134e9" +version = "0.0.1" + +[[deps.ArnoldiMethod]] +deps = ["LinearAlgebra", "Random", "StaticArrays"] +git-tree-sha1 = "62e51b39331de8911e4a7ff6f5aaf38a5f4cc0ae" +uuid = "ec485272-7323-5ecc-a04f-4719b315124d" +version = "0.2.0" + +[[deps.Artifacts]] +uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" + +[[deps.Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[deps.Compat]] +deps = ["Dates", "LinearAlgebra", "UUIDs"] +git-tree-sha1 = "61fdd77467a5c3ad071ef8277ac6bd6af7dd4c04" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "4.6.0" + +[[deps.CompilerSupportLibraries_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" +version = "1.0.1+0" + +[[deps.DataStructures]] +deps = ["Compat", "InteractiveUtils", "OrderedCollections"] +git-tree-sha1 = "d1fff3a548102f48987a52a2e0d114fa97d730f0" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.18.13" + +[[deps.Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[deps.Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[deps.DocStringExtensions]] +deps = ["LibGit2"] +git-tree-sha1 = "2fb1e02f2b635d0845df5d7c167fec4dd739b00d" +uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +version = "0.9.3" + +[[deps.Documenter]] +deps = ["ANSIColoredPrinters", "Base64", "Dates", "DocStringExtensions", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"] +git-tree-sha1 = "58fea7c536acd71f3eef6be3b21c0df5f3df88fd" +uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +version = "0.27.24" + +[[deps.Graphs]] +deps = ["ArnoldiMethod", "Compat", "DataStructures", "Distributed", "Inflate", "LinearAlgebra", "Random", "SharedArrays", "SimpleTraits", "SparseArrays", "Statistics"] +git-tree-sha1 = "1cf1d7dcb4bc32d7b4a5add4232db3750c27ecb4" +uuid = "86223c79-3864-5bf0-83f7-82e725a168b6" +version = "1.8.0" + +[[deps.IOCapture]] +deps = ["Logging", "Random"] +git-tree-sha1 = "f7be53659ab06ddc986428d3a9dcc95f6fa6705a" +uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89" +version = "0.2.2" + +[[deps.Inflate]] +git-tree-sha1 = "5cd07aab533df5170988219191dfad0519391428" +uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9" +version = "0.1.3" + +[[deps.InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[deps.JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "3c837543ddb02250ef42f4738347454f95079d4e" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.3" + +[[deps.LibGit2]] +deps = ["Base64", "NetworkOptions", "Printf", "SHA"] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[deps.Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[deps.LinearAlgebra]] +deps = ["Libdl", "libblastrampoline_jll"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[deps.Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[deps.MacroTools]] +deps = ["Markdown", "Random"] +git-tree-sha1 = "42324d08725e200c23d4dfb549e0d5d89dede2d2" +uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +version = "0.5.10" + +[[deps.Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[deps.Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[deps.NetworkOptions]] +uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" +version = "1.2.0" + +[[deps.OpenBLAS_jll]] +deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] +uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" +version = "0.3.20+0" + +[[deps.OrderedCollections]] +git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.4.1" + +[[deps.Parsers]] +deps = ["Dates", "SnoopPrecompile"] +git-tree-sha1 = "6f4fbcd1ad45905a5dee3f4256fabb49aa2110c6" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "2.5.7" + +[[deps.Preferences]] +deps = ["TOML"] +git-tree-sha1 = "47e5f437cc0e7ef2ce8406ce1e7e24d44915f88d" +uuid = "21216c6a-2e73-6563-6e65-726566657250" +version = "1.3.0" + +[[deps.Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[deps.REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[deps.Random]] +deps = ["SHA", "Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[deps.SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" +version = "0.7.0" + +[[deps.Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[deps.SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[deps.SimpleTraits]] +deps = ["InteractiveUtils", "MacroTools"] +git-tree-sha1 = "5d7e3f4e11935503d3ecaf7186eac40602e7d231" +uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d" +version = "0.9.4" + +[[deps.SimpleWeightedGraphs]] +deps = ["Graphs", "LinearAlgebra", "Markdown", "SparseArrays"] +path = ".." +uuid = "47aef6b3-ad0c-573a-a1e2-d07658019622" +version = "1.3.0" + +[[deps.SnoopPrecompile]] +deps = ["Preferences"] +git-tree-sha1 = "e760a70afdcd461cf01a575947738d359234665c" +uuid = "66db9d55-30c0-4569-8b51-7e840670fc0c" +version = "1.0.3" + +[[deps.Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[deps.SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[deps.StaticArrays]] +deps = ["LinearAlgebra", "Random", "StaticArraysCore", "Statistics"] +git-tree-sha1 = "2d7d9e1ddadc8407ffd460e24218e37ef52dd9a3" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "1.5.16" + +[[deps.StaticArraysCore]] +git-tree-sha1 = "6b7ba252635a5eff6a0b0664a41ee140a1c9e72a" +uuid = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" +version = "1.4.0" + +[[deps.Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[deps.TOML]] +deps = ["Dates"] +uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" +version = "1.0.0" + +[[deps.Test]] +deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[deps.UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[deps.Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[deps.libblastrampoline_jll]] +deps = ["Artifacts", "Libdl", "OpenBLAS_jll"] +uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" +version = "5.1.1+0" diff --git a/docs/Project.toml b/docs/Project.toml new file mode 100644 index 0000000..f01fb7a --- /dev/null +++ b/docs/Project.toml @@ -0,0 +1,3 @@ +[deps] +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +SimpleWeightedGraphs = "47aef6b3-ad0c-573a-a1e2-d07658019622" diff --git a/docs/make.jl b/docs/make.jl new file mode 100644 index 0000000..53e00a5 --- /dev/null +++ b/docs/make.jl @@ -0,0 +1,28 @@ +using SimpleWeightedGraphs +using Documenter + +DocMeta.setdocmeta!(SimpleWeightedGraphs, :DocTestSetup, :(using SimpleWeightedGraphs); recursive=true) + +makedocs(; + modules=[SimpleWeightedGraphs], + authors="Seth Bromberger and contributors", + repo="https://github.com/JuliaGraphs/SimpleWeightedGraphs.jl/blob/{commit}{path}#{line}", + sitename="SimpleWeightedGraphs.jl", + format=Documenter.HTML(; + prettyurls=get(ENV, "CI", "false") == "true", + canonical="https://JuliaGraphs.github.io/SimpleWeightedGraphs.jl", + edit_link="master", + assets=String[], + ), + pages=[ + "Home" => "index.md", + "API reference" => "api.md", + ], + linkcheck=true, + strict=true, +) + +deploydocs(; + repo="github.com/JuliaGraphs/SimpleWeightedGraphs.jl", + devbranch="master", +) diff --git a/docs/src/api.md b/docs/src/api.md new file mode 100644 index 0000000..804c3c7 --- /dev/null +++ b/docs/src/api.md @@ -0,0 +1,12 @@ +# API reference + +## Index + +```@index +``` + +## Docstrings + +```@autodocs +Modules = [SimpleWeightedGraphs] +``` diff --git a/docs/src/index.md b/docs/src/index.md new file mode 100644 index 0000000..9c53d03 --- /dev/null +++ b/docs/src/index.md @@ -0,0 +1,63 @@ +```@meta +CurrentModule = SimpleWeightedGraphs +``` + +# SimpleWeightedGraphs + +Documentation for [SimpleWeightedGraphs](https://github.com/JuliaGraphs/SimpleWeightedGraphs.jl). + + +## Quick start + +```julia +using Graphs, SimpleWeightedGraphs + +g = SimpleWeightedGraph(3) # or use `SimpleWeightedDiGraph` for directed graphs +add_edge!(g, 1, 2, 0.5) +add_edge!(g, 2, 3, 0.8) +add_edge!(g, 1, 3, 2.0) + +# get weight of edge from vertex 1 to vertex 2 +get_weight(g, 1, 2) + +# find the shortest path from vertex 1 to vertex 3 taking weights into account. +enumerate_paths(dijkstra_shortest_paths(g, 1), 3) +3-element Array{Int64,1}: + 1 + 2 + 3 + +# reweight the edge from 1 to 2 +add_edge!(g, 1, 2, 1.6) + +# rerun the shortest path calculation from 1 to 3 +enumerate_paths(dijkstra_shortest_paths(g, 1), 3) +2-element Array{Int64,1}: + 1 + 3 + +# it's possible to build the graph from arrays of sources, destinations and weights +sources = [1,2,1] +destinations = [2,3,3] +weights = [0.5, 0.8, 2.0] +g = SimpleWeightedGraph(sources, destinations, weights) + +# the combine keyword handles repeated pairs (sum by default) +g = SimpleWeightedGraph([1,2,1], [2,1,2], [1,1,1]; combine = +) +g.weights[2,1] == g.weights[1,2] == 3 # true + +# WARNING: unexpected results might occur with non-associative combine functions + +# notice that weights are indexed by [destination, source] +s = SimpleWeightedDiGraph([1,2,1], [2,1,2], [1,1,1]; combine = +) +s.weights[1,2] == 1 # true +s.weights[2,1] == 2 # true +``` + +## Caveats + +Please pay attention to the fact that zero-weight edges are discarded by `add_edge!`. +This is due to the way the graph is stored (a sparse matrix). A possible workaround +is to [set a very small weight instead](https://stackoverflow.com/questions/48977068/how-to-add-free-edge-to-graph-in-lightgraphs-julia/48994712#48994712). + +Note that adding or removing vertices or edges from these graph types is not particularly performant. See [MetaGraphsNext.jl](https://github.com/JuliaGraphs/MetaGraphsNext.jl) or [MetaGraphs.jl](https://github.com/JuliaGraphs/MetaGraphs.jl) for possible alternatives. \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index cf0cd22..f106347 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,12 +1,25 @@ +using Aqua +using Documenter using Graphs -using SimpleWeightedGraphs +using JuliaFormatter using LinearAlgebra +using SimpleWeightedGraphs using Test +DocMeta.setdocmeta!( + SimpleWeightedGraphs, :DocTestSetup, :(using SimpleWeightedGraphs); recursive=true +) + testdir = dirname(@__FILE__) -testgraphs(g) = [g, SimpleWeightedGraph{UInt8,Float64}(g), SimpleWeightedGraph{Int16,Float32}(g)] -testdigraphs(g) = [g, SimpleWeightedDiGraph{UInt8,Float64}(g), SimpleWeightedDiGraph{Int16,Float32}(g)] +function testgraphs(g) + return [g, SimpleWeightedGraph{UInt8,Float64}(g), SimpleWeightedGraph{Int16,Float32}(g)] +end +function testdigraphs(g) + return [ + g, SimpleWeightedDiGraph{UInt8,Float64}(g), SimpleWeightedDiGraph{Int16,Float32}(g) + ] +end testsimplegraphs(g) = [g, Graphs.SimpleGraph{UInt8}(g), Graphs.SimpleGraph{Int16}(g)] testsimpledigraphs(g) = [g, Graphs.SimpleDiGraph{UInt8}(g), Graphs.SimpleDiGraph{Int16}(g)] @@ -17,10 +30,20 @@ tests = [ "overrides", "persistence", "connectivity", - "a_star" + "a_star", ] @testset verbose = true "SimpleWeightedGraphs" begin + @testset verbose = true "Code quality (Aqua.jl)" begin + Aqua.test_all(SimpleWeightedGraphs; ambiguities=false) + end + @testset verbose = false "Code formatting (JuliaFormatter.jl)" begin + @test_broken format(SimpleWeightedGraphs; verbose=false, overwrite=false) + end + @testset verbose = false "Doctests (Documenter.jl)" begin + doctest(SimpleWeightedGraphs) + end + for t in tests tp = joinpath(testdir, "$(t).jl") include(tp)