diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml new file mode 100644 index 0000000..faa9d41 --- /dev/null +++ b/.github/workflows/format_check.yml @@ -0,0 +1,32 @@ +name: format-check +on: + push: + branches: + - master + - release-* + pull_request: + types: [opened, synchronize, reopened] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: julia-actions/setup-julia@latest + with: + version: '1' + - uses: actions/checkout@v4 + - name: Format check + shell: julia --color=yes {0} + run: | + using Pkg + # If you update the version, also update the style guide docs. + Pkg.add(PackageSpec(name="JuliaFormatter", version="1")) + using JuliaFormatter + format("src", verbose=true) + format("test", verbose=true) + out = String(read(Cmd(`git diff`))) + if isempty(out) + exit(0) + end + @error "Some files have not been formatted !!!" + write(stdout, out) + exit(1) diff --git a/Project.toml b/Project.toml index fa91370..2ba530f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,17 +1,15 @@ name = "CombinatorialLinearOracles" uuid = "0002e35e-4a6a-41c8-a2f5-6940c7e5949f" -version = "0.1.4" +version = "0.1.5" authors = ["ZIB-IOL and contributors"] [deps] Boscia = "36b166db-dac5-4d05-b36a-e6c4cef071c9" FrankWolfe = "f55ce6ea-fdc5-4628-88c5-0087fe54bd30" Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" -GraphsFlows = "06909019-6f44-4949-96fc-b9d9aaa02889" GraphsMatching = "c3af3a8c-b79e-4b01-bf44-c718d7e0e0d6" Hungarian = "e91730f6-4275-51fb-a7a0-7064cfbd3b39" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" -MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" @@ -19,11 +17,9 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Boscia = "0.2" FrankWolfe = "0.6" Graphs = "1" -GraphsFlows = "0.1" GraphsMatching = "0.2" Hungarian = "0.7.0" LinearAlgebra = "1" -MathOptInterface = "1" julia = "1.10" [extras] diff --git a/src/matchings.jl b/src/matchings.jl index 022a059..40af163 100644 --- a/src/matchings.jl +++ b/src/matchings.jl @@ -38,7 +38,7 @@ function FrankWolfe.compute_extreme_point( v .= 0 end nvtx = nv(lmo.original_graph) - w = Dict{edgetype(lmo.original_graph), eltype(direction)}() + w = Dict{edgetype(lmo.original_graph),eltype(direction)}() for (i, edge) in enumerate(edges(lmo.original_graph)) w[edge] = direction[i] w[Edge(src(edge) + nvtx, dst(edge) + nvtx)] = direction[i] @@ -61,7 +61,14 @@ function FrankWolfe.compute_extreme_point( return v end -function Boscia.bounded_compute_extreme_point(lmo::MatchingLMO, direction, lb, ub, int_vars; kwargs...) +function Boscia.bounded_compute_extreme_point( + lmo::MatchingLMO, + direction, + lb, + ub, + int_vars; + kwargs..., +) # any entry i fixed to zero -> use a positive direction, ensuring the edge is not taken # any entry i fixed to one with neighbors (u, v) -> use positive direction for all other neighbors of u, of v corrected_direction = copy(direction) diff --git a/src/shortest_path.jl b/src/shortest_path.jl index fc878da..debcb9e 100644 --- a/src/shortest_path.jl +++ b/src/shortest_path.jl @@ -12,10 +12,21 @@ function ShortestPathLMO(graph, src_node, dst_node) @assert Graphs.has_path(graph, src_node, dst_node) dist_matrix = spzeros(Graphs.nv(graph), Graphs.nv(graph)) edge_dict = Dict(Graphs.edges(graph) .=> 1:Graphs.ne(graph)) - return ShortestPathLMO{eltype(dist_matrix), typeof(graph)}(graph, src_node, dst_node, dist_matrix, edge_dict) + return ShortestPathLMO{eltype(dist_matrix),typeof(graph)}( + graph, + src_node, + dst_node, + dist_matrix, + edge_dict, + ) end -function FrankWolfe.compute_extreme_point(lmo::ShortestPathLMO, direction; v=falses(ne(lmo.graph)), kwargs...) +function FrankWolfe.compute_extreme_point( + lmo::ShortestPathLMO, + direction; + v=falses(ne(lmo.graph)), + kwargs..., +) for (idx, edge) in enumerate(edges(lmo.graph)) lmo.dist_matrix[src(edge), dst(edge)] = direction[idx] end diff --git a/test/runtests.jl b/test/runtests.jl index 3d6cc68..ecaf42a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -68,7 +68,13 @@ end @testset "Fix one entry to zero" begin for one_idx in SparseArrays.nonzeroinds(v) # upperbound one everywhere except one_idx fixed to zero - v_fixed1 = Boscia.bounded_compute_extreme_point(lmo, direction, zeros(M), (1:M) .!= one_idx, 1:M) + v_fixed1 = Boscia.bounded_compute_extreme_point( + lmo, + direction, + zeros(M), + (1:M) .!= one_idx, + 1:M, + ) @test v_fixed1[one_idx] == 0 @test Boscia.is_simple_linear_feasible(lmo, v_fixed1) end @@ -166,10 +172,10 @@ end add_edge!(g, 2, 3) add_edge!(g, 3, 4) mat = adjacency_matrix(g) - mat[3,4] = -10 + mat[3, 4] = -10 lmo = CO.ShortestPathLMO(g, 1, 4) costs = ones(ne(g)) - idx = findfirst(==(Edge(3,4)), collect(edges(g))) + idx = findfirst(==(Edge(3, 4)), collect(edges(g))) costs[idx] = -10 v = FrankWolfe.compute_extreme_point(lmo, costs) @test sum(v) == 3