Skip to content

Commit 5cf52c6

Browse files
authored
add formatter action (#25)
* add formatter action * lighter deps
1 parent 1d78e06 commit 5cf52c6

5 files changed

Lines changed: 64 additions & 12 deletions

File tree

.github/workflows/format_check.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: format-check
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- release-*
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: julia-actions/setup-julia@latest
14+
with:
15+
version: '1'
16+
- uses: actions/checkout@v4
17+
- name: Format check
18+
shell: julia --color=yes {0}
19+
run: |
20+
using Pkg
21+
# If you update the version, also update the style guide docs.
22+
Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))
23+
using JuliaFormatter
24+
format("src", verbose=true)
25+
format("test", verbose=true)
26+
out = String(read(Cmd(`git diff`)))
27+
if isempty(out)
28+
exit(0)
29+
end
30+
@error "Some files have not been formatted !!!"
31+
write(stdout, out)
32+
exit(1)

Project.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
name = "CombinatorialLinearOracles"
22
uuid = "0002e35e-4a6a-41c8-a2f5-6940c7e5949f"
3-
version = "0.1.4"
3+
version = "0.1.5"
44
authors = ["ZIB-IOL and contributors"]
55

66
[deps]
77
Boscia = "36b166db-dac5-4d05-b36a-e6c4cef071c9"
88
FrankWolfe = "f55ce6ea-fdc5-4628-88c5-0087fe54bd30"
99
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
10-
GraphsFlows = "06909019-6f44-4949-96fc-b9d9aaa02889"
1110
GraphsMatching = "c3af3a8c-b79e-4b01-bf44-c718d7e0e0d6"
1211
Hungarian = "e91730f6-4275-51fb-a7a0-7064cfbd3b39"
1312
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
14-
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
1513
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1614
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1715

1816
[compat]
1917
Boscia = "0.2"
2018
FrankWolfe = "0.6"
2119
Graphs = "1"
22-
GraphsFlows = "0.1"
2320
GraphsMatching = "0.2"
2421
Hungarian = "0.7.0"
2522
LinearAlgebra = "1"
26-
MathOptInterface = "1"
2723
julia = "1.10"
2824

2925
[extras]

src/matchings.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function FrankWolfe.compute_extreme_point(
3838
v .= 0
3939
end
4040
nvtx = nv(lmo.original_graph)
41-
w = Dict{edgetype(lmo.original_graph), eltype(direction)}()
41+
w = Dict{edgetype(lmo.original_graph),eltype(direction)}()
4242
for (i, edge) in enumerate(edges(lmo.original_graph))
4343
w[edge] = direction[i]
4444
w[Edge(src(edge) + nvtx, dst(edge) + nvtx)] = direction[i]
@@ -61,7 +61,14 @@ function FrankWolfe.compute_extreme_point(
6161
return v
6262
end
6363

64-
function Boscia.bounded_compute_extreme_point(lmo::MatchingLMO, direction, lb, ub, int_vars; kwargs...)
64+
function Boscia.bounded_compute_extreme_point(
65+
lmo::MatchingLMO,
66+
direction,
67+
lb,
68+
ub,
69+
int_vars;
70+
kwargs...,
71+
)
6572
# any entry i fixed to zero -> use a positive direction, ensuring the edge is not taken
6673
# any entry i fixed to one with neighbors (u, v) -> use positive direction for all other neighbors of u, of v
6774
corrected_direction = copy(direction)

src/shortest_path.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@ function ShortestPathLMO(graph, src_node, dst_node)
1212
@assert Graphs.has_path(graph, src_node, dst_node)
1313
dist_matrix = spzeros(Graphs.nv(graph), Graphs.nv(graph))
1414
edge_dict = Dict(Graphs.edges(graph) .=> 1:Graphs.ne(graph))
15-
return ShortestPathLMO{eltype(dist_matrix), typeof(graph)}(graph, src_node, dst_node, dist_matrix, edge_dict)
15+
return ShortestPathLMO{eltype(dist_matrix),typeof(graph)}(
16+
graph,
17+
src_node,
18+
dst_node,
19+
dist_matrix,
20+
edge_dict,
21+
)
1622
end
1723

18-
function FrankWolfe.compute_extreme_point(lmo::ShortestPathLMO, direction; v=falses(ne(lmo.graph)), kwargs...)
24+
function FrankWolfe.compute_extreme_point(
25+
lmo::ShortestPathLMO,
26+
direction;
27+
v=falses(ne(lmo.graph)),
28+
kwargs...,
29+
)
1930
for (idx, edge) in enumerate(edges(lmo.graph))
2031
lmo.dist_matrix[src(edge), dst(edge)] = direction[idx]
2132
end

test/runtests.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ end
6868
@testset "Fix one entry to zero" begin
6969
for one_idx in SparseArrays.nonzeroinds(v)
7070
# upperbound one everywhere except one_idx fixed to zero
71-
v_fixed1 = Boscia.bounded_compute_extreme_point(lmo, direction, zeros(M), (1:M) .!= one_idx, 1:M)
71+
v_fixed1 = Boscia.bounded_compute_extreme_point(
72+
lmo,
73+
direction,
74+
zeros(M),
75+
(1:M) .!= one_idx,
76+
1:M,
77+
)
7278
@test v_fixed1[one_idx] == 0
7379
@test Boscia.is_simple_linear_feasible(lmo, v_fixed1)
7480
end
@@ -166,10 +172,10 @@ end
166172
add_edge!(g, 2, 3)
167173
add_edge!(g, 3, 4)
168174
mat = adjacency_matrix(g)
169-
mat[3,4] = -10
175+
mat[3, 4] = -10
170176
lmo = CO.ShortestPathLMO(g, 1, 4)
171177
costs = ones(ne(g))
172-
idx = findfirst(==(Edge(3,4)), collect(edges(g)))
178+
idx = findfirst(==(Edge(3, 4)), collect(edges(g)))
173179
costs[idx] = -10
174180
v = FrankWolfe.compute_extreme_point(lmo, costs)
175181
@test sum(v) == 3

0 commit comments

Comments
 (0)