Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 1 addition & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
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"

[compat]
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]
Expand Down
11 changes: 9 additions & 2 deletions src/matchings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions src/shortest_path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down